Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <string>
  5. #include <iomanip>
  6. #include <cstdlib>
  7. #include <vector>
  8.  
  9. // Don't comment out code. It's distracting.
  10.  
  11. //#include "student.h"
  12. #include "studentList.h"
  13.  
  14. // Don't use the standard namespace. It's bad style.
  15. using namespace std;
  16.  
  17. const int fileNameSize=20;
  18. ofstream outFile;
  19. //char inputFileName [fileNameSize+1];
  20. //char outputFilename [fileNameSize+1];
  21. studentList stList;
  22. string id, name;
  23.  
  24. // There is a tab of excess whitespace here
  25.  
  26. //
  27.  
  28. // This and others should be a static function or in an anonymous
  29. // namespace Inconsistent and bad naming style. The standard C++
  30. // naming convention is foo_bar_gar.
  31. void showmenu()
  32. {
  33. cout << "Please type in one of the following opotions: \n";
  34. cout << "L or l to load the student list \n";
  35. cout << "D or d to display the student data \n";
  36. cout << "P or p to process grades\n";
  37. cout << "C or c to change a student \n";
  38. cout << "A or a to add a student. \n";
  39. cout << "S or s to search for a particular student's information \n";
  40. cout << "R or r to print the total grades and letter grade \n";
  41. cout << "M or m to display this menu \n";
  42. cout << "E or e to save and exit \n";
  43. }
  44.  
  45. void loadStudents()
  46. {
  47. // I'd use a char for this.
  48. int dummy = 1;
  49. //choice='1';
  50. //char temp=choice;
  51.  
  52. // The bounds here should be constants. C++ is an ugly sack of
  53. // shit so the best way to do this is:
  54. // contexpr size_t bound = 10;
  55. // or
  56. // enum { BOUND = 10 };
  57.  
  58. int hpScores[10];
  59. int tScores[4];
  60. ifstream inFile;
  61. //cout << "infile flag";
  62. student st;
  63. // Use a string class instead of a bounded buffer.
  64. char filename[30];
  65. cout << "What is the file we are reading from? \n";
  66. cin >> filename;
  67. cout << "Loading students... \n";
  68. cout << filename << endl;
  69. // Windows is an ugly sack of shit and so this doesn't work
  70. // for Unicode filepaths.
  71. inFile.open(filename);
  72. cout << "open check" << endl;
  73. if (!inFile)
  74. {
  75. cout << "Error, could not load/find file.";
  76. // You don't need this. The destructor handles
  77. // this. The only point of explicitly handling this
  78. // would be checking for errors but there's no point
  79. // because this is already an error situation.
  80. inFile.close();
  81. inFile.clear();
  82. return;// choice;
  83. }
  84. cout << name << endl;
  85. st.setName(name);
  86. while (!inFile.eof())
  87. {
  88. cout << "open flag";
  89. cout << " " << name;
  90. inFile >> id; st.setID(id);
  91. cout << " " << id;
  92. cin >> dummy;
  93. for(int i=0;i<10;i++)
  94. {
  95. inFile >> hpScores[i];
  96. cout << " " <<hpScores[i] << endl;
  97. }
  98. st.setHPScores(hpScores);
  99. for(int i=0;i<4;i++)
  100. {
  101. inFile >> tScores[i];
  102. cout << " " <<tScores[i] << endl;
  103. }
  104. st.setTestScores(tScores);
  105. stList.addStudent(st);
  106. inFile >> name;
  107. st.setName(name);
  108. }
  109. //cout << "flag6";
  110. //return choice;
  111. string wastedata;
  112. getline(cin, wastedata);
  113. inFile.clear();
  114. inFile.close();
  115.  
  116. }
  117.  
  118. void displayStudentProfile()
  119. {
  120. cout << "Displaying data...\n";
  121. }
  122.  
  123. void processGrades()
  124. {
  125. cout << "Processing grades... \n";
  126. }
  127.  
  128. void changeGrades()
  129. {
  130. cout << "Changing student grade(s)...\n";
  131. }
  132.  
  133. void addStudent()
  134. {
  135. cout << "Adding student... \n";
  136. }
  137.  
  138. void searchStudent()
  139. {
  140. cout << "Searhing student...\n";
  141. }
  142.  
  143. void saveInfo()
  144. {
  145. cout << "Saving data...";
  146. }
  147.  
  148. void printGrades()
  149. {
  150. cout << "Printing total grades and letter grade...";
  151. }
  152.  
  153. int main()
  154. {
  155. int ilchk=0;
  156. char choice='m';
  157. string wastedata;
  158. showmenu();
  159. cout << "Please indicate your choice of operation (m for menu): ";
  160. cin >> choice;
  161. while((choice!='e')&&(choice!='E') and ilchk<5)
  162. {
  163. switch(choice)
  164. {
  165. case 'l':
  166. case 'L': loadStudents(); cin.ignore(400, '\n'); cin.clear(); break;
  167. case 'd':
  168. case 'D': displayStudentProfile(); cin.ignore(400, '\n'); cin.clear(); break;
  169. case 'p':
  170. case 'P': processGrades(); cin.ignore(400, '\n'); cin.clear(); break;
  171. case 'c':
  172. case 'C': changeGrades(); cin.ignore(400, '\n'); cin.clear(); break;
  173. case 'a':
  174. case 'A': addStudent(); cin.ignore(400, '\n'); cin.clear(); break;
  175. case 's':
  176. case 'S': searchStudent(); cin.ignore(400, '\n'); cin.clear(); break;
  177. case 'r':
  178. case 'R': printGrades(); cin.ignore(400, '\n'); cin.clear(); break;
  179. case 'm':
  180. case 'M': showmenu(); cin.ignore(400, '\n'); cin.clear(); break;
  181. case 'e':
  182. case 'E': cin.ignore(400, '\n'); cin.clear(); break;
  183. default : cout << "Invalid command." << endl;
  184. }
  185. cout << "Please indicate your choice of operation (m for menu): ";
  186. cin >> choice;
  187. ilchk++;
  188. }
  189. saveInfo();
  190. cout << "Thank you, have a good one!\n";
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement