Advertisement
remmydev

Untitled

Feb 17th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <conio.h>
  5. #include <Windows.h>
  6. using namespace std;
  7.  
  8.  
  9. // Structure for students
  10. struct student
  11. {
  12. string fname;
  13. string lname;
  14. string Registration;
  15. string ClassMajor;
  16. string grade;
  17. int Gpa;
  18. string GPA;
  19. string accelarated;
  20. string studentData;
  21. string studentName;
  22. string newGrade;
  23. string Borrowing_Book;
  24. }studentData;
  25.  
  26. //Classes
  27. struct classes
  28. {
  29. string S_C_math;
  30. int I_C_M_Math = 50;
  31. int I_C_math;
  32. }Class;
  33.  
  34. struct teacher
  35. {
  36. string fst_name;
  37. string lst_name;
  38. string qualification;
  39. string exp;
  40. string pay;
  41. string subj;
  42. string lec;
  43. string serves;
  44. string cel_no;
  45.  
  46. }tech[50];
  47.  
  48. void getlastLine(string filename)
  49. {
  50. ifstream fin;
  51. fin.open(filename);
  52. if (fin.is_open()) {
  53. fin.seekg(-1, ios_base::end);
  54.  
  55. bool keepLooping = true;
  56. while (keepLooping) {
  57. char ch;
  58. fin.get(ch);
  59.  
  60. if ((int)fin.tellg() <= 1) {
  61. fin.seekg(0);
  62. keepLooping = false;
  63. }
  64. else if (ch == '\n') {
  65. keepLooping = false;
  66. }
  67. else {
  68. fin.seekg(-2, ios_base::cur);
  69. }
  70. }
  71.  
  72. string lastLine;
  73. getline(fin, lastLine);
  74. Class.S_C_math = lastLine;
  75. Class.I_C_math = stoi(lastLine);
  76.  
  77.  
  78. fin.close();
  79. }
  80.  
  81.  
  82. }
  83.  
  84. // Function to add a new student
  85. void addStudent() {
  86. ofstream f1("Students.txt", ios::app);
  87. char choice = 'Y';
  88. for (int i = 0; choice != 'n' && choice != 'N'; i++) {
  89. cout << "Enter First name: ";
  90. cin >> studentData.fname;
  91. cout << "Enter Last name: ";
  92. cin >> studentData.lname;
  93. cout << "Enter Registration number: ";
  94. cin >> studentData.Registration;
  95. cout << "Enter class: ";
  96. cin >> studentData.ClassMajor;
  97. cout << "Enter Students Gpa: ";
  98. cin >> studentData.GPA;
  99. cout << "Enter True if student is borrowing a book enter False if not: ";
  100. cin >> studentData.Borrowing_Book;
  101. int Gpa = stoi(studentData.GPA);
  102. if (Gpa >= 3.6) {
  103. studentData.accelarated = "True";
  104. }
  105. f1 << studentData.fname << endl << studentData.lname << endl << studentData.Registration << endl << studentData.ClassMajor << endl << studentData.GPA << endl << studentData.accelarated << endl << studentData.Borrowing_Book << endl;
  106.  
  107. cout << "Do you want to continue Adding student? Y to continue N to stop";
  108. cin >> choice;
  109. }
  110. f1.close();
  111. }
  112.  
  113. // Function to display a student
  114. void displayStudent() {
  115. ifstream f2("Students.txt");
  116. if (!f2.is_open()) {
  117. cout << "Error opening file 'Students.txt'.";
  118. return;
  119. }
  120.  
  121. cout << "Enter the first name to be displayed: ";
  122. string find;
  123. cin >> find;
  124. cout << endl;
  125.  
  126. int notFound = 0;
  127. while (getline(f2, studentData.fname)) {
  128. if (studentData.fname == find) {
  129. notFound = 1;
  130. cout << "First Name: " << studentData.fname << endl;
  131. getline(f2, studentData.lname);
  132. cout << "Last Name: " << studentData.lname << endl;
  133. getline(f2, studentData.Registration);
  134. cout << "Registration Number: " << studentData.Registration << endl;
  135. getline(f2, studentData.ClassMajor);
  136. cout << "Class: " << studentData.ClassMajor << endl;
  137. getline(f2, studentData.GPA);
  138. cout << "GPA: " << studentData.GPA << endl;
  139. getline(f2, studentData.accelarated);
  140. cout << "Accelerated: " << studentData.accelarated << endl << endl;
  141. }
  142. }
  143.  
  144. f2.close();
  145.  
  146. if (notFound == 0) {
  147. cout << "No Record Found" << endl;
  148. }
  149.  
  150. cout << "Press any key twice to proceed" << endl << endl;
  151. _getch();
  152. _getch();
  153. }
  154.  
  155. // Function to add a new teacher
  156. void addTeacher() {
  157. ofstream t1("Teachers.txt", ios::app);
  158. char choice = 'Y';
  159. for (int i = 0; choice != 'n' && choice != 'N'; i++) {
  160. cout << "Enter First name: ";
  161. cin >> tech[i].fst_name;
  162. cout << "Enter Last name: ";
  163. cin >> tech[i].lst_name;
  164. cout << "Enter qualification: ";
  165. cin >> tech[i].qualification;
  166. cout << "Enter experience(years): ";
  167. cin >> tech[i].exp;
  168. cout << "Enter number of year in this School: ";
  169. cin >> tech[i].serves;
  170. cout << "Enter Subject whos teach: ";
  171. cin >> tech[i].subj;
  172. cout << "Enter Lecture(per Week): ";
  173. cin >> tech[i].lec;
  174. cout << "Enter pay: ";
  175. cin >> tech[i].pay;
  176. cout << "Enter Phone Number: ";
  177. cin >> tech[i].cel_no;
  178.  
  179. t1 << tech[i].fst_name << endl << tech[i].lst_name << endl << tech[i].qualification << endl << tech[i].exp << endl << tech[i].serves << endl << tech[i].subj << endl << tech[i].lec << endl << tech[i].pay << endl << tech[i].cel_no << endl;
  180.  
  181. cout << "Do you want to enter any more data: ";
  182. cout << "Press Y to Continue and N to Finish: ";
  183. cin >> choice;
  184. }
  185. t1.close();
  186. }
  187.  
  188. // Function to display a teacher
  189. void displayTeacher() {
  190. ifstream t2("Teachers.txt");
  191. cout << "Enter First name to be displayed: ";
  192. string find;
  193. cin >> find;
  194. cout << endl;
  195. int notFound = 0;
  196. int i = 0;
  197. while (!t2.eof()) {
  198. getline(t2, tech[i].fst_name);
  199.  
  200. if (tech[i].fst_name == find) {
  201. notFound = 1;
  202. cout << "First name: " << tech[i].fst_name << endl;
  203. getline(t2, tech[i].lst_name);
  204. cout << "Last name: " << tech[i].lst_name << endl;
  205. getline(t2, tech[i].qualification);
  206. cout << "Qualification: " << tech[i].qualification << endl;
  207. getline(t2, tech[i].exp);
  208. cout << "Experience: " << tech[i].exp << endl;
  209. getline(t2, tech[i].serves);
  210. cout << "number of year in this School: " << tech[i].serves << endl;
  211. getline(t2, tech[i].subj);
  212. cout << "Subject whos teach: " << tech[i].subj << endl;
  213. getline(t2, tech[i].lec);
  214. cout << "Lectures (per Week): " << tech[i].lec << endl;
  215. getline(t2, tech[i].pay);
  216. cout << "pay: " << tech[i].pay << endl;
  217. getline(t2, tech[i].cel_no);
  218. cout << "Phone Number: " << tech[i].cel_no << endl;
  219. }
  220. i++;
  221. }
  222. t2.close();
  223. if (notFound == 0) {
  224. cout << "No Record Found" << endl;
  225. }
  226. cout << "Press any key two times to proceed";
  227. _getch();
  228. _getch();
  229. }
  230.  
  231. // Main function
  232. int main() {
  233. char choice;
  234. while (true) {
  235. cout << "\n\n\t\t\tSCHOOL MANAGEMENT PROGRAM\n\n";
  236. cout << "Enter your choice: " << endl;
  237. cout << "1.Students information" << endl;
  238. cout << "2.Teacher information" << endl;
  239. cout << "3.Check amount of people in a class" << endl;
  240. cout << "4.Add or Look For Students Borrowing books" << endl;
  241. cout << "5.Manage grades" << endl;
  242. cout << "6.Exit program" << endl;
  243. cin >> choice;
  244.  
  245. switch (choice) {
  246. case '1':
  247. addStudent();
  248. break;
  249. case '2':
  250. addTeacher();
  251. break;
  252. case '3':
  253. getlastLine("Class.txt");
  254. cout << "Math Class: " << Class.S_C_math << "/" << Class.I_C_M_Math << endl;
  255. cout << "Press any key two times to proceed" << endl;
  256. _getch();
  257. _getch();
  258. break;
  259. case '4':
  260. displayStudent();
  261. break;
  262. case '5':
  263. // Manage grades
  264. cout << "1. Update Math Grade\n";
  265. cout << "2. View Math Grade\n";
  266. cout << "Enter your choice: ";
  267. int choice;
  268. cin >> choice;
  269. switch (choice) {
  270. case 1:
  271. cout << "Enter student's name: ";
  272. cin >> studentData.studentName;
  273. cout << "Enter new grade: ";
  274. cin >> studentData.newGrade;
  275. updateMathGrade(studentData.studentName, studentData.newGrade);
  276. break;
  277. case 2:
  278. // View Math Grade
  279. break;
  280. default:
  281. cout << "Invalid choice\n";
  282. break;
  283. }
  284. break;
  285. case '6':
  286. exit(0);
  287. break;
  288. default:
  289. cout << "Invalid choice\n";
  290. break;
  291. }
  292.  
  293. }
  294. return 0;
  295. }
  296.  
  297.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement