Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Homework 3 - Create your own Loop application

Create your own unique While-End or (For End) repetition C code. You decide the theme. Be sure to provide an overview of what your repetition structure is doing. Please keep the design simple for this exercise. Just a few lines of code is all that is needed for this response. This should be code you wrote for an application that is interesting to you. In other words, make it your own and have fun with it.

Provide the C code and a screen capture showing the results of testing your code in an online compiler. Be sure to test your code with several test cases and show your test case table.

Hands-On Lab

Overview

This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, design (using pseudocode), and implementation with C code. The example provided uses sequential, selection and repetition statements.

Program Description

This program will calculate the average of 10 positive integers. The program will ask the user to 10 integers. If any of the values entered is negative, a message will be displayed asking the user to enter a value greater than 0. The program will use a loop to input the data.

Analysis

I will use sequential, selection and repetition programming statements.

I will define two integer numbers: count, value and sum. count will store how many times values are entered. value will store the input. Sum will store the sum of all 10 integers.

I will define one double number: avg. avg will store the average of the ten positive integers input.

The sum will be calculated by this formula:

sum = sum + value

For example, if the first value entered was 4 and second was 10:

sum = sum + value = 0 + 4
sum = 4 + 10 = 14

Values and sum can be input and calculated within a repetition loop:

while count <10
Input value
sum = sum + value
End while
Avg can be calculated by:
avg = value/count

A selection statement can be used inside the loop to make sure the input value is positive.

If value >= 0 then
count = count + 1
Else
input value
End If

Test Plan

To verify this program is working properly the input values could be used for testing:

Pseudocode

// This program will calculate the average of 10 positive integers.
// Declare variables
Declare count, value, sum as Integer
Declare avg as double
//Initialize value
Set count=0
Set sum = 0
set avg = 0.0;
// Loop through 10 integers
While count < 10
Print "Enter a Positive Integer"
Input value
if (value >=0)
sum = sum + value
count=count+1
else
Print ("Value must be positive");
End if
End While
// Calculate average
avg = sum/count
// Print results
Print "Average is " + avg

C Code

The following is the C Code that will compile in execute in the online compilers.

// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include
int main ()
{
/* variable definition: */
int count, value, sum;
double avg;
/* Initialize */
count = 0;
sum = 0;
avg = 0.0;
// Loop through to input values
while (count < 10)
{
printf("Enter a positive Integer\n");
scanf("%d", &value);
if (value >= 0) {
sum = sum + value;
count = count + 1;
}
else {
printf("Value must be positive\n");
}
}
// Calculate avg. Need to type cast since two integers will yield an integer
avg = (double) sum/count;
printf("average is %lf\n " , avg );
return 0;
}

Setting up the code and the input parameters in ideone.com:

Learning Exercises for you to complete

1. Change the code to average 20 integers as opposed to 10. Support your experimentation with screen captures of executing the new code.

2. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created after step 1.

3. What happens if you entered a value other than an integer? (For example a float or even a string). Support your experimentation with screen captures of executing the code.

4. Modify the code to allow the user to enter an unspecified number of positive integers and calculate the average. In other words, the user could enter number of positive integers. (Hint: You can prompt the user for how many they want to enter. Or; you could use a sentinel value to trigger when the user has completed entering values). You may need to conduct some research on your own to solve this problem. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created. Support your experimentation with screen captures of executing the new code.

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91978060
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Determine whether or not the following claim is true for

Determine whether or not the following claim is true for all regular expressions r 1  and r 2 . The symbol ≡ stands for equivalence regular expressions in the sense that both expressions denote the same language.  (a) (r ...

Question process designoperations management involves

Question: Process Design Operations management involves various activities, such as process design, selection, management of information technology, work systems, planning and development, and quality assurance (Slack, C ...

Question 1 select a specific activity or responsibility of

Question: 1. Select a specific activity or responsibility of the systems analyst. Define the purpose of the systems analyst and why it is important in the overall systems analysis process. Write this post to an audience ...

Questionhow can you start business by mobile application

Question How can you start business by Mobile Application Development ? Discuss the testing process of Mobile Applications in detail ? List important steps for publishing an app in the Target Market ?

Sorted golf scoresdesign a program that asks the user to

Sorted Golf Scores Design a program that asks the user to enter 10 golf scores. The scores should be stored in an Integer array. Sort the array in ascending order and display its contents. Looking for psuedocode format & ...

Calculate the thinkness of the monolayer assuming that the

Calculate the thinkness of the monolayer assuming that the volume of the monolayer is 7.39×10-6 mL and diameter of the watch glass is 5 cm.

Suppose two packets arrive to two different input ports of

Suppose two packets arrive to two different input ports of a router at exactly the same time. Also suppose there are no other packets anywhere in the router. a. Suppose the two packets are to be forwarded to two differen ...

In 2005 team dad used a toyota truck with a system of

In 2005, Team DAD used a Toyota truck with a system of spinning lasers as its "visual" system. What advantages and or disadvantage does such a system have compared to camera-based systems?

Assignment -question 1 - go-back-n in the following network

Assignment - Question 1 - (Go-Back-N) In the following network, node A transmits packets that pass through B and C, and arrive at the destination D. The bit rate of all links is R = 1 Mbit/sec. The maximum packet size in ...

Computer sciencewhat is required of an organization to

Computer Science What is required of an organization, to implement and maintain IT Governance? What outside resources are available to assist technology managers in the implementation and maintenance process?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As