- #1
tebes
- 39
- 0
Homework Statement
After I typed in the name, and tested it by running " lookup " under "option". But the "name:" showed nothing.
Code:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
const int name_length = 20;
struct student
{
int idnum;
char name[name_length];
char gender;
};
void menu(int *);
int main()
{
student kbccstudent[500];
int p=5,y,procceed;
for(int x=0; x<500; x++)
{
kbccstudent[x].idnum = 0;
kbccstudent[x].name[0] = ' ';
kbccstudent[x].gender = ' ' ;
}
while(p!=4)
{
menu(&p);
switch(p)
{
case(1):
{
cout<<"What entry to update? \n";
cin>>y;
cout<<"\nEnter student name? \n";
cin.getline(kbccstudent[y].name, name_length);
cin.ignore(name_length,'\n');
cout<<"\nEnter student ID ? \n";
cin>>kbccstudent[y].idnum;
cout<<"\nEnter student gender? (m/f) \n";
cin>>kbccstudent[y].gender;
cout<<"Database updated. \n";
break;
}
case(2):
{
loop:
cout<<"What entry to update? \n";
cin>>y;
cout<<"\nStudent record "<<y
<<"\nName: "<<kbccstudent[y].name
<<"\nID: "<<kbccstudent[y].idnum
<<"\nGender: "<<kbccstudent[y].gender
<<"\nPress 1 to procceed\n";
cin>>procceed;
if(procceed == 1)
{
cout<<"\nEnter student name? \n";
cin.getline(kbccstudent[y].name,name_length);
cin.ignore(name_length,'\n');
cout<<"\nEnter student ID ? \n";
cin>>kbccstudent[y].idnum;
cout<<"\nEnter student gender? (m/f) \n";
cin>>kbccstudent[y].gender;
cout<<"Database updated. \n";
}
else
{
cout<<"\nNot the right student. Going back\n";
goto loop;
}
break;
}
case(3):
{
cout<<"What entry to lookup? \n";
cin>>y;
cout<<"\nStudent record "<<y
<<"\nName: "<<kbccstudent[y].name
<<"\nID: "<<kbccstudent[y].idnum
<<"\nGender: "<<kbccstudent[y].gender;
break;
}
case(4):
{
cout<<"Warning , window to be closed.\n";
system("pause");
exit(0);
}
}
}
system("pause");
return 0;
}
void menu(int *p)
{
cout<<"\nStudent Record Database \n"
<<"----------------------- \n"
<<"Options \n"
<<"1. Add student \n"
<<"2. Update record \n"
<<"3. Lookup record \n"
<<"4. Quit \n"
<<"Selection ? ";
cin>>*p;
}