CMIS 102 Week 5 Hands On Lab
Just Click on Below Link To Download This Course:
http://bit.ly/2Nkfkd8
CMIS 102 Week 5 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:
|
1 |
|
For example, if the first value entered was 4 and second
was 10:
|
1 2 |
|
Values and sum can be input and calculated within a
repetition loop:
|
1 2 3 4 |
|
Avg can be calculated by:
|
1 |
|
A selection statement can be used inside the loop to make
sure the input value is positive.
|
1 2 3 4 5 |
|
|
|
Test case |
Input |
Expected output |
|
1 |
Value=1 |
Average=1.2 |
|
2 |
Value=100 |
Average=120.0 |
|
3 |
Value=100 |
Input
positive value |
Pseudocode
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
C
Code
The following is the C Code that will compile in execute in the online
compilers.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
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.
Learning Exercises for you to complete
- Change the code to average 20 integers as opposed to 10. Support
your experimentation with screen captures of executing the new code.
- 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.
- 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.
- 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
Submission
Successfully demonstrates execution of this lab with online compiler. Includes
a screen capture. Modifies the C code average 20 integers as opposed to 10.
Support your experimentation with screen captures of
executing the new code.
Provides a new test table with at least 3 distinct test
cases listing input and expected output for the code you created after step 1.
Describes what happens if you entered a value other than an integer? Support
your experimentation with screen captures of executing the code.
Modifies the C code to allow the user to enter an
unspecified number of positive integers and calculate the average. Provides 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.
Document is
well-organized, and contains minimal spelling and grammatical errors.


Comments
Post a Comment