1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
char menu[10];
bool StudentMenu()
{
system ("CLS");
int j;
cout<<"**********************************\n";
cout<<"********** Student Menu **********\n";
cout<<"1. Add New Student Data\n";
cout<<"2. List Student\n";
cout<<"3. Change Student Information\n";
cout<<"4. Delete Student\n";
cout<<"5. Save Student\n";
cout<<"6. Main Menu\n";
cout<<"Number of Student = "<<NumberofStudent<<endl;
cout<<"Please enter your choice: ";
cin.getline(menu,10);
if(menu[0] == '1')
{
system ("CLS");
cout<<"Name : ";
cin.getline(S[NumberofStudent].GetName(),51);
cout<<"ID/Matrix no. : ";
cin.getline(S[NumberofStudent].GetId(),11);
cout<<"Nationality : ";
cin.getline(S[NumberofStudent].GetNation(),21);
cout<<"Address : ";
cin.getline(S[NumberofStudent].GetAddress(),101);
cout<<"Date of registration (eg. 01/07/2009) : ";
cin.getline(S[NumberofStudent].GetDate(),11);
cout<<"Falculty (eg. FK) : ";
cin.getline(S[NumberofStudent].GetFaculty(),6);
cout<<"Year (eg. 08/09) : ";
cin.getline(S[NumberofStudent].GetYear(),6);
cout<<"Grades/CGPA : ";
cin.getline(S[NumberofStudent].GetGrades(),5);
cout<<"Subjects taken : ";
cin.getline(S[NumberofStudent].GetSubTak(),101);
cout<<"Subjects to be taken : ";
cin.getline(S[NumberofStudent].GetSubTobeTak(),101);
S[NumberofStudent].Empty = false;
++NumberofStudent;
return true;
}
else if(menu[0] == '2')
{
system ("CLS");
for(int k=0;k<NumberofStudent;++k)
{
cout<<"Record "<<k+1<<"\n";
cout<<"Name : "<<S[k].GetName()<<"\n";
cout<<"ID/Matrix no. : "<<S[k].GetId()<<"\n";
cout<<"Nationality : "<<S[k].GetNation()<<"\n";
cout<<"Address : "<<S[k].GetAddress()<<"\n";
cout<<"Date of registration : "<<S[k].GetDate()<<"\n";
cout<<"Falculty : "<<S[k].GetFaculty()<<"\n";
cout<<"Year : "<<S[k].GetYear()<<"\n";
cout<<"Grades/CGPA : "<<S[k].GetGrades()<<"\n";
cout<<"Subjects taken : "<<S[k].GetSubTak()<<"\n";
cout<<"Subjects to be taken : "<<S[k].GetSubToBeTak()<<"\n";
cout<<"Press 'enter' for next record"<<endl;
cin.get();
}
cout<<"No more Student Record!"<<endl;
return true;
}
else if(menu[0] == '3')
{
system ("CLS");
cout<<"Please enter the Student ID/Matrix no. to change information : ";
cin.getline(menu,10);
for(j=0;j<NumberofStudent;++j)
{
if(strcmp(menu,S[j].GetId()) == 0)
{
cout<<"Please key in student new data."<<endl;
cout<<"Name ("<<S[j].GetName()<<") :";
cin.getline(S[j].GetName(),51);
cout<<"Nationality ("<<S[j].GetNation()<<") :";
cin.getline(S[j].GetNation(),21);
cout<<"Address ("<<S[j].GetAddress() <<") :";
cin.getline(S[j].GetAddress(),101);
cout<<"Date of registration ("<<S[j].GetDate() <<") :";
cin.getline(S[j].GetDate(),11);
cout<<"Faculty ("<<S[j].GetFaculty()<<") :";
cin.getline(S[j].GetFaculty(),6);
cout<<"Year ("<<S[j].GetYear()<<") :";
cin.getline(S[j].GetYear(),6);
cout<<"Grades/CGPA ("<<S[j].GetGrades()<<") :";
cin.getline(S[j].GetGrades(),5);
cout<<"Subjects taken ("<<S[j].GetSubTak()<<") :";
cin.getline(S[j].GetSubTak(),101);
cout<<"Subjects to be taken ("<<S[j].GetSubToBeTak()<<") :";
cin.getline(S[j].GetSubToBeTak(),101);
return true;
}
}
cout<<"Student record not found!"<<endl;
return true;
}
else if(menu[0] == '4')
{
system ("CLS");
cout<<"Please enter the Student ID/Matrix no. to Delete : ";
cin.getline(menu,10);
for(j=0;j<NumberofStudent;++j)
{
if(strcmp(menu,S[j].GetId()) == 0)
{
cout<<"Are you sure Delete the Student ("<<S[j].GetName()<<")? (y/n) : ";
cin.getline(menu,10);
if(menu[0] == 'y' || menu[0] == 'Y')
{
while(j+1<NumberofStudent)
{
strcpy(S[j].GetId(),S[j+1].GetId());
strcpy(S[j].GetName(),S[j+1].GetName());
strcpy(S[j].GetNation(),S[j+1].GetNation());
strcpy(S[j].GetAddress(),S[j+1].GetAddress());
strcpy(S[j].GetDate(),S[j+1].GetDate());
strcpy(S[j].GetFaculty(),S[j+1].GetFaculty());
strcpy(S[j].GetYear(),S[j+1].GetYear());
strcpy(S[j].GetGrades(),S[j+1].GetGrades());
strcpy(S[j].GetSubTak(),S[j+1].GetSubTak());
strcpy(S[j].GetSubToBeTak(),S[j+1].GetSubToBeTak());
++j;
}
S[j].Empty = true;
--NumberofStudent;
}
return true;
}
}
cout<<"Student record not found!"<<endl;
return true;
}
else if(menu[0] == '5')
{
system ("CLS");
SaveStudentRecord();
return true;
}
else if(menu[0] == '6')
return false;
else
{
system ("CLS");
cout<<"Unknown Command. Please try again!\n";
return true;
}
return false;
}
class Staff:public unimas
{
public:
Staff() {}
~Staff() {}
char* GetPost() {return Post;}
void SetPost(char post) { Post[21]=post;}
char* GetSalary() {return Salary;}
void SetSalary(char salary) {Salary[11]=salary;}
char* GetPaper() {return Paper;}
void SetPaper(char peper) {Paper[101]=paper;}
bool Empty; //is this record empty?
protected:
char Post[21];
char Salary[11];
char Paper[101];
};
Staff B[1000];
int NumberofStaff;
void InitializeStaff()
{
for(int i=0;i<1000;++i)
{
B[i].Empty = true;
}
NumberofBook = 0;
}
bool OpenStaffRecord()
{
InitializeStaff();
ifstream iB;
iB.clear();
iB.open("./debug/Staff.dat",ios::in);
if(!iB) return false;
int NumFields = 0;
while(!iB.eof())
{
if(NumFields == 7)
{
B[NumberofStaff].Empty = false;
++NumberofStaff;
NumFields = 0;
}
if(NumFields == 0)
{
iB.getline(B[NumberofStaff].GetName(),51,';');
++NumFields;
}
else if(NumFields == 1)
{
iB.getline(B[NumberofStaff].GetId(),11,';');
++NumFields;
}
else if(NumFields == 2)
{
iB.getline(B[NumberofStaff].GetNation(),21,';');
++NumFields;
}
else if(NumFields == 3)
{
iB.getline(B[NumberofStaff].GetNation(),21,';');
++NumFields;
}
else if(NumFields == 4)
{
iB.getline(B[NumberofStaff].GetAddress(),101,';');
++NumFields;
}
else if(NumFields == 5)
{
iB.getline(B[NumberofStaff].GetPost(),21,';');
++NumFields;
}
else if(NumFields == 6)
{
iB.getline(B[NumberofStaff].GetSalary,11,';');
++NumFields;
}
else if(NumFields == 7)
{
iB.getline(B[NumberofStaff].GetPaper(),101,';');
++NumFields;
}
}
iB.close();
return true;
}
bool SaveStaffRecord()
{
ofstream oB("./debug/Staff.dat",ofstream::out | ofstream::trunc );
if(!oB) return false;
for(int j=0;j<NumberofStaff;++j)
{ if(B[j].Empty == false)
{
oB.write(B[j].GetId(),strlen(B[j].GetId()));
oB.write(";",1);
oB.write(B[j].GetName(),strlen(B[j].GetName()));
oB.write(";",1);
oB.write(B[j].GetNation(),strlen(B[j].GetNation()));
oB.write(";",1);
oB.write(B[j].GetAddress(),strlen(B[j].GetAddress()));
oB.write(";",1);
oB.write(B[j].GetPost(),strlen(B[j].GetPost()));
oB.write(";",1);
oB.write(B[j].GetSalary(),strlen(B[j].GetSalary()));
oB.write(";",1);
}
}
oB.close();
return true;
}
| |