Cash-back offer from May 7th to 12th, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 14.00

CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key

Question posted by
Online Tutor Profile
request

CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key

 

CMIS 102 Hands-On Lab

Week 5

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 2

Test Plan

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

Input

Expected Output

1

value=1 value=1 value=1 value=0

value=1 value=2 value=0 value=1 value=3 value=2

Average = 1.2

2

value=100 value=100 value=100 value=100

value=100 value=200 value=200 value=200 value=200 value=200

Average = 120.0

3

value=100 value=100 value=100 value=100

value=-100

value = 100 value=200 value=200 value=200 value=200 value=200

Input a positive value average is 120.0

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 <stdio.h>

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:

Note the input integer values are 1, 1, 1, 0, 1, 2, 0, 1, 3, 2 for this test case. You can change these values to any valid integer values to match your test cases. You should also test with a negative number to make sure the positive integer logic works properly.

Results from running the programming at 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.

 

Available Answer
$ 14.00

[Solved] CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key

  • This Solution has been Purchased 1 time
  • Submitted On 20 Jan, 2017 02:06:35
Answer posted by
Online Tutor Profile
solution
CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key CMIS 102 Hands-On Lab Week 5 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 + va...
Buy now to view the complete solution
attachment
Attachment
Other Similar Questions
User Profile
Tutor...

University of Maryland CMIS 102 Hands-On Lab Week 8 Lab

CMIS 102 Week 8 Hands-On Lab 1. To successfully carry out this code I assigned the sum of rainfall to a variable called totalRain. This variable is defined as the rainfall of each month of the year in the array. I also decla...
User Profile
vpqnr...

CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key

CMIS 102 Hands-On Lab Week 5 complete solutions correct answers key CMIS 102 Hands-On Lab Week 5 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the ...
User Profile
vpqnr...

CMIS 102 Hands-On Lab Week 8 complete solutions correct answers key

CMIS 102 Hands-On Lab Week 8 complete solutions correct answers key CMIS 102 Hands-On Lab Week 8 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the pr...
User Profile
vpqnr...

CMIS 102 Hands-On Lab Week 7 complete solutions correct answers key

CMIS 102 Hands-On Lab Week 7 complete solutions correct answers key CMIS 102 Hands-On Lab Week 7 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the ...
User Profile
vpqnr...

CMIS 102 Hands-On Lab Week 6 complete solutions correct answers key

CMIS 102 Hands-On Lab Week 6 complete solutions correct answers key CMIS 102 Hands-On Lab Week 6 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the ...

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35