Question: C++ Programming You will create your own simple database with a text file. Each record will consist of two rows: a name and a dollar

C++ Programming

You will create your own simple database with a text file. Each record will consist of two rows: a name and a dollar amount:

A string for a full name, containing more than one word.

A double for money

The tester will provide your code with an initial file that contains two records, one for Mikel Harry and another for Thomas Harris.

This file will be called "MyDatabase.txt", so you should write that into your code.

To use the same file the tester is using, create a file called "MyDatabase.txt" using notepad or a similar text editor and place it in the same directory as your project. Write the following contents into the file using your text editor and save it. Be sure to place a newline after the last line:

 Mikel Harry 3000000.36 Thomas Harris 9999999999.99 

Implement the menu below:

 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 

Option 1 will output the contents of the file to the console (cout).

When outputting the name to cout, format the field as follows:

width of 20 spaces

When outputting the money to cout, format the field is as follows:

width of 15 spaces

fixed point, always show the decimal point, precision of two digits after the decimal point

 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 1 Name Money ($) Mikel Harry 3000000.36 
 Thomas Harris 9999999999.99 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 4 

option 2 will allow you to append a record to the end of the file.

Be sure to open the file in append mode so you don't overwrite the previous contents

 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 2 Name: Julie Atkinson 
 Money: 3.50 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 1 Name Money ($) Mikel Harry 3000000.36 Thomas Harris 9999999999.99 Julie Atkinson 3.50 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 4 

option 3 will allow you to search a record by name and output that person's money. The money in this case does not need to be formatted.

 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 3 Name: Julie Atkinson Money: $3.50 1) Output database. 2) Append a record 3) Search by name. 4) Quit. 4 

Clues and Hints:

Don't forget to open the file in append mode, or it will delete the previous contents: myFile.open(fileName, ios::app);

Make sure manipulators are set properly for cout, whitespace matters in this project

Make sure to write a newline after each field if you create "MyDatabase.txt" on your computer: (name money ...)

getline will work well to input your strings from the file.

Pass in your ifstream object instead of cin

Don't forget to use ignore after using any extraction operator (>>)

After reading from the file to the end, if you want to read it again, close it and open it again to reset the read position.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!