Hi,
I've done a program about Sequential files. One of the functions asked for Update record. I have a problem, I'm trying to create a menu(switch statement) inside of the update function, asking about attributes for update but it runs another menu function done by myself. As below
void menu(char &choice)
{
cout<<"Enter choice 'A' to add all students to a file"<<endl;
cout<<"Enter choice 'B' to add additional students to the file"<<endl;
cout<<"Enter choice 'R' to read and display content of the file"<<endl;
cout<<"Enter choice 'U' to alter any of the given attributes of a student details"<<endl;
cout<<"Enter choice 'D' to show how to delete a student by marking the record"<<endl;
cout<<"Enter choice 'N' to show the students who haven't been deleted from the system"<<endl;
cout<<"Enter choice 'E' to close the system\n"<<endl;
cout<<"Enter one of the option, please"<<endl;
cin >> choice;
}
void updateDetails(fstream & file) //this is the update function
{
S rec;
long len;
int regNumb;
char option;
cout<<"Enter registration number of student to be update:"<<endl;
cin>>regNumb;
file.seekg (0,ios::beg); //0 bytes from beginning of file(ios::beg)
file.read(reinterpret_cast<char*>(&rec),len);
while (!( file.eof()))
{
if (regNumb == rec.regisNumb)
{
cout<<"What kind of attribute do you want to update?"<<endl;
menu (option);
cout<<"A -Registration number"<<endl;
cout<<"B -Name of the student"<<endl;
cout<<"C -Student address"<<endl;
cout<<"D -Date of registration"<<endl;
cout<<"E -Name of the modules"<<endl;
cout<<"F -Mark of modules"<<endl;
cout<<"G -Exit"<<endl;
switch(option)
{
case 'A' :
{
cout<<"Enter registration number:"<<endl;
cin>>rec.regisNumb;
break;
}
case 'B' :
{
cout <<"Enter name of student:"<<endl;
cin.getline(rec.name, MAXNAME);
break;
}
case 'C':
{
cout <<"Enter student address:"<<endl;
cin.getline(rec.address,30);
break;
}
case 'D':
{
cout <<"Enter day of registration:"<<endl;
cin>>rec.datRegi.day;
cout <<"Enter month of registration:"<<endl;
cin>>rec.datRegi.month;
cout <<"Enter year of registration:"<<endl;
cin>>rec.datRegi.year;
break;
}
case 'E':
{
cout <<"Enter name of modules:"<<endl;
for(int j=0;j<rec.arraysize; j++)
{
cin>>rec.modArray[j].moduleName;
cout<<endl;
}
break;
}
case 'F':
{
cout <<"Enter module marks:"<<endl;
for(int j=0;j<rec.arraysize; j++)
{
cout<<rec.modArray[j].moduleMark<<endl;
}
break;
}
case 'G':
{
cout<<"Exit"<<endl;
break;
}
}
!!This is my program c++!!!
What kind of attribute do you want to update?"
A -Registration number
B -Name of the student
C -Student address
D -Date of registration
E -Name of the modules
F -Mark of modules
G -Exit
Enter choice 'A' to add all students to a file
Enter choice 'B' to add additional students to the file
Enter choice 'R' to read and display content of the file
Enter choice 'U' to alter any of the given attributes of a student details
Enter choice 'D' to show how to delete a student by marking the record
Enter choice 'N' to show the students who haven't been deleted from the system
Enter choice 'E' to close the system
Enter one of the option, please
F
You must enter either A, B, R, U, D, N or E