Modify the classify numbers programming

Assignment Help Computer Engineering
Reference no: EM132155900

Use C++ program to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements:

a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.

b. Save the output of the program in a file.

c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends the number read to the function main. Print only 10 numbers per line.

d. Have the program find the sum and average of the numbers.

e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting the appropriate counts, this new definition of the function printResult should also output the sum and average of the numbers.

CLASSIFY NUMBERS EXAMPLE:

In this example, using functions we rewrite the program that determines the number of odds and evens from a given list of integers. This program was first written in Chapter 5.

•The main algorithm remains the same:

1. Initialize variables, zeros, odds, and evens to 0.

2. Read a number.

3. If the number is even, increment the even count, and if the number is also zero, increment the zero count; else increment the odd count.

4. Repeat Steps 2 and 3 for each number in the list.

·To simplify the function main and further illustrate parameter passing, the program includes

•A function, initialize, to initialize the variables, such as zeros, odds, and evens.

•A function, getNumber, to get the number.

•A function, classifyNumber, to determine whether the number is odd or even (and whether it is also zero). This function also increments the appropriate count.

•A function, printResults, to print the results.

•initialize

void initialize(int& zeroCount, int& oddCount,

int& evenCount)

{

zeroCount = 0;

oddCount = 0;

evenCount = 0;

}

•getNumber

void getNumber(int& num)

{

cin>>num;

}

• classifyNumber

void classifyNumber(int num, int& zeroCount,

int& oddCount, int& evenCount)

{

switch(num % 2)

{

case 0: evenCount++; // update even count

if(num == 0) // number is also zero

zeroCount++; // update zero count

break;

case 1:

case -1: oddCount++; // update odd count

} //end switch

}

• printResults

void printResults(int zeroCount, int oddCount,

int evenCount)

{

cout<<"There are "<<evenCount<<" evens, "

<<"which also includes "<<zeroCount

<<" zeros"<<endl;

cout<<"Total number of odds are: "

<<oddCount<<endl;

}

Main Algorithm

1. Call function initialize to initialize variables.

2. Prompt the user to enter 20 numbers.

3. For each number in the list

a. Call function getNumber to read a number

b. Output the number.

c. Call function classifyNumber to classify the number and increment the appropriate count.

4. Call function printResults to print the final results.

Reference no: EM132155900

Questions Cloud

What is the probability that at least 3 of the 5 trees : What is the probability that at least 3 of the 5 trees that he measures are really Douglas-firs?
What code can be added : The ADT UnsortedType List function ‘DeleteItem(ItemType item)' creates an endless loop error when trying to delete a word or key that is not in the list.
Confidence interval for the true proportion : Construct a 95% confidence interval for the true proportion, mean, of Phantol users who got relief from using the drug.
How many would you expect to weigh between 3 and 8 pounds : The weights for newborn babies is approximately normally distributed with a mean of 5.5 pounds and a standard deviation of 1.1 pounds.
Modify the classify numbers programming : Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.
What is the efficiency rating : The expected value with no survey is $62,000 and the EVPI is $4,000. What is the efficiency rating?
Reads in a series of lines of input character by character : Write a program that reads in a series of lines of input character by character (using getchar()).
Write a program that exits when the user inputs character : Write a program that exits when the user inputs the character 'y At the start of the program, prompt the user to input a character.
What is the probability that : If one buys 10 of these tires from the distributor, what is the probability that

Reviews

Write a Review

Computer Engineering Questions & Answers

  About the encryption and decryption

Encryption and decryption Fill in the missing code in the main function of the provided skeleton code

  Find minimum amount of time invested in the installation

assume you want to test a motherboard used in an installation before you proceed too far into the installation.

  How would you design combined hardware and software support

How would you design combined hardware and software support to provide the illusion of a nearly infinite virtual memory on a limited amount of physical memory?

  Display all of the values in a table

Prompt the user for a string, and display the corresponding number. For example, if the user types "five", the program would output.

  Need to re-connectd when being mobile

I want some good examples of challenges individuals and organizations face with wireless VOIP telephony. With all of the flexibility and added functionality comes a price for stability. So how does an organization handle these challenges.

  Virtual circuit is newly set up in an atm network

ATM networks use a token bucket scheme to regulate traffic (traffic shaping). A new token is put into the bucket every 1 usec so ATM cells can be sent during this time. The data payload of ATM cells is 48 bytes.

  Executive summary explaining what the company is give it a

in this project you are the consulting firm that will be creating a proposal to implement networking technology for a

  Write a public static method named static long fibfast

Effecfively, we are creating a loop in which a and b represent two consecutive fibonacci numbers.

  How they are choosen and prioritized by management

how they are choosen and prioritized by management at a strategic level?

  Troubleshooting the software

AV software has eliminated the malware from highly infected system. After the first reboot, an error message is displayed that consists of the reference to strange DLL file that is missing.

  Overview of company and client business case

What is your companys expertise and Ensure that the expertise matches the skill sets required for the business case you have chosen - Overview of Company and Client Business Case

  What concerns should be understood about data communications

What concerns should be understood about data communications being sent over wireless networks? Discuss the pros and cons of one method of transmission.

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