Hey guys, I can't wrap my head around these 5 functions and statement to call the function. I've written comments on the areas I cant figure out and what the functions need to do.
The program is a menu driven program that keeps track of a list of student's names using vector.
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
usingnamespace std;
//function prototypes
int read_file(string, vector<string>&);
void display_all(vector<string>);
void add_name(vector<string>&);
void delete_name(vector<string>&);
void quit_program(string, vector<string>&);
int main()
{
char cInput;
string strFileName;
vector<string> vecStudent;
cout<<"Please enter the data file name (with location): ";
cin >> strFileName;
//Need to write a statement that calls a function to read the content of the
//input file into the vector vecStudent
while (true)
{
cout<<"----------------------------------------"<<endl;
cout<<" Student Record - Main Menu "<<endl;
cout<<"----------------------------------------"<<endl;
cout<<" Enter 1 to display ALL students"<<endl;
cout<<" Enter 2 to add a student name"<<endl;
cout<<" Enter 3 to delete a student name"<<endl;
cout<<" Enter 4 to SAVE and quit the program"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"Enter menu option: ";
cin>>cInput;
switch (cInput)
{
case'1':
display_all(vecStudent);
break;
case'2':
add_name(vecStudent);
break;
case'3':
delete_name(vecStudent);
break;
case'4':
quit_program(strFileName, vecStudent);
return 0;
default:
cout<<"invalid input"<<endl;
break;
}
}
return 0;
}
//Still need to define functions
int read_file(string strFileName, vector<string>&vecThisStudent)
{
//This function read the content of the file into the vector. If there
//is an error, an error code should be returned.
}
void display_all(vector<string> vecThisStudent)
{
}
void add_name(vector<string>&vecThisStudent)
{
}
void delete_name(vector<string>&vecThisStudent)
{
}
void quit_program(string strFileName, vector<string>&vecThisStudent)
{
//This is the function that should write the vector’s content back to the file.
cout<<"Thanks for using the program. Program terminated"<<endl;
}