Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Write a program writeOddEven.cpp which reads in a list of integers from the terminal and writes the odd numbers to one file and the even numbers to another file. The program prompts and reads in the name of the file which will contain the odd integers, the name of the file to contain the even integers and a list of integers terminated by a 0. In each of the files, exactly five integers should be written on each line except for the last line. In addition to writing the two files, the program writes to the terminal the number of integers in each file.

A sample run of the program would look like this:

> writeOddEven.exe
Enter name of file for odd integers: odd.txt
Enter name of file for even integers: even.txt
Enter list of odd and even integers (followed by 0):
2 3 20 300 400 5 -70 9 9 -101 6 8 10 77 55 400 16 20 300 0 File odd.txt contains 7 odd integers.
File even.txt contains 12 even integers.

After running this program file odd.txt contains: 3 5 9 9 -101

77 55

To view the contents of the file, type "more odd.txt". After running this program file even.txt contains:

2 20 300 400 -70 6 8 10 400 16
20 300

To view the contents of the file, type "more even.txt". Note that duplicate integers are permitted in the input and in files odd.txt and even.txt. Also note that the names for the files can be different than what is used here (do not hard code these in your solution).

Run writeOddEven_solution.exe to see examples of the program. Your program should behave like this program with the same input and output.

Prompt and read in the name of the output for the odd integers. Read and store this name as a string. Include the C++ command "#include " to use C++ strings.

Prompt and read in the name of the output file for the even integers. Read and store this name as a string.

Review and use the program writeFile3.cpp discussed in class as a template for your program. (See the class slides or download the program from Carmen).

Open two files for output. Make sure to pass a C style string, not the C++ string, to the open routine. Include the C++ command "#include " to use C++ file streams. Be sure to use the type "ofstream", not "ifstream", for your output file streams.

Check if the two files were successfully opened for output. If not, print an error message and exit. Include the C++ command "#include " to use the C++ exit command.

Prompt for the list of odd and even integers followed by 0.

Read in the first element x of the list

While x is not 0 do:

If x is odd, then:

? Write x followed by a blank space to the file for odd numbers
? Increment the counter of odd integers by 1
? If there are 5 integers on the current line in the file output a new line to the file

If x is even, then:
? Write x followed by a blank space to the file for even numbers
? Increment the counter of even integers by 1
? If there are 5 integers on the current line in the file output a new line to the file

Output a new line to both of the output files. (This makes sure that both files end in a new line).

CLOSE both output file streams. (You will lose points if you forget to close the output file streams, even though your program runs correctly).

Write the following message to the terminal:

File fnameOdd contains numOdd odd integers.
File fnameEven contains numEven positive integers.

where fnameOdd and fnameEven are the odd and even file names, respectively, and numOdd and numEven are the number of odd and number of even integers, respectively.

TEST YOUR CODE THOROUGHLY. For example, pay close attention to the format of the output including empty lines. Your program must not have a run-time error.

Be sure to add the header comments "File", "Created by", "Creation Date" and "Synopsis" at the top of the file. Each synopsis should contain a brief description of what the program does.

Be sure that there is a comment documenting each variable.

Be sure that your if statements, for and while loops and blocks are properly indented;

Check your output against the output from the solution executables provided.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9901617

Have any Question?


Related Questions in Computer Engineering

Question suppose a computer using direct mapped cache has

Question Suppose a computer using direct mapped cache has 2 40 bytes of byte-addressable main memory and a cache of 64 blocks, where each block contains 32 bytes. a. how many blocks pf main memory are there? b. what is t ...

Question 1conduct research to determine three types of

Question: 1. Conduct research to determine three types of computer crime. Please provide a detailed description for all crimes, and share an example of where an organization was impacted by each of the types. 2. Elaborat ...

Assignmentsuppose that a particular algorithm has time

Assignment Suppose that a particular algorithm has time complexity T(n) - 3 times 2 n , and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented w ...

Question skyeducation will develop a new branch in the city

Question : SkyEducation will develop a new branch in the city for J2EE programming training. The information is given in the following table. (Ignore the crashing parameters.) Task a b c d e f g Predecessors - - - a b c ...

Case description mama mias mm pizzeria offers pizzas

Case Description: Mama Mia's (MM) pizzeria offers pizzas, breadsticks, and Buffalo chicken wings for carry out customers only. Customers phone in the order and come by to pick up their order. When regular customers call ...

What are the minimum numbers of keys and pointers in btree

What are the minimum numbers of keys and pointers in Btree (i) interior nodes and (ii) leaves, when: a) n = 10; i.e., a block holds 10 keys and 11 pointeis. b) n = 11; i.e., a block holds 11 keys and 12 pointers.

We are evaluating a project that costs 1120000 has a

We are evaluating a project that costs $1,120,000, has a ten-year life, and has no salvage value. Assume that depreciation is straight-line to zero over the life of the project. Sales are projected at 64,000 units per ye ...

How could legislation impact on operations within your

How could legislation impact on operations within your organisation in relation to innovation, project management, and operational planning? Briefly outline any relevant requirements (e.g. intellectual property, WHS).

Question monicas reading comprehension score 22nbspmean

Question: Monica's reading comprehension score = 22  Mean fourth grade reading comprehension score = 19  Standard deviation of the fourth grade's reading comprehension = 1.8  Monica's z-score in math = 2.2  Mean fourth g ...

Letang industrial systems company lisc is trying to decide

Letang Industrial Systems Company (LISC) is trying to decide between two different conveyor belt systems. System A costs $300,000, has a four-year life, and requires $101,000 in pretax annual operating costs. System B co ...

  • 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