Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. #include "studentlist.h"
  2.  
  3. using namespace std;
  4.  
  5. //*****INDEX*****
  6. //Student Class
  7. //StudentList Class
  8. //History Class
  9. //Math Class
  10. //English Class
  11.  
  12. //**************************Student Class*********************************//
  13.  
  14. Student::Student(){
  15.  
  16. firstName[0] = '\n';
  17. lastName[0] = '\n';
  18. classType = " ";
  19.  
  20. }
  21.  
  22. Student::Student(const char* fn, const char* ln, const string& c){
  23.  
  24. strcpy(firstName,fn);
  25. strcpy(lastName,ln);
  26. classType = c;
  27.  
  28. }
  29.  
  30. const char* Student::getFN(){return this->firstName;}
  31.  
  32. const char* Student::getLN(){return this->lastName;}
  33.  
  34. const string Student::getCT(){return this->classType;}
  35.  
  36. //**************************StudentList Class*********************************//
  37.  
  38.  
  39. StudentList::StudentList(){
  40.  
  41. size = 0;
  42. tracker = 0;
  43. list = new Student*[size];
  44.  
  45. }
  46.  
  47. StudentList::~StudentList(){
  48.  
  49. for(int i = 0; i <= size; i++)
  50. delete list[i];
  51.  
  52. delete[] list;
  53.  
  54. }
  55.  
  56. bool StudentList::ImportFile(const char* filename){
  57.  
  58. bool check = false;
  59. Student s;
  60. ifstream in;
  61.  
  62. if(check == false){
  63.  
  64. in.open(filename);
  65.  
  66. if(!in){
  67. cout << "File input error\nTry again" << endl;
  68. return false;
  69. }
  70. check = true;
  71. }
  72.  
  73. int sSize;
  74. char last[20];char first[20];
  75. string c;
  76. in >> sSize;
  77.  
  78. for(int i = 0; i < sSize; i++){
  79. in.getline(last,20,',');
  80. in.getline(first,20,'\n');
  81. in >> c;
  82.  
  83. if(c == "Math"){
  84. int tq1,tq2,tq3,tq4,tq5,tt1,tt2,ttf;
  85.  
  86. in >> tq1;in >> tq2;
  87. in >> tq3;in >> tq4;
  88. in >> tq5;in >> tt1;
  89. in >> tt2;in >> ttf;
  90. cout << "made it to math" << endl;
  91. list[tracker] = new Math(first,last,c,tq1,tq2,tq3,tq4,tq5,tt1,tt2,ttf);
  92. Grow();
  93. }
  94. else if(c == "English"){
  95. int ta,tp,tm,tf;
  96.  
  97. in >> ta;in >> tp;
  98. in >> tm;in >> tf;
  99. cout << "made it to english" << endl;
  100. list[tracker] = new English(first,last,c,ta,tp,tm,tf);
  101. Grow();
  102. }
  103. else if(c == "History"){
  104. int tp,tm,tf;
  105.  
  106. in >> tp;in >> tm;in >> tf;
  107. cout << "made it to history" << endl;
  108. list[tracker] = new History(first,last,c,tp,tm,tf);
  109. Grow();
  110. }
  111. else
  112. return false;
  113.  
  114.  
  115. }
  116.  
  117. return true;
  118.  
  119. }
  120.  
  121. bool StudentList::CreateReportFile(const char* filename){
  122. /*
  123. ofstream o;
  124.  
  125. o << "Student Grade Summary\n"
  126. << "---------------------\n\n";
  127.  
  128.  
  129.  
  130. o << "ENGLISH CLASS\n\n";
  131. o << "Student Final Final Letter\n";
  132. o << "Name Exam Avg Grade\n";
  133. o << "----------------------------------------------------------------------\n";
  134. for(int i = 0; i < tracker;i++){
  135. if(list[i]->classType == "English"){
  136. o << list[i]->firstName << " " << list[i]->lastName << setw(20) << left << list[i]->Final << " " << list[i]->getAvg() << " ";
  137.  
  138.  
  139.  
  140. }
  141. }
  142.  
  143. */return true;
  144. }
  145.  
  146. void StudentList::ShowList() const {
  147.  
  148. cout << "Last First Course\n\n";
  149.  
  150. for(int i = 0; i <= 1; i++){
  151. cout << setw(20) << left << list[i]->getLN() << setw(20) << left << list[i]->getFN() << setw(20) << left << list[i]->getCT();
  152. }
  153.  
  154. }
  155.  
  156. void StudentList::Grow(){
  157.  
  158.  
  159. if(tracker == size){
  160. Student* * TL = new Student*[size + 3];
  161.  
  162. cout << "size is = " << size << endl;
  163. cout << "new size is = " << size + 3 << endl;
  164. cout << "tracker is = " << tracker << endl;
  165.  
  166. for(int i = 0; i <= tracker; i++){
  167. TL[i] = list[i];
  168. cout << "no seg fault at: " << i << endl;
  169. }
  170.  
  171. cout << "temp list is filled" << endl;
  172.  
  173. for(int i = 0; i <= size; i++){
  174. delete list[i];
  175. cout << "no seg fault at: " << i << endl;
  176. }
  177.  
  178. delete[] list;
  179. list = new Student*[size + 3];
  180. list = TL;
  181. cout << "list transfer complete" << endl;
  182. size = size + 3;tracker++;
  183. delete[] TL;
  184. cout << "made it thru grow" << endl;
  185. }
  186.  
  187. }
  188.  
  189. //const int StudentList::getSize(){return size;}
  190.  
  191. //const int StudentList::getTracker(){return tracker;}
  192.  
  193. //int StudentList::setTracker(int p){return tracker += p};
  194.  
  195. //**************************History Class*********************************//
  196.  
  197.  
  198. History::History(const char* fn, const char* ln,const string& c,const int& p, const int& m, const int& f) : Student(fn,ln,c){
  199.  
  200. paper = p;
  201. midterm = m;
  202. Final = f;
  203.  
  204. }
  205.  
  206. /*
  207. const int History::getAttend(){return attend;}
  208.  
  209. const int History::getProject(){return project;}
  210.  
  211. const int History::getMidterm(){return midterm;}
  212.  
  213. const int History::getFinal(){return Final;}
  214. */
  215.  
  216. double History::getAvg(){
  217.  
  218. avg = (.25 * paper) + (.35 * midterm) + (.40 * Final);
  219.  
  220. return avg;
  221.  
  222. }
  223.  
  224.  
  225. //**************************Math Class*********************************//
  226.  
  227.  
  228. Math::Math(const char* fn,const char* ln,const string& c,const int& qq1, const int& qq2, const int& qq3, const int& qq4, const int& qq5, const int& t1, const int& t2, const int& tf) : Student(fn,ln,c){
  229.  
  230. q1 = qq1;
  231. q2 = qq2;
  232. q3 = qq3;
  233. q4 = qq4;
  234. q5 = qq5;
  235. test1 = t1;
  236. test2 = t2;
  237. testF = tf;
  238.  
  239. }
  240.  
  241. double Math::getAvg(){
  242.  
  243. avg = (.15 * (q1+q2+q3+q4+q5)) + (.25 * test1) + (.25 * test2) + (.35 * testF);
  244.  
  245. return avg;
  246.  
  247. }
  248.  
  249. //**************************English Class*********************************//
  250.  
  251.  
  252. English::English(const char* fn,const char* ln,const string& c,const int& a,const int& p, const int& m, const int& f) : Student(fn,ln,c){
  253.  
  254. attend = a;
  255. project = p;
  256. midterm = m;
  257. Final = f;
  258.  
  259. }
  260.  
  261. double English::getAvg(){
  262.  
  263. avg = (.10 * attend) + (.30 * project) + (.30 * midterm) + (.30 * Final);
  264.  
  265. return avg;
  266.  
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement