fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <iomanip>
  6. #include <conio.h>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. void gotoxy(int x, int y)
  12. {
  13. COORD coord;
  14. coord.X = x;
  15. coord.Y = y;
  16. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  17. }
  18.  
  19. int createClassFunction()
  20. {
  21.  
  22. ofstream create_classList_file;
  23.  
  24. system("cls");
  25.  
  26. int yCoord;
  27. int itr;
  28.  
  29. string keepGoing = "y";
  30. string className;
  31.  
  32. int studentNum = 0;
  33. string firstName = "0";
  34. string lastName = "0";
  35.  
  36. int assignmentMark = 0;
  37. int midtermMark = 0;
  38. int finalTestMark = 0;
  39. int overallAverageMark = 0;
  40. string letterGradeMark = "0";
  41.  
  42.  
  43.  
  44.  
  45. struct classInfo
  46. {
  47. int studentNum;
  48. string firstName;
  49. string lastName;
  50. int assignmentMark;
  51. int midtermMark;
  52. int finalTestMark;
  53. float overallAverageMark;
  54. string letterGradeMark;
  55. };
  56.  
  57. classInfo student[30] =
  58. {
  59. {
  60. studentNum,
  61. firstName,
  62. lastName,
  63. assignmentMark,
  64. midtermMark,
  65. finalTestMark,
  66. overallAverageMark,
  67. letterGradeMark
  68. }
  69. };
  70.  
  71.  
  72.  
  73. gotoxy(5,4);
  74. cout << "Class name: ";
  75. cin >> className;
  76.  
  77. system("cls");
  78.  
  79. create_classList_file.open(className + ".txt", ios::out | ios::binary );
  80.  
  81. itr = 0;
  82. while(itr < 30)
  83. {
  84. system("cls");
  85.  
  86. yCoord = 6;
  87.  
  88. gotoxy(5,yCoord);
  89. cout << "Student Num: ";
  90. cin >> student[itr].studentNum;
  91. yCoord += 2;
  92.  
  93. gotoxy(5, yCoord);
  94. cout << "First name: ";
  95. cin >> student[itr].firstName;
  96. yCoord += 2;
  97.  
  98. gotoxy(5, yCoord);
  99. cout << "Last name ";
  100. cin >> student[itr].lastName;
  101. yCoord += 2;
  102.  
  103. student[itr].assignmentMark = 0;
  104. student[itr].midtermMark = 0;
  105. student[itr].finalTestMark = 0;
  106. student[itr].overallAverageMark = 0;
  107. student[itr].letterGradeMark = "0";
  108.  
  109. create_classList_file.write((char *) &student[itr], sizeof(classInfo));
  110.  
  111. gotoxy(5,yCoord);
  112. cout << "Press any key to enter another(N to quit): ";
  113. cin >> keepGoing;
  114.  
  115. if(keepGoing == "n" || keepGoing == "N")
  116. break;
  117. else
  118. itr++;
  119.  
  120. } // end of while loop
  121.  
  122. create_classList_file.close();
  123.  
  124. return 0;
  125. }
  126.  
  127. int viewClassFunction()
  128. {
  129. int x;
  130. int itr;
  131. int numOfStudents;
  132.  
  133. int yCoord;
  134.  
  135. system("cls");
  136.  
  137. ifstream view_classList_file;
  138.  
  139. struct classInfo
  140. {
  141. int studentNum;
  142. string firstName;
  143. string lastName;
  144. int assignmentMark;
  145. int midtermMark;
  146. int finalTestMark;
  147. float overallAverageMark;
  148. string letterGradeMark;
  149. };
  150.  
  151. string className;
  152.  
  153. gotoxy(5,4);
  154. cout << "Class file to open: ";
  155. cin >> className;
  156.  
  157. view_classList_file.open(className + ".txt", ios::in | ios::binary);
  158.  
  159. /*
  160.  
  161. view_classList_file.seekg(0l, ios::end);
  162. int size = view_classList_file.tellg();
  163. cout << size;
  164. system("pause");
  165.  
  166. */
  167.  
  168. classInfo student[30];
  169.  
  170.  
  171. yCoord = 6;
  172. x = 0;
  173. while(!view_classList_file.eof())
  174. {
  175. if(view_classList_file.eof())
  176. break;
  177. view_classList_file.read((char *) &student[x], sizeof(classInfo));
  178.  
  179. gotoxy(5,yCoord);
  180. cout << "Student Num: " << student[x].studentNum;
  181. yCoord += 2;
  182.  
  183.  
  184. gotoxy(5, yCoord);
  185. cout << "First name: " << student[x].firstName;
  186. yCoord += 2;
  187.  
  188.  
  189. gotoxy(5, yCoord);
  190. cout << "Last name " << student[x].lastName;
  191. yCoord += 2;
  192.  
  193. x++;
  194. }
  195.  
  196.  
  197. /*
  198. int i = 0;
  199. while(student[i].studentNum > 0)
  200. {
  201. gotoxy(5,yCoord);
  202. cout << "Student Num: " << student[i].studentNum;
  203. yCoord += 2;
  204.  
  205.  
  206. gotoxy(5, yCoord);
  207. cout << "First name: " << student[i].firstName;
  208. yCoord += 2;
  209.  
  210.  
  211. gotoxy(5, yCoord);
  212. cout << "Last name " << student[i].lastName;
  213. yCoord += 2;
  214.  
  215. i++;
  216. }
  217. */
  218.  
  219. /*
  220. if(student[i].gradestuff == 0)
  221. {
  222. cout << "whatever grade: n/a";
  223. }
  224.  
  225. else
  226. */
  227.  
  228.  
  229.  
  230. system("pause");
  231.  
  232. return 0;
  233.  
  234. }
  235.  
  236. int main()
  237. {
  238. int menuChoice;
  239. menuChoice = 0;
  240.  
  241. while(menuChoice != 7 && menuChoice< 8)
  242. {
  243.  
  244. system("cls");
  245.  
  246. gotoxy(5,2);
  247. cout << "Please select an option";
  248. gotoxy(5,4);
  249. cout << "1. Create Class";
  250. gotoxy(5,5);
  251. cout << "2. Add student";
  252. gotoxy(5,6);
  253. cout << "3. Update class data";
  254. gotoxy(5,7);
  255. cout << "4. Update student data";
  256. gotoxy(5,8);
  257. cout << "5. View class data";
  258. gotoxy(5,9);
  259. cout << "6. View student data";
  260. gotoxy(5,11);
  261. cout << "7. Exit";
  262. gotoxy(6,13);
  263. cout << "Option: ";
  264. cin >> menuChoice;
  265.  
  266.  
  267. if(menuChoice == 1)
  268. createClassFunction();
  269. /*
  270. else if(menuChoice == 2)
  271. addStudent();
  272. else if(menuChoice == 3)
  273. updateClassData();
  274. else if(menuChoice == 4)
  275. updateStudentData();
  276. */
  277. else if(menuChoice == 5)
  278. viewClassFunction();
  279. /*
  280. else if(menuChoice == 6)
  281. viewStudentData();
  282. */
  283. else if(menuChoice == 7)
  284. break;
  285. }
  286.  
  287. return 0;
  288.  
  289. }
  290.  
  291. /*
  292.  
  293. Use file size to determine how many students, sizeof(structureName), logicalFileName.tellg() is used to get size of a file
  294. 30 student limit
  295. Only update grades
  296.  
  297. seekg
  298. tellg
  299.  
  300. filename.seekg(0l, ios::end)
  301.  
  302. */
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty