The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
C++ console application that will store and retrieve names and addresses in a text file.
The program should do the following.
Build upon the code below to complete the assignment.
//Specification: Append and display records in a address database
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void menu(void);
void writeData(void);
void readData(void);
const char FileName[] = "TestAddress.txt";
int main () {
       menu();
       return 0;
}Â //end main
void menu(void) {
//allow user to choose to append records, display records or exit the program
}//end menu
void writeData(void){
//Write the Address Info to a file
//loop while user still has data to write to file
//eg outStream<<name<<"#"; //where # is the delimiter
}//end write data
void readData(void){
//read data from a file
//use the split function to break a
//deliminated line of text into fields
ifstream inMyStream (FileName);
   if (inMyStream.is_open()) {
                       //set character to use as a line between record displaysÂ
                       string recBreaks = "";
                       recBreaks.assign(20,'-');
                       int fieldCount = 0; //keep track of the number of fields read
                       int recordCount = 1; //keep track of the number of records read
                       //read the first field
                       fieldCount = 1;
                       string fieldBuffer;
                       getline (inMyStream, fieldBuffer, '#');
                       while (!inMyStream.eof() ){
                                   //display the field
                                   switch (fieldCount) {
                                               case 1:
                                                           cout << recBreaks << endl;                                         Â
                                                           cout << "record # " << recordCount << endl;
                                                           cout << "Name...." << fieldBuffer << endl; break;
                                               case 2:
                                                           cout << "Street.." << fieldBuffer << endl; break;
                                               case 3:
                                                           cout << "City...." << fieldBuffer << endl; break;
                                               case 4:
                                                           cout << "State..." << fieldBuffer << endl; break;
                                               case 5:
                                                           cout << "Zip....." << fieldBuffer << endl;
                                                           fieldCount = 0;
                                                           recordCount++;            break;                                                Â
                                   }
                                   //read the next field
                                   getline (inMyStream, fieldBuffer, '#');
           fieldCount++;
      }
             cout << recBreaks << endl;   Â
      inMyStream.close();
}//end read data
Step 2:Â Processing Logic
Using the pseudocode below, write the code that will meet the requirements.
The pseudocode for the writeData function is shown below.
Start
     open the text file to append
     start do while loop
                  Allow user to enter name
                   store name (using getline method)
                  Allow user to enter city
                   store city (using getline method)
                   .
                   .
                   write name, city, etc. to the file
     end loop
     close the file
End
The program input should appear similar to this.
Append Records
Name..........John Smith
Street.........902 Union Ave
City............Any Town
State...........TX
Zip Code......78552
"Enter another Record? (Y/N) "
The file structure should look like this.
John Smith, 902 Union Ave, Any Town, TX, 79552
Eric Jones, 345 State Way, Fresno, CA, 93432
...
The file output should appear similar to the following.
Show Records
__________________________________________
Record #1
Name...........John Smith
Street..........902 Union Ave
City.............Any Town
State...........TX
Zip Code......78552
__________________________________________
Record #2
Name...........Eric Jones
Street..........345 State Way
City.............Fresno
State...........CA
Zip Code.......93432
__________________________________________
(A)ppend Records, (S)how Records, (E)xit
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly