Guest User

Untitled

a guest
Dec 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.59 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<fstream>
  5. #include <sstream>
  6. #include <string>
  7. #include <iterator>
  8. #include <vector>
  9. #include <iomanip>
  10. #include <cstdlib>
  11.  
  12.  
  13. using namespace std;
  14.  
  15.  
  16. struct student
  17. {
  18. //student info.
  19. string id, firstname, lastname, sex, age, clas;
  20.  
  21. };
  22.  
  23. void addstudent() //get student data.
  24. {
  25. char inchoice;
  26. int i;
  27. student stu;
  28. ofstream outputfile;
  29. cout<< "\npress 1 again to confirm add student: ";cin>>inchoice;
  30. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  31. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='1')){
  32.  
  33. cout<< "\n\n\t\t\tADD STUDENT"<<endl;
  34. cout<<"\tId number: "; cin>>stu.id;
  35. cout<<"\tFirst Name: "; cin>>stu.firstname;
  36. cout<<"\tLast Name: "; cin>>stu.lastname;
  37. cout<<"\tClass: "; cin>>stu.clas;
  38. cout<<"\tSex: "; cin>>stu.sex;
  39. cout<<"\tAge: "; cin>>stu.age;
  40.  
  41.  
  42. outputfile.open("student.txt",ios::app);
  43. outputfile<<stu.id<<" "<<stu.firstname<<" "<<stu.lastname<<" "<<stu.clas<<" "<<stu.sex<<" "<<stu.age<<endl;
  44. outputfile.close();
  45. cout<<"\n\n\t\t\tStudent has been Added!!!.\n";
  46. cout<<"\n\n\n\npress 'Y' to add another student or 'N' to finish: "; cin>>inchoice;
  47.  
  48. }
  49. }
  50. system("cls");
  51. return;
  52. }
  53.  
  54.  
  55. void editstudent()
  56. {
  57. char inchoice;
  58. int i;
  59.  
  60. cout<< "\npress 2 again to confirm edit student: ";cin>>inchoice;
  61. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  62. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='2')){
  63. cout<< "\n\n\t\t\tEDIT STUDENT"<<endl;
  64. string id;
  65. cout<<"\n Enter the student's ID number: ";
  66. cin>>id;
  67.  
  68. student stu;
  69. fstream intofile ("student.txt");
  70. fstream temporalfile ("temp.txt",ios::app);
  71. string line;
  72.  
  73. while(std::getline(intofile, line))
  74. {
  75. istringstream ss(line);
  76. std::istream_iterator<std::string> begin(ss), end;
  77. //putting all the tokens in the vector
  78. std::vector<std::string> arrayTokens(begin, end);
  79.  
  80. vector<string>::iterator it;
  81. int i=0,flag=0;
  82. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  83. {
  84. if(i==0 && id==*it)
  85. {
  86. flag=1;
  87. }
  88. else
  89. break;
  90. i++;
  91. }
  92. if(flag==1)
  93. {
  94. cout<<"FirstName:"; cin>>stu.firstname;
  95. cout<<"LastName:"; cin>>stu.lastname;
  96. cout<<"Class:"; cin>>stu.clas;
  97. cout<<"Sex: "; cin>>stu.sex;
  98. cout<<"Age: "; cin>>stu.age;
  99.  
  100. temporalfile<<id<<" "<<stu.firstname<<" "<<stu.lastname<<" "<<stu.clas<<" "<<stu.sex<<" "<<stu.age<<endl;
  101. cout<<"\nstudent information has been successfully edited.\n";
  102. }
  103. else
  104. {
  105. temporalfile<<line<<endl;
  106. }
  107.  
  108.  
  109. }
  110. intofile.close();
  111. temporalfile.close();
  112. remove("student.txt");
  113. rename("temp.txt","student.txt");
  114. cout<<"\n\n\n\npress 'Y' to edit another student or 'N' to finish: "; cin>>inchoice;
  115. }
  116. }
  117. system("cls");
  118. }
  119.  
  120. void deletestudent()
  121. {
  122. char inchoice;
  123. int i;
  124.  
  125. cout<< "\npress 3 again to confirm delete student: ";cin>>inchoice;
  126. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  127. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='3')){
  128. cout<< "\n\n\t\t\tDELETE STUDENT"<<endl;
  129. string id;
  130. cout<<"Enter Id number: ";
  131. cin>>id;
  132.  
  133. student stu;
  134. fstream intofile ("student.txt");
  135. fstream temporalfile ("temp.txt",ios::app);
  136. string line;
  137.  
  138. while(std::getline(intofile, line))
  139. {
  140. istringstream ss(line);
  141. std::istream_iterator<std::string> begin(ss), end;
  142. //putting all the tokens in the vector
  143. std::vector<std::string> arrayTokens(begin, end);
  144.  
  145. vector<string>::iterator it;
  146. int i=0,flag=0;
  147. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  148. {
  149. if(i==0 && id==*it)
  150. {
  151. flag=1;
  152. }
  153. else
  154. break;
  155. i++;
  156. }
  157. if(flag!=1)
  158. {
  159. temporalfile<<line<<endl;
  160. }
  161. else
  162. {
  163. cout<<"\n Student has been successfully deleted \n";
  164. }
  165.  
  166.  
  167. }
  168. intofile.close();
  169. temporalfile.close();
  170. remove("student.txt");
  171. rename("temp.txt","student.txt");
  172. cout<<"\n\n\n\npress 'Y' to delete another student or 'N' to finish: "; cin>>inchoice;
  173. }
  174. }
  175.  
  176. system("cls");
  177. }
  178.  
  179.  
  180. void studentslist()
  181. {
  182. ifstream outputfile("student.txt");
  183. string content,i;
  184. cout<<endl<<"\t\t\t\t ALL STUDENTS \t\t\n\n\n";
  185. cout << setw(15) <<"ID NUMBER" << setw(15) << "FIRST_NAME" << setw(15) << "LAST_NAME" <<setw(15) << "CLASS"<<setw(15)<<"SEX"<<setw(15)<<"AGE"<< endl<<endl;
  186. string line;
  187. while(std::getline(outputfile, line))
  188. {
  189. istringstream ss(line);
  190. std::istream_iterator<std::string> begin(ss), end;
  191.  
  192. //putting all the tokens in the vector
  193. std::vector<std::string> arrayTokens(begin, end);
  194.  
  195. vector<string>::iterator it;
  196.  
  197. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  198. {
  199.  
  200. cout<<setw(15)<<*it;// prints d.
  201.  
  202. }
  203. std::cout << '\n';
  204.  
  205. }
  206.  
  207. cout<< "\n\n\n\nenter any key to continue to main menu: "; cin>>i;
  208. system("cls");
  209. }
  210.  
  211.  
  212.  
  213.  
  214. //FOR STAFF
  215. struct staff
  216. {
  217. string id, firstname, lastname,sex, age, teachcourse;
  218. };
  219. void addstaff() //get staff data.
  220. {
  221. char inchoice;
  222. int i;
  223. staff sta;
  224. ofstream outputfile;
  225. cout<< "\npress 1 again to confirm add staff: ";cin>>inchoice;
  226. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  227. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='1')){
  228.  
  229.  
  230. cout<< "\n\n\t\t\tADD STAFF"<<endl;
  231. cout<<"\tId number: "; cin>>sta.id;
  232. cout<<"\tFirst Name: "; cin>>sta.firstname;
  233. cout<<"\tLast Name: "; cin>>sta.lastname;
  234. cout<<"\tteachcourse: "; cin>>sta.teachcourse;
  235. cout<<"\tSex: "; cin>>sta.sex;
  236. cout<<"\tAge: "; cin>>sta.age;
  237.  
  238. //output to student file.
  239. outputfile.open("staff.txt",ios::app);
  240. outputfile<<sta.id<<" "<<sta.firstname<<" "<<sta.lastname<<" "<<sta.teachcourse<<" "<<sta.sex<<" "<<sta.age<<endl;
  241. outputfile.close();
  242. cout<<"\n\n\t\t\tStaff has been Added!!!.\n";
  243. cout<<"\n\n\n\npress 'Y' to add another staff or 'N' to finish: "; cin>>inchoice;
  244.  
  245. }
  246. }
  247. system("cls");
  248. return;
  249. }
  250.  
  251. void editstaff()
  252. {
  253. char inchoice;
  254. int i;
  255.  
  256. cout<< "\npress 2 again to confirm edit staff: ";cin>>inchoice;
  257. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  258. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='2')){
  259. cout<< "\n\n\t\t\tEDIT STAFF"<<endl;
  260. string id;
  261. cout<<"\n Enter the staff's ID number: ";
  262. cin>>id;
  263.  
  264. staff sta;
  265. fstream intofile ("staff.txt");
  266. fstream temporalfile ("temp1.txt",ios::app);
  267. string line;
  268.  
  269. while(std::getline(intofile, line))
  270. {
  271. istringstream ss(line);
  272. std::istream_iterator<std::string> begin(ss), end;
  273. //putting all the tokens in the vector
  274. std::vector<std::string> arrayTokens(begin, end);
  275.  
  276. vector<string>::iterator it;
  277. int i=0,flag=0;
  278. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  279. {
  280. if(i==0 && id==*it)
  281. {
  282. flag=1;
  283. }
  284. else
  285. break;
  286. i++;
  287. }
  288. if(flag==1)
  289. {
  290. cout<<"FirstName:"; cin>>sta.firstname;
  291. cout<<"LastName:"; cin>>sta.lastname;
  292. cout<<"Class:"; cin>>sta.teachcourse;
  293. cout<<"Sex: "; cin>>sta.sex;
  294. cout<<"Age: "; cin>>sta.age;
  295.  
  296. temporalfile<<id<<" "<<sta.firstname<<" "<<sta.lastname<<" "<<sta.teachcourse<<" "<<sta.sex<<" "<<sta.age<<endl;
  297. cout<<"\nstaff has been successfully edited.\n";
  298. }
  299. else
  300. {
  301. temporalfile<<line<<endl;
  302. }
  303.  
  304.  
  305. }
  306. intofile.close();
  307. temporalfile.close();
  308. remove("staff.txt");
  309. rename("temp1.txt","staff.txt");
  310. cout<<"\n\n\n\npress 'Y' to edit another staff or 'N' to finish: "; cin>>inchoice;
  311. }
  312. }
  313. system("cls");
  314. }
  315.  
  316. void deletestaff()
  317. {
  318. char inchoice;
  319. int i;
  320.  
  321. cout<< "\npress 3 again to confirm delete student: ";cin>>inchoice;
  322. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  323. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='3')){
  324. cout<< "\n\n\t\t\tDELETE STAFF"<<endl;
  325. string id;
  326. cout<<"Enter Id number: ";
  327. cin>>id;
  328.  
  329. staff sta;
  330. fstream intofile ("staff.txt");
  331. fstream temporalfile ("temp1.txt",ios::app);
  332. string line;
  333.  
  334. while(std::getline(intofile, line))
  335. {
  336. istringstream ss(line);
  337. std::istream_iterator<std::string> begin(ss), end;
  338. //putting all the tokens in the vector
  339. std::vector<std::string> arrayTokens(begin, end);
  340.  
  341. vector<string>::iterator it;
  342. int i=0,flag=0;
  343. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  344. {
  345. if(i==0 && id==*it)
  346. {
  347. flag=1;
  348. }
  349. else
  350. break;
  351. i++;
  352. }
  353. if(flag!=1)
  354. {
  355. temporalfile<<line<<endl;
  356. }
  357. else
  358. {
  359. cout<<"\n Staff has been successfully deleted \n";
  360. }
  361.  
  362.  
  363. }
  364. intofile.close();
  365. temporalfile.close();
  366. remove("staff.txt");
  367. rename("temp1.txt","staff.txt");
  368.  
  369. cout<<"\n\n\n\npress 'Y' to delete another student or 'N' to finish: "; cin>>inchoice;
  370. }
  371. }
  372. system("cls");
  373. }
  374.  
  375.  
  376. void staffslist()
  377. {
  378. string i;
  379. ifstream outputfile("staff.txt");
  380. string content;
  381. cout<<endl<<"\t\t\t\t ALL STAFF \t\t\n\n\n";
  382. cout << setw(15) <<"ID NUMBER" << setw(15) << "FIRST_NAME" << setw(15) << "LAST_NAME" <<setw(15) << "SUBJECT_TAKEN"<<setw(15)<<"SEX"<<setw(15)<<"AGE"<< endl<<endl;
  383.  
  384. string line;
  385. while(std::getline(outputfile, line))
  386. {
  387. istringstream ss(line);
  388. std::istream_iterator<std::string> begin(ss), end;
  389.  
  390. //putting all the tokens in the vector
  391. std::vector<std::string> arrayTokens(begin, end);
  392.  
  393. vector<string>::iterator it;
  394.  
  395. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  396. {
  397.  
  398. cout<<setw(15)<<*it;// prints d.
  399.  
  400. }
  401. std::cout << '\n';
  402.  
  403. }
  404.  
  405. cout<< "\n\n\n\nenter any key to continue: "; cin>>i;
  406. system("cls");
  407. }
  408.  
  409.  
  410.  
  411. //FOR COURSES
  412. struct course
  413. {
  414. string code, title, credithrs, tutor;
  415. };
  416. void addcourse() //get course data.
  417. {
  418. char inchoice;
  419. int i;
  420. course cou[1000];
  421. ofstream outputfile;
  422. cout<< "\npress 1 to confirm add course: ";cin>>inchoice;
  423. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  424. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='1')){
  425.  
  426. cout<< "\n\n\t\t\tADD COURSE"<<endl;
  427. cout<<"\tcourse code: "; cin>>cou[i].code;
  428. cout<<"\tcourse title: "; cin>>cou[i].title;
  429. cout<<"\tcredit hours: "; cin>>cou[i].credithrs;
  430. cout<<"\tcourse tutor: "; cin>>cou[i].tutor;
  431.  
  432. //output to student file.
  433. outputfile.open("course.txt",ios::app);
  434. outputfile<<cou[i].code<<" "<<cou[i].title<<" "<<cou[i].credithrs<<" "<<cou[i].tutor<<" "<<endl;
  435. outputfile.close();
  436. cout<<"\n\n\t\t\tCourse has been Added!!!.\n";
  437. cout<<"\n\n\n\npress 'Y' to add another course or 'N' to finish: "; cin>>inchoice;
  438.  
  439. }
  440. }
  441. system("cls");
  442. return;
  443. }
  444.  
  445. void editcourse()
  446. {
  447. char inchoice;
  448. int i;
  449.  
  450. cout<< "\npress 2 again to confirm edit course: ";cin>>inchoice;
  451. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  452. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='2')){
  453. cout<< "\n\n\t\t\tEDIT COURSE"<<endl;
  454. string code;
  455. cout<<"\n Enter the course code: ";
  456. cin>>code;
  457.  
  458. course cou;
  459. fstream intofile ("course.txt");
  460. fstream temporalfile ("temp2.txt",ios::app);
  461. string line;
  462.  
  463. while(std::getline(intofile, line))
  464. {
  465. istringstream ss(line);
  466. std::istream_iterator<std::string> begin(ss), end;
  467. //putting all the tokens in the vector
  468. std::vector<std::string> arrayTokens(begin, end);
  469.  
  470. vector<string>::iterator it;
  471. int i=0,flag=0;
  472. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  473. {
  474. if(i==0 && code==*it)
  475. {
  476. flag=1;
  477. }
  478. else
  479. break;
  480. i++;
  481. }
  482. if(flag==1)
  483. {
  484. cout<<"Course title:"; cin>>cou.title;
  485. cout<<"Credit hours:"; cin>>cou.credithrs;
  486. cout<<"Tutor:"; cin>>cou.tutor;
  487.  
  488. temporalfile<<code<<" "<<cou.title<<" "<<cou.credithrs<<" "<<cou.tutor<<endl;
  489. cout<<"\nCourse information has been successfully edited.\n";
  490. }
  491. else
  492. {
  493. temporalfile<<line<<endl;
  494. }
  495.  
  496.  
  497. }
  498. intofile.close();
  499. temporalfile.close();
  500. remove("course.txt");
  501. rename("temp.txt","course.txt");
  502. cout<<"\n\n\n\npress 'Y' to edit another course or 'N' to finish: "; cin>>inchoice;
  503. }
  504. }
  505. system("cls");
  506. }
  507.  
  508. void deletecourse()
  509. {
  510. char inchoice;
  511. int i;
  512.  
  513. cout<< "\npress 3 again to confirm delete course: ";cin>>inchoice;
  514. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  515. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='3')){
  516. cout<< "\n\n\t\t\tDELETE COURSE"<<endl;
  517. string code;
  518. cout<<"Enter Course Code: ";
  519. cin>>code;
  520.  
  521. course cou;
  522. fstream intofile ("course.txt");
  523. fstream temporalfile ("temp2.txt",ios::app);
  524. string line;
  525.  
  526. while(std::getline(intofile, line))
  527. {
  528. istringstream ss(line);
  529. std::istream_iterator<std::string> begin(ss), end;
  530. //putting all the tokens in the vector
  531. std::vector<std::string> arrayTokens(begin, end);
  532.  
  533. vector<string>::iterator it;
  534. int i=0,flag=0;
  535. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  536. {
  537. if(i==0 && code==*it)
  538. {
  539. flag=1;
  540. }
  541. else
  542. break;
  543. i++;
  544. }
  545. if(flag!=1)
  546. {
  547. temporalfile<<line<<endl;
  548. }
  549. else
  550. {
  551. cout<<"\n Course has been successfully deleted \n";
  552. }
  553.  
  554.  
  555. }
  556. intofile.close();
  557. temporalfile.close();
  558. remove("course.txt");
  559. rename("temp2.txt","course.txt");
  560. cout<<"\n\n\n\npress 'Y' to delete another course or 'N' to finish: "; cin>>inchoice;
  561. }
  562. }
  563.  
  564. system("cls");
  565. }
  566.  
  567.  
  568. void courselist()
  569. {
  570. ifstream outputfile("course.txt");
  571. string content,i;
  572. cout<<endl<<"\t\t\t\t ALL COURSES \t\t\n\n\n";
  573. cout << setw(15) <<"COURSE_CODE" << setw(15) << "COURSE_TITLE" << setw(15) << "CREDIT_HOURS" <<setw(15) << "COURSE_TUTOR"<< endl<<endl;
  574. string line;
  575. while(std::getline(outputfile, line))
  576. {
  577. istringstream ss(line);
  578. std::istream_iterator<std::string> begin(ss), end;
  579.  
  580. //putting all the tokens in the vector
  581. std::vector<std::string> arrayTokens(begin, end);
  582.  
  583. vector<string>::iterator it;
  584.  
  585. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  586. {
  587.  
  588. cout<<setw(15)<<*it;// prints d.
  589.  
  590. }
  591. std::cout << '\n';
  592.  
  593. }
  594.  
  595. cout<< "\n\n\n\nenter any key to continue to main menu: "; cin>>i;
  596. system("cls");
  597. }
  598.  
  599.  
  600.  
  601. struct studentrecord
  602. {
  603. string id, firstname, lastname;
  604. float afrstds, calc, mech , phy, chem;
  605. char afrgrd, calcgrd, mechgrd, phygrd, chemgrd;
  606. string afrem, calcrem, mechrem, phyrem, chemrem;
  607. };
  608. void addstudentrecord() //get student data.
  609. {
  610. char inchoice;
  611. int i;
  612. studentrecord g;
  613. ofstream outputfile;
  614. ofstream outputfile2;
  615. cout<< "\npress 1 again to confirm add student record: ";cin>>inchoice;
  616. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  617. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='1')){
  618.  
  619. cout<< "\n\n\t\t\tRECORD STUDENT GRADE"<<endl;
  620. cout<<"Student ID: ";cin>>g.id;
  621. cout<<"First name: ";cin>>g.firstname;
  622. cout<<"Last name: ";cin>>g.lastname;
  623. cout<<"\n\n\n\t\t\tenter marks for "<<g.firstname<<" "<<g.lastname<<" ("<<g.id<<")"<<endl;
  624.  
  625. cout<<"\n\n\tenter Academic Writing mark: ";cin>>g.afrstds;
  626.  
  627. if (g.afrstds >= 80) g.afrgrd='A'; else if (g.afrstds>= 70) g.afrgrd='B';
  628. else if (g.afrstds>= 60) g.afrgrd='C'; else if (g.afrstds>= 50) g.afrgrd='D'; else if (g.afrstds>= 40) g.afrgrd='E'; else g.afrgrd='F';
  629. if (g.afrstds >= 80) g.afrem="EXCELLENT"; else if (g.afrstds>= 70) g.afrem="V.GOOD"; else if (g.afrstds>= 60) g.afrem="GOOD"; else if (g.afrstds>= 50) g.afrem="CREDIT"; else if (g.afrstds>= 40) g.afrem="PASS"; else g.afrem="FAIL";
  630.  
  631. cout<<"\tenter Math mark: ";cin>>g.calc;
  632. if (g.calc >= 80) g.calcgrd='A'; else if (g.calc>= 70) g.calcgrd='B';
  633. else if (g.calc>= 60) g.calcgrd='C'; else if (g.calc>= 50) g.calcgrd='D'; else if (g.calc>= 40) g.calcgrd='E'; else g.calcgrd='F';
  634. if (g.calc >= 80) g.calcrem="EXCELLENT"; else if (g.calc>= 70) g.calcrem="V.GOOD"; else if (g.calc>= 60) g.calcrem="GOOD"; else if (g.calc>= 50) g.calcrem="CREDIT"; else if (g.calc>= 40) g.calcrem="PASS"; else g.calcrem="FAIL";
  635.  
  636. cout<<"\tenter Programming1 mark for: ";cin>>g.mech ;
  637. if (g.mech >= 80) g.mechgrd='A'; else if (g.mech >= 70) g.mechgrd='B'; else if (g.mech >= 60) g.mechgrd='C'; else if (g.mech >= 50) g.mechgrd='D'; else if (g.mech >= 40) g.mechgrd='E'; else g.mechgrd='F';
  638. if (g.mech >= 80) g.mechrem="EXCELLENT";
  639. else if (g.mech >= 70) g.mechrem="V.GOOD"; else if (g.mech >= 60) g.mechrem="GOOD"; else if (g.mech >= 50) g.mechrem="CREDIT"; else if (g.mech >= 40) g.mechrem="PASS"; else g.mechrem="FAIL";
  640.  
  641. cout<<"\tStatistics mark: "; cin>>g.phy;
  642. if (g.phy >= 80) g.phygrd='A'; else if (g.phy>= 70) g.phygrd='B'; else if (g.phy>= 60) g.phygrd='C'; else if (g.phy>= 50) g.phygrd='D'; else if (g.phy>= 40) g.phygrd='E'; else g.phygrd='F';
  643. if (g.phy >= 80) g.phyrem="EXCELLENT"; else if (g.phy>= 70) g.phyrem="V.GOOD"; else if (g.phy>= 60) g.phyrem="GOOD"; else if (g.phy>= 50) g.phyrem="CREDIT"; else if (g.phy>= 40) g.phyrem="PASS"; else g.phyrem="FAIL";
  644.  
  645. cout<<"\tCulture mark: "; cin>>g.chem;
  646. if (g.chem >= 80) g.chemgrd='A'; else if (g.chem>= 70) g.chemgrd='B'; else if (g.chem>= 60) g.chemgrd='C'; else if (g.chem>= 50) g.chemgrd='D'; else if (g.chem>= 40) g.chemgrd='E'; else g.chemgrd='F';
  647. if (g.chem >= 80) g.chemrem="EXCELLENT"; else if (g.chem>= 70) g.chemrem="V.GOOD"; else if (g.chem>= 60) g.chemrem="GOOD"; else if (g.chem>= 50) g.chemrem="CREDIT"; else if (g.chem>= 40) g.chemrem="PASS"; else g.chemrem="FAIL";
  648.  
  649. //output to student record file.
  650. outputfile.open("record.txt",ios::app);
  651. outputfile<<g.id<<" "<<g.firstname<<" "<<g.lastname<<" "<<g.afrgrd<<" "<<g.calcgrd<<" "<<g.mechgrd<<" "<<g.phygrd<<" "<<g.chemgrd<<endl<<endl;
  652. outputfile2.open("record2.txt",ios::app);
  653. outputfile2<<g.id<<endl<<g.firstname<<endl<<g.lastname<<endl<<setw(10)<<g.afrstds<<" "<<setw(10)<<g.afrgrd<<" "<<setw(15)<<g.afrem<<endl<<setw(10)<<g.calc<<" "<<setw(10)<<g.calcgrd<<" "<<setw(15)<<g.calcrem<<endl<<setw(10)<<g.mech <<" "<<setw(10)<<g.mechgrd<<" "<<setw(15)<<g.mechrem<<endl<<setw(10)<<g.phy<<" "<<setw(10)<<g.phygrd<<" "<<setw(15)<<g.phyrem<<endl<<setw(10)<<g.chem<<" "<<setw(10)<<g.chemgrd<<" "<<setw(15)<<g.chemrem<<endl<<endl;
  654. outputfile.close();
  655. outputfile2.close();
  656. cout<<"\n\n\t\t\tStudent grade has been Added!!!.\n";
  657. cout<<"\n\n\n\npress 'Y' to add another student or 'N' to finish: "; cin>>inchoice;
  658.  
  659. }
  660. }
  661. system("cls");
  662. return;
  663. }
  664.  
  665. void editstudentrecord()
  666. {
  667. char inchoice;
  668. int i;
  669.  
  670. cout<< "\npress 2 again to confirm edit student record: ";cin>>inchoice;
  671. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  672. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='2')){
  673. cout<< "\n\n\t\t\tEDIT STUDENT"<<endl;
  674. string id;
  675. cout<<"\n Enter the student's ID number: ";
  676. cin>>id;
  677.  
  678. studentrecord g;
  679. fstream intofile ("record.txt");
  680. fstream temporalfile ("temp8.txt",ios::app);
  681. string line;
  682.  
  683. while(std::getline(intofile, line))
  684. {
  685. istringstream ss(line);
  686. std::istream_iterator<std::string> begin(ss), end;
  687. //putting all the tokens in the vector
  688. std::vector<std::string> arrayTokens(begin, end);
  689.  
  690. vector<string>::iterator it;
  691. int i=0,flag=0;
  692. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  693. {
  694. if(i==0 && id==*it)
  695. {
  696. flag=1;
  697. }
  698. else
  699. break;
  700. i++;
  701. }
  702. if(flag==1)
  703. {
  704. cout<<"First name: ";cin>>g.firstname;
  705. cout<<"Last name: ";cin>>g.lastname;
  706. cout<<"\n\n\n\t\t\tenter marks for "<<g.firstname<<" "<<g.lastname<<" ("<<id<<")"<<endl;
  707.  
  708. cout<<"\n\n\tEnter African Studies: ";cin>>g.afrstds;
  709. if (g.afrstds >= 80) g.afrgrd='A'; else if (g.afrstds>= 70) g.afrgrd='B'; else if (g.afrstds>= 60) g.afrgrd='C'; else if (g.afrstds>= 50) g.afrgrd='D'; else if (g.afrstds>= 40) g.afrgrd='E'; else g.afrgrd='F';
  710. if (g.afrstds >= 80) g.afrem="EXCELLENT"; else if (g.afrstds>= 70) g.afrem="V.GOOD"; else if (g.afrstds>= 60) g.afrem="GOOD"; else if (g.afrstds>= 50) g.afrem="CREDIT"; else if (g.afrstds>= 40) g.afrem="PASS"; else g.afrem="FAIL";
  711.  
  712. cout<<"\tEnter Calculus mark: ";cin>>g.calc;
  713. if (g.calc >= 80) g.calcgrd='A'; else if (g.calc>= 70) g.calcgrd='B'; else if (g.calc>= 60) g.calcgrd='C'; else if (g.calc>= 50) g.calcgrd='D'; else if (g.calc>= 40) g.calcgrd='E'; else g.calcgrd='F';
  714. if (g.calc >= 80) g.calcrem="EXCELLENT"; else if (g.calc>= 70) g.calcrem="V.GOOD"; else if (g.calc>= 60) g.calcrem="GOOD"; else if (g.calc>= 50) g.calcrem="CREDIT"; else if (g.calc>= 40) g.calcrem="PASS"; else g.calcrem="FAIL";
  715.  
  716. cout<<"\tEnter Mechanics mark for: ";cin>>g.mech ;
  717. if (g.mech >= 80) g.mechgrd='A'; else if (g.mech >= 70) g.mechgrd='B'; else if (g.mech >= 60) g.mechgrd='C'; else if (g.mech >= 50) g.mechgrd='D'; else if (g.mech >= 40) g.mechgrd='E'; else g.mechgrd='F';
  718. if (g.mech >= 80) g.mechrem="EXCELLENT"; else if (g.mech >= 70) g.mechrem="V.GOOD"; else if (g.mech >= 60) g.mechrem="GOOD"; else if (g.mech >= 50) g.mechrem="CREDIT"; else if (g.mech >= 40) g.mechrem="PASS"; else g.mechrem="FAIL";
  719.  
  720. cout<<"\tEnter Physics mark: "; cin>>g.phy;
  721. if (g.phy >= 80) g.phygrd='A'; else if (g.phy>= 70) g.phygrd='B'; else if (g.phy>= 60) g.phygrd='C'; else if (g.phy>= 50) g.phygrd='D'; else if (g.phy>= 40) g.phygrd='E'; else g.phygrd='F';
  722. if (g.phy >= 80) g.phyrem="EXCELLENT"; else if (g.phy>= 70) g.phyrem="V.GOOD"; else if (g.phy>= 60) g.phyrem="GOOD"; else if (g.phy>= 50) g.phyrem="CREDIT"; else if (g.phy>= 40) g.phyrem="PASS"; else g.phyrem="FAIL";
  723.  
  724. cout<<"\tEnter Chemistry mark: "; cin>>g.chem;
  725. if (g.chem >= 80) g.chemgrd='A'; else if (g.chem>= 70) g.chemgrd='B'; else if (g.chem>= 60) g.chemgrd='C'; else if (g.chem>= 50) g.chemgrd='D'; else if (g.chem>= 40) g.chemgrd='E'; else g.chemgrd='F';
  726. if (g.chem >= 80) g.chemrem="EXCELLENT"; else if (g.chem>= 70) g.chemrem="V.GOOD"; else if (g.chem>= 60) g.chemrem="GOOD"; else if (g.chem>= 50) g.chemrem="CREDIT"; else if (g.chem>= 40) g.chemrem="PASS"; else g.chemrem="FAIL";
  727.  
  728.  
  729. temporalfile<<id<<" "<<g.firstname<<" "<<g.lastname<<" "<<g.afrgrd<<" "<<g.calcgrd<<" "<<g.mechgrd<<" "<<g.phygrd<<" "<<g.chemgrd<<endl;
  730.  
  731. cout<<"\nstudent record has been successfully edited.\n";
  732. }
  733. else
  734. {
  735. temporalfile<<line<<endl;
  736. }
  737.  
  738.  
  739. }
  740. intofile.close();
  741. temporalfile.close();
  742. remove("record.txt");
  743. rename("temp8.txt","record.txt");
  744. cout<<"\n\n\n\npress 'Y' to edit another student record or 'N' to finish: "; cin>>inchoice;
  745. }
  746. }
  747. system("cls");
  748. }
  749.  
  750. void deletestudentrecord()
  751. {
  752. char inchoice;
  753. int i;
  754.  
  755. cout<< "\npress 3 again to confirm delete student record: ";cin>>inchoice;
  756. for (i=0; inchoice!='n'&&inchoice!='N'; i++){
  757. if((inchoice=='y')||(inchoice=='Y')||(inchoice=='3')){
  758. cout<< "\n\n\t\t\tDELETE STUDENT"<<endl;
  759. string id;
  760. cout<<"Enter Id number: ";
  761. cin>>id;
  762.  
  763. student stu;
  764. fstream intofile ("record.txt");
  765. fstream temporalfile ("temp9.txt",ios::app);
  766. string line;
  767.  
  768. while(std::getline(intofile, line))
  769. {
  770. istringstream ss(line);
  771. std::istream_iterator<std::string> begin(ss), end;
  772. //putting all the tokens in the vector
  773. std::vector<std::string> arrayTokens(begin, end);
  774.  
  775. vector<string>::iterator it;
  776. int i=0,flag=0;
  777. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  778. {
  779. if(i==0 && id==*it)
  780. {
  781. flag=1;
  782. }
  783. else
  784. break;
  785. i++;
  786. }
  787. if(flag!=1)
  788. {
  789. temporalfile<<line<<endl;
  790. }
  791. else
  792. {
  793. cout<<"\n Student record has been successfully deleted \n";
  794. }
  795.  
  796.  
  797. }
  798. intofile.close();
  799. temporalfile.close();
  800. remove("record.txt");
  801. rename("temp9.txt","record.txt");
  802. cout<<"\n\n\n\npress 'Y' to delete another student record or 'N' to finish: "; cin>>inchoice;
  803. }
  804. }
  805.  
  806. system("cls");
  807. }
  808.  
  809. void studentsrecordlist()
  810. {
  811. ifstream outputfile("record.txt");
  812. string content,i;
  813. cout<<endl<<"\t\t\t\t\t\t\tALL STUDENT RECORDS \t\t\n\n\n";
  814. cout <<setw(15) <<"ID"<<setw(15)<<"FIRST_NAME"<<setw(15)<<"LAST_NAME"<<setw(20)<<"ACADEMIC_WRITING"<<setw(15)<<"MATHEMATICS"<<setw(15)<<"PROGRAMMING"<<setw(15)<<"STATISTICS"<<setw(15)<<"CULTURE"<<endl<<endl;
  815. string line;
  816. while(std::getline(outputfile, line))
  817. {
  818. istringstream ss(line);
  819. std::istream_iterator<std::string> begin(ss), end;
  820.  
  821. //putting all the tokens in the vector
  822. std::vector<std::string> arrayTokens(begin, end);
  823.  
  824. vector<string>::iterator it;
  825.  
  826. for(it = arrayTokens.begin(); it != arrayTokens.end(); it++)
  827. {
  828.  
  829. cout<<setw(15)<<*it;// prints d.
  830.  
  831. }
  832. std::cout << '\n';
  833.  
  834. }
  835.  
  836. cout<< "\n\n\n\nenter any key to continue to main menu: "; cin>>i;
  837. system("cls");
  838. }
  839.  
  840. void display()
  841. {
  842. int notfound=0,y=1,q,i;
  843. string find, id,firstname,lastname,afrstd,calc,mech ,phys,chem;
  844. ifstream f2("record2.txt");
  845. cout<<"Enter ID of student whose record you want to display: ";cin>>find;
  846. cout<<endl;
  847.  
  848. for(q=0; (q<y)||(!f2.eof()); q++)
  849. {
  850. getline(f2,id);
  851. if (id==find)
  852. {
  853. notfound=1;
  854. cout<<setw(12)<<"ID: "<<id<<endl;
  855. getline(f2,firstname);
  856. cout<<setw(12)<<"First name: "<<firstname<<endl;
  857. getline(f2,lastname);
  858. cout<<setw(12)<<"Last name: "<<lastname<<endl<<endl;
  859. cout<<"\t\t\t\tCOURSES\n\n";
  860. cout<<setw(20)<<"COURSE "<<setw(12)<<"MARK "<<setw(12)<<"GRADE "<<setw(17)<<"REMARK "<<endl<<endl;
  861. getline(f2,afrstd);
  862. cout<<setw(20)<<"African Studies: "<<afrstd<<endl;
  863. getline(f2,calc);
  864. cout<<setw(20)<<"Calculus: "<<calc<<endl;
  865. getline(f2,mech );
  866. cout<<setw(20)<<"Mechanics: "<<mech <<endl;
  867. getline(f2,phys);
  868. cout<<setw(20)<<"Physics: "<<phys<<endl;
  869. getline(f2,chem);
  870. cout<<setw(20)<<"Chemistry: "<<chem<<endl;
  871. }
  872. }
  873. if(notfound==0){cout<<"No Record Found"<<endl;}
  874. f2.close();
  875. cout<< "\n\n\n\nenter any key to continue to main menu: "; cin>>i;
  876.  
  877. }
  878.  
  879. int main()
  880. {
  881. int select;
  882. string find;
  883. while(1)
  884. {
  885.  
  886. cout <<endl<<endl;
  887. cout << "\t\t\t\t SCHOOL MANAGEMENT SYSTEM\n\t\t\t\t"<< endl;
  888. cout << "\t\t\t\t__________________________"<<endl<<endl<<endl<<endl;
  889. cout << "\t\t\t\t\t MAIN MENU"<< endl<<endl<<endl;
  890. cout <<"\tPlease select: "<<endl;
  891. cout << "\t\t\t1. STUDENT (ADD/EDIT/DELETE/SHOW ALL STUDENTS)"<< endl;
  892. cout << "\t\t\t2. STAFF (ADD/EDIT/DELETE)"<< endl;
  893. cout << "\t\t\t3. COURSES (ADD/EDIT/DELETE)"<< endl;
  894. cout << "\t\t\t4. STUDENT RECORD "<< endl;
  895. cout << "\t\t\t5. EXIT"<< endl<<endl;
  896. cout << "Input option: ";
  897.  
  898.  
  899. cin>>select;
  900. system("cls");
  901. switch(select)
  902. {
  903. case 1:
  904. int stuselect;
  905. cout <<endl<<endl;
  906. cout << "\t\t\t\t SCHOOL MANAGEMENT SYSTEM"<< endl;
  907. cout << "\t\t\t\t__________________________"<<endl<<endl<<endl<<endl;
  908. cout << "\t\t\t\t\tSTUDENT "<< endl<<endl;
  909. cout << "\t\t\t1. ADD STUDENT"<< endl;
  910. cout << "\t\t\t2. EDIT STUDENT"<< endl;
  911. cout << "\t\t\t3. DELETE STUDENT"<< endl;
  912. cout << "\t\t\t4. SHOW ALL STUDENTS"<< endl;
  913. cout << "\t\t\t5. EXIT"<< endl<<endl;
  914. cout << "what is your choice?: ";
  915. cin>>stuselect;
  916. switch(stuselect)
  917. {
  918. case 1:
  919. addstudent();
  920. break;
  921. case 2:
  922. editstudent();
  923. break;
  924. case 3:
  925. deletestudent();
  926. break;
  927. case 4:
  928. studentslist();
  929. break;
  930. case 5:exit(0);
  931. break;
  932. default:
  933. cout<<"!!!wrong entry. Enter between 1-5!!!";
  934. }
  935.  
  936. break;
  937. case 2:
  938. int staffselect;
  939.  
  940. cout <<endl<<endl;
  941. cout << "\t\t\t\t SCHOOL MANAGEMENT SYSTEM"<< endl;
  942. cout << "\t\t\t\t__________________________"<<endl<<endl<<endl<<endl;
  943. cout << "\t\t\t\t\tSTAFF "<< endl<<endl;
  944. cout << "\t\t\t1. ADD STAFF"<< endl;
  945. cout << "\t\t\t2. EDIT STAFF"<< endl;
  946. cout << "\t\t\t3. DELETE STAFF"<< endl;
  947. cout << "\t\t\t4. SHOW ALL STAFF"<< endl;
  948. cout << "\t\t\t5. EXIT"<< endl<<endl;
  949. cout << "what is your choice?: ";
  950. cin>>staffselect;
  951. switch(staffselect)
  952. {
  953. case 1:
  954. addstaff();
  955. break;
  956. case 2:
  957. editstaff();
  958. break;
  959. case 3:
  960. deletestaff();
  961. break;
  962. case 4:
  963. staffslist();
  964. break;
  965. case 5:exit(0);
  966. break;
  967. default:
  968. cout<<"!!!wrong entry! \npress any key to continue: ";
  969. }
  970.  
  971. break;
  972. case 3:
  973. int couselect;
  974. cout <<endl<<endl;
  975. cout << "\t\t\t\t SCHOOL MANAGEMENT SYSTEM"<< endl;
  976. cout << "\t\t\t\t__________________________"<<endl<<endl<<endl<<endl;
  977. cout << "\t\t\t\t\tCOURSES "<< endl<<endl;
  978. cout << "\t\t\t1. ADD COURSE"<< endl;
  979. cout << "\t\t\t2. EDIT COURSE"<< endl;
  980. cout << "\t\t\t3. DELETE COURSE"<< endl;
  981. cout << "\t\t\t4. SHOW ALL COURSES"<< endl;
  982. cout << "\t\t\t5. EXIT"<< endl<<endl;
  983. cout << "what is your choice?: ";
  984. cin>>couselect;
  985. switch(couselect)
  986. {
  987. case 1:
  988. addcourse();
  989. break;
  990. case 2:
  991. editcourse();
  992. break;
  993. case 3:
  994. deletecourse();
  995. break;
  996. case 4:
  997. courselist();
  998. break;
  999. case 5:exit(0);
  1000. break;
  1001. default:
  1002. cout<<"!!!wrong input. Enter between 1-5!!!";
  1003. }
  1004.  
  1005. break;
  1006.  
  1007. case 4:
  1008. int recordselect;
  1009. cout <<endl<<endl;
  1010. cout << "\t\t\t\t SCHOOL MANAGEMENT SYSTEM"<< endl;
  1011. cout << "\t\t\t\t__________________________"<<endl<<endl<<endl<<endl;
  1012. cout << "\t\t\t\t\tSTUDENT RECORDS "<< endl<<endl;
  1013. cout << "\t\t\t1. ADD STUDENT RECORD"<< endl;
  1014. cout << "\t\t\t2. EDIT STUDENT RECORD"<< endl;
  1015. cout << "\t\t\t3. DELETE STUDENT RECORD"<< endl;
  1016. cout << "\t\t\t4. SHOW ALL STUDENTS RECORDS"<< endl;
  1017. cout << "\t\t\t5. FIND AND DISPLAY DETAILED STUDENT RECORD"<< endl;
  1018. cout << "\t\t\t6. EXIT"<< endl<<endl;
  1019. cout << "Select your option: ";
  1020. cin>>recordselect;
  1021. switch(recordselect)
  1022. {
  1023. case 1:
  1024. addstudentrecord();
  1025. break;
  1026. case 2:
  1027. editstudentrecord();
  1028. break;
  1029. case 3:
  1030. deletestudentrecord();
  1031. break;
  1032. case 4:
  1033. studentsrecordlist();
  1034. break;
  1035. case 5:
  1036. display();
  1037. break;
  1038. case 6:exit(0);
  1039. break;
  1040. default:
  1041. cout<<"!!!wrong input. Enter between 1-5!!!";
  1042. }
  1043.  
  1044. break;
  1045. case 5:exit(0);
  1046. break;
  1047. default:cout<<"wrong input, please try again";
  1048. }
  1049. system("cls");
  1050. }
  1051.  
  1052. return 0;
  1053. }
Add Comment
Please, Sign In to add comment