Question: #include #include #include #include using namespace std; // Saving Data Program // This program will help the user to save their event, celebrity, and fan

#include

#include

#include

#include

using namespace std;

// Saving Data Program

// This program will help the user to save their event, celebrity, and fan favorite to a file.

// The user can add maximum 10 a new item into a file.

const int event {50};

const int celebrity {50};

const int fan {50};

const int MAX {10}; // the maximum for the user to add into a file

struct event

{

char event[EVENT]

char celebrity[CELEBRITY];

char fan[FAN];

};

void read_event(event & new_event);

void display_event(event & to_display);

int load_events(event all_events[]);

bool save_events(event all_events[], int num_events);

bool again();

int main()

{

event my_event;

event list[MAX];

int num_events{0};

int i {0};

num_events = load_events(LIST);

i = num_events;

if (i < MAX)

do

{

read_event(LIST[i]);

display_event(LIST[i]);

++i;

} while (i < MAX && again());

num_events = i;

if (save_events(LIST, num_events))

cout <<" All events are saved, Have a nice day!" << endl;

else

cout <<" FILE CORRUPTION ERROR!!!" << endl;

return 0;

}

int load_events(event array[])

{

ifstream file.in;

int i {0};

file_in.open("event_list.txt");

if (!file_in)

return 0;

file_in.get(array[i].event, EVENT, ':');

file_in.ignore(100, ':');

while (file_in && !file_in.eof())

{

// We about to process it

file_in.get(array[i].celebrity, CELEBRITY, ':');

file_in.ignore(100, ':');

file_in.get(array[i].fan, FAN, ':');

file_in.ignore(100, ':');

++i;

// read again

file_in.get(array[i].event, EVENT, ':');

file_in.ignore(100, ':');

}

return i;

}

// this function will write all the events to an external data file

// if we cannot connect to the file return false

bool save_events(event all[], int num)

{

ofstream file_out;

file_out.open("event_list.txt");

if (!file_out) return false;

for ( int i{0}; i < num; ++i)

file_out << all[i].event <<':'

<< all[i].celebrity <<':'

<< all[i].fan << endl;

return true;

}

// ask the user if they want to it again ?

bool again()

{

char response {'n'};

cout << "Do you want to enter another? ";

cin >> response;

cin.ignore(100, ' ');

if (toupper(response) == 'Y')

return true;

return false;

}

// all of the event's information

void read_event(event & new_event)

{

cout <<" Please enter the event's name: ";

cin.get(new_event.name, NAME, ' ');

cin.ingnore(100, ' ')

cout <<" Please enter the celebrity : ";

cin.get(new_event.celebrity, CELEBRITY);

cin.ignore(100. ' ');

cout <<" Please enter your fan favorite : ";

cin.get(new_event.fan, FAN);

cin.ignore(100, ' ');

}

// this function will display all event to the user

void display_event(event & to_display)

{

cout << to_display.event <<" Celebrity :" <

<< " Fan Favorite : " << to_display.fan << endl;

}

what errors that I have ? and how can I fix it ?

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!