Advertisement
Guest User

main.cpp

a guest
Oct 22nd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "Training.h"
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. Training *ptr; // training class object
  10. char object_training_id[6]; // these object is act like tempopray variable only
  11. char object_description[50]; // the result will then set into Training class object
  12. char object_date[50];
  13. char object_time[20];
  14. float object_charges;
  15. int object_registered;
  16. char object_Ic[15];
  17. char object_firstname[20];
  18. char object_lastname[20];
  19.  
  20.  
  21. ifstream inputfile; // variable for inputfile
  22. inputfile.open("data.txt", ios::in); //open file
  23.  
  24. if(!inputfile)
  25. {
  26. cout << "Unavailable file" << endl;
  27. return 0;
  28. }
  29. int number_Training;
  30. inputfile >> number_Training;
  31. cout << number_Training << endl;
  32. ptr = new Training[number_Training]; // dynamic
  33.  
  34.  
  35. if(inputfile)
  36. {
  37. for(int i = 0; i < number_Training;i++)
  38. {
  39.  
  40. inputfile >> object_training_id;
  41. ptr[i].setTrainingId(object_training_id);
  42. cout << object_training_id << endl;
  43.  
  44. inputfile.ignore();
  45. inputfile.getline(object_description,50);
  46. ptr[i].setTrainingDescp(object_description);
  47. cout << object_description << endl;
  48.  
  49. inputfile.getline(object_date,50);
  50. ptr[i].setTrainingDate(object_date);
  51. cout << object_date << endl;
  52.  
  53. inputfile.getline(object_time,20);
  54. ptr[i].setTrainingTime(object_time);
  55. cout << object_time << endl;
  56.  
  57. inputfile >> object_charges;
  58. ptr[i].setTrainingCharges(object_charges);
  59. cout << object_charges << endl;
  60.  
  61. inputfile >> object_registered;
  62. ptr[i].setTrainingReg(object_registered);
  63. cout << object_registered << endl;
  64.  
  65. for(int j=0; j < object_registered; j++)
  66. {
  67. inputfile.ignore();
  68. inputfile.getline(object_Ic,15);
  69.  
  70. cout << object_Ic << endl;
  71. inputfile >> object_firstname;
  72. cout << object_firstname << endl;
  73. inputfile >> object_lastname;
  74. cout << object_lastname << endl;
  75. ptr[i].setParticipant(j,object_Ic,object_firstname,object_lastname);
  76. }//end for inner for loop
  77. }
  78.  
  79. }//if for infile
  80.  
  81. inputfile.close();
  82. char choice;
  83. do{
  84. cout << "Welcome yoo" << endl;
  85. cout << "1. Register a new participant" << endl;
  86. cout << "2. Remove a participant from a training session" << endl;
  87. cout << "3. Modify a Training details" << endl;
  88. cout << "4. Display a Training details" << endl;
  89. cout << "5. Quit" << endl;
  90. cout << "Please Enter a Number : " ;
  91. cin >> choice;
  92. cout << endl; // for end line
  93.  
  94. if(choice == '1')
  95. {
  96. cout << "Entered 1" << endl;
  97. cout << "There are now " << number_Training << " course" << endl;
  98. cout << "Number" << "\t" << "Course Description" << endl;
  99. for(int i =0; i < number_Training; i++)
  100. {
  101. cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
  102.  
  103. }
  104.  
  105. int number;
  106. cout << "Please enter the number : ";
  107. cin >> number;
  108.  
  109. if(validate_Session(number,number_Training))
  110. {
  111. if(ptr[number-1].getTrainingReg() >= 30)
  112. {
  113. cout << "No new registration should be allowed!" << endl;
  114. cout << "It's Full."<< endl;
  115. }//end for if
  116.  
  117. else
  118. {
  119. registration(object_Ic,object_firstname, object_lastname);
  120.  
  121. if(validate_Ic(object_Ic))
  122. {
  123. ptr[number-1].setParticipant(ptr[number-1].getTrainingReg(), object_Ic, object_firstname,object_lastname);
  124. ptr[number-1].setTrainingReg(ptr[number-1].getTrainingReg() + 1);
  125. cout << "Successfully Register" << endl;
  126. cout << endl;
  127. }
  128. else
  129. {
  130. cout << "Unable to register. Please try again " << endl;
  131. cout << endl;
  132. }
  133. }// end for else
  134. }//end for if validate
  135. else
  136. {
  137. cout << "The number invalid "<<endl;
  138. }
  139. }//end for choice 1
  140. else if(choice == '2')
  141. {
  142. cout << "Entered 2" << endl;
  143. cout << "There are now " << number_Training << " course" << endl;
  144. cout << "Number" << "\t" << "Course Description" << endl;
  145. for(int i =0; i < number_Training; i++)
  146. {
  147. cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
  148.  
  149. }
  150.  
  151. int number;
  152. cout << "Please enter the number : ";
  153. cin >> number;
  154.  
  155. if(validate_Session(number, number_Training))
  156. {
  157. cout << "No. " << "\t" << "Participant ID" << endl;
  158. for(int i =0; i < ptr[number-1].getTrainingReg(); i++)
  159. {
  160. cout << (i+1) << "\t" << ptr[number-1].getParticipantIc(i) << endl;
  161. }
  162.  
  163. cout << "Enter Participant ID : ";
  164. cin.ignore();
  165. cin.getline(object_Ic,15);
  166.  
  167. ptr[number-1].remove_Participant(object_Ic);
  168.  
  169. }
  170. }//end for choice 2
  171.  
  172. else if(choice=='3')
  173. {
  174. cout << "Entered 3" << endl;
  175.  
  176. cout << "There are now " << number_Training << " course" << endl;
  177. cout << "Number" << "\t" << "Course Description" << endl;
  178. for(int i =0; i < number_Training; i++)
  179. {
  180. cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
  181.  
  182. }
  183.  
  184. int number;
  185. cout << "Please enter the number : ";
  186. cin >> number;
  187. cout << endl;
  188.  
  189. bool validated = true;
  190.  
  191. if(validate_Session(number,number_Training))
  192. {
  193. cout << "+# " << ptr[number-1].getTrainingId() << endl;
  194. cout << "+# " << ptr[number-1].getTrainingDescp() << endl;
  195. cout << "+# " << ptr[number-1].getTrainingDate() << endl;
  196. cout << "+# " << ptr[number-1].getTrainingTime() << endl;
  197. cout << "+# " << ptr[number-1].getTrainingCharges() << endl;
  198. cout << endl;
  199. cout << "Enter new Info below" << endl;
  200. cin.ignore();
  201.  
  202. cout << "Training ID : " ;
  203. cin.getline(object_training_id, 6);
  204.  
  205. cout << "Training Description : ";
  206. cin.getline(object_description, 50);
  207.  
  208. cout << "Training Date : ";
  209. cin.getline(object_date, 50);
  210.  
  211. cout << "Training Time : ";
  212. cin.getline(object_time, 20);
  213.  
  214. cout << "Training Charges : ";
  215. cin >> object_charges;
  216.  
  217. if(validate_Id(object_training_id))
  218. {
  219. ptr[number-1].setTrainingId(object_training_id);
  220. ptr[number-1].setTrainingDescp(object_description);
  221. ptr[number-1].setTrainingDate(object_date);
  222. ptr[number-1].setTrainingTime(object_time);
  223. ptr[number-1].setTrainingCharges(object_charges);
  224.  
  225. cout << "Successfully Modify!!!" << endl;
  226. }
  227. else
  228. {
  229. cout << "Unable to modify data. Please try again" << endl;
  230. }
  231.  
  232.  
  233. }
  234. else
  235. {
  236. cout << "Invalid Session" << endl;
  237. }
  238. }//end for choice 3
  239.  
  240. else if(choice == '4')
  241. {
  242. for(int i = 0; i < number_Training; i++)
  243. {
  244. ptr[i].display();
  245. }
  246.  
  247. }//end for choice 4
  248.  
  249. cout << endl;
  250. }while(choice != '5');
  251.  
  252.  
  253. return 0;
  254. }//end for main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement