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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started