Prompt and read in the name of the output file

Assignment Help Basic Computer Science
Reference no: EM13322315

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 <string>" 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 <fstream>" 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 <cstdlib>" 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.

Reference no: EM13322315

Questions Cloud

Find the direction of the electron force on this charge : A charge q=-1.0 nC is instantaneously at a place where the electric field is 45 kN/C due east. hat are the magnitude and direction of the electron force on this charge
The statement of cash flow under the indirect method : The below is a list of activities to be included in the preparation of UMUC's 2013 statement of cash flows. Prepare, IN GOOD FORM, the statement of cash flow under the indirect method.
What was the change of the systems electric potential : An electron moves from point A where the potential is Va=+20.0kV to point B where the potential is Vb=- 40.0 kV. what was the change of the system's electric potential
Percentage-of-completion method in accounting for long-term : UMUC contracted to build a new hotel for $800,000 that will take 3 years to complete. The following information pertains to the contract. UMUC uses the percentage-of-completion method in accounting for long-term contracts.
Prompt and read in the name of the output file : 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.
Compute the magnitude of the electric force : A water molecule floating in the air loses one electron, becoming an ion, What is the magnitude of the electric force between the electron and the water ion
What is the fundamental harmonic frequency of this pipe : An organ pipe is 1.17 m long. The temperature of the air is 20 degree C. What is the fundamental harmonic frequency of this pipe when it is closed at one end
History of indan economy discuss : History of Indan Economy discuss - discuss everyday forms of peasent resistance in mughal india.
Cash and financial investments : For the two transaction cycles of "cash and financial investments" and "accounts receivable

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Subsets of integers which sum to the same number

How many numbers do you require from this generator to guarantee that there exist 2 subsets of integers which  sum to the same number? Write steps how derive the solution.

  How to strive to nurture place which holds learning

What type of organization permits you to be creative, risk prone, and good conversationalist with peers? How can you strive to nurture place which embraces learning?

  Design an application to take and process a pizza order

Design an application to take and process a pizza order. The user should be able to make pizza order choices from listboxes, and the application should display the order price.

  How much would it have cost to have corrected fault

How much would it have cost to have corrected the fault during the specification phase? What should be the best answer to this question by a software engineering?

  Programming in mpi

What advantages are gained by programming in MPI as opposed to using threads? Is there a disadvantage to MPI? What?

  Write the necessary preprocessor directive to enable

Given an int variable x write some statements that attempt to open a file named "table20" and read a value into x ; if that turns out not to be possible your code should then read avalue from standard input into x .

  Describe the components of the ethernet frame in detail

Describe the components of the Ethernet frame in detail

  Cnditions under which full offsite backup is worth the cost

Discuss conditions under which it is worth the cost. Suggest some kind of compromise, lower cost solutions that still proved some recovery capabilities, and cases where these might be a preferred alternative.

  Make the color of the text lightblue

Write a CSS rule that gives h1 and h2 elements a padding of 0.5 ems, a dashed border style and a margin of 0.5 ems.

  Heptadeca class that encapsulates a heptadeca number

Write a Heptadeca class that encapsulates a Heptadeca number value. A Heptadeca number is one with 17 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G. The methods the class has are: public void read(), public void set(String), public voi..

  Prepare disaster recovery plan for organization

Prepare a Disaster Recovery (DR) Plan for following organization; Company; Widget Works Electronics, Employees; 250, Infrastructure; 1 Central Office building housing primary datacenter. 10 satellite sales branches.

  Information assets to estimate for risk management

If organization has three information assets to estimate for risk management as shown in accompanying data, which vulnerability must be evaluated for additional controls first?

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