Question: Hi, I need help constructing a function that would store the user's input into a text file. Please assist me with this in C++ language.

Hi, I need help constructing a function that would store the user's input into a text file. Please assist me with this in C++ language. Provide comments and screenshot of the output. Thanks

Here is what I have thus far:

#include

#include

#include

//#include "student.h"

using namespace std;

int main()

{

bool x = true;

//student mystudent ("class.txt");

char choice;

string name[100];

int id[100];

int count = 0;

bool flag = true;

cout << "S: sign-up" << endl;

cout << "P: print" << endl;

cout << "Q: quit" << endl;

cout << "Enter choice: ";

cin >> choice;

do {

if (choice == 's' || choice == 'S')

{

cout << "Name:";

cin >> name[count];

cout << " ID:";

cin >> id[count];

for (int i = 0; i < count; ++i)

{

if (id[i] == id[count])

{

flag = true;

break;

}

}

if (flag == true)

{

cout << "The name and id have already been added" << endl;

flag = false;

}

else

{

cout << name[count] << " has been added " << endl;

count++;

}

}

else if (choice == 'P' || choice == 'p')

{

for (int i = 0; i < count; ++i)

{

cout << "Name: " << name[i] << " ID: " << id[i] << endl;

}

}

else

{

exit(0);

}

cout << "S: sign-up" << endl;

cout << "P: print" << endl;

cout << "Q: quit" << endl;

cout << "Enter choice: ";

cin >> choice;

} while (x);

system("pause");

return 0;

}

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!