Question: I need help with this program not working properly //Specification: Append and display records in a address database #include #include #include using namespace std; void

I need help with this program not working properly

//Specification: Append and display records in a address database

#include

#include

#include

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

char userEnter= '-';

do

{

// do you want to apprend, show records or E for exit

cin >> userEnter;

userEnter = toupper(userEnter);

switch (userEnter)

{

case 'A':

writeData();

break;

case 'S':

// reading the records from file

writeData();

break;

}

} while (userEnter != 'E');

}//end menu

void writeData(void) {

//Write the Address Info to a file

ofstream outMyStream(fileName, ios::app);

if (outMyStream.is_open())

{

string name, street, city, state, zip;

cout << "Enter your name: ";

getline(cin, name);

outMyStream << name << '#';

// do this for all the address

}

outMyStream.close();

//loop while user still has data to write to file

//eg outStream<

}//end write data

void readData(void) {

ifstream inMyStream(fileName);

if (inMyStream.is_open())

{

string delim = "";

delim.assign(20, '-');

int fieldCount = 0;

int recordCount = 1;

fieldCount = 1;

string fieldBuffer;

getline(inMyStream, fieldBuffer, '#');

while (!inMyStream.eof())

{

switch (fieldCount)

{

case 1:

cout << delim << 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;

default:

break;

}

getline(inMyStream, fieldBuffer, '#');

inMyStream.close();

}

}

}

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!