Prepare a new test table with at least three distinct test

Assignment Help Data Structure & Algorithms
Reference no: EM131222125

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 <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:

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.

 

Reference no: EM131222125

Questions Cloud

Academic definition of the term metric : Discussion #1: Give an academic definition of the term metric (with an in-text citation) and share an example of at least two metrics you are considering for your second MS PowerPoint presentation due at the end of this week.
Examine motivational theories or models : Your task is to examine motivational theories/models as they apply to us in our daily lives and equally as they apply in the workplace. Groups will write an essay using theories of motivation to analyse the experiences recorded in the reflective j..
Selection methods barry ilaisa used for hiring salespeople : Identify the selection methods Barry Ilaisa used for hiring salespeople? Did he go about using these methods in the best order? Explain your answer.
Do descriptive statistics : HI6007 Do a frequency table, histogram, normal Q - Q and the de-trended normal Q-Q for each one of the 11 variables - Do descriptive statistics (mean, standard deviation, minimum, maximum) for each one of the 11 variables.
Prepare a new test table with at least three distinct test : 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 are the value ranges of the normalization methods : What are the value ranges of the following normalization methods?
Besides giving employees feedback : Question: Besides giving employees feedback, what other steps a manager can take to improve employees' performance?
Are the two schedules equivalent in terms of present values : Are the two schedules equivalent in terms of present values? Why or why not? - Why is the total sum of interest payments higher for the equal installment schedule?
The installment method of accounting generally equals cash : Income recognized using the installment method of accounting generally equals cash collected multiplied by the. A company uses the completed-contract method to account for a long-term construction contract. Revenue is recognized when recorded progres..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Write a program that implements dijkstras algorithm

Write a program that implements Dijkstra's algorithm

  How many students need to be entered

Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered

  Algorithm bubble sort

This project is a great opportunity to express your unique problem solving skills as well as your use of structured logic.

  A store makes four types of healthy cakes

A store makes four types of healthy cakes. To produce a type A cake requires 16 cups of Pour, 5 corn of sup:, 2 dozensof eggs. and 4 gram of vitamin c. 10 produce a typo !Italic tryouts 50 cups of flour. 6 cups of sugar, I dozens of eggs, and 2 gram ..

  Question about shortest prefixes

A prefix of a string is a substring string at the beginning of the given string. The prefixes of "carbon" are: c, ca, car, carb, carbo and carbon.

  Provide polynomial-time algorithm to decide in graph

Provide a polynomial-time algorithm to decide whether G has unique minimum s - t cut (i.e., an s - t cut of capacity strictly less than that of all other s - t cuts).

  Write down the output values and number of instances

Write down the output (class) values and number of instances that appear in each of the leaf nodes A, B and C of the tree.

  How much time will it take to sort the array

If an arbitrary item is added to the end of an already sorted list, how much time will it take to sort the array again using insertion sort?

  Create an asp.net project with visual studio.net

CpCreate an MS Access database called "Members.mdb." Add a table called "tblScores" with the following columns.

  Conduct space complexity analysis of the algorithm

conduct time complexity analysis of the algorithm (and also mention best case and worst case analysis if applicable).

  Compute a shortest-path

Compute a shortest-path from u to v (instead of from u to all the nodes). One way to speed up Dijkstra's algorithm might be to run the algorithm u and from v at the same time.

  Use structures and pointers to create linked lists

Objective: Use structures and pointers to create linked lists. Use knowledge of pointers to modify linked lists. Implement a recursive function.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd