Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct Time{
  8. int hour;
  9. int minutes;};
  10. struct Classes{
  11. std::string day;
  12. std::string location;
  13. std::string coursenumber;
  14. Time time;};
  15.  
  16. void getfile(ifstream& inData, string& filename);
  17. void printmenu();
  18. char getoption();
  19. void print(ifstream& inData, string& filename);
  20. Classes newentry(ifstream& inData, ofstream& outData, string& filename);
  21. void NewSearch(ifstream& inData);
  22.  
  23. int main(){
  24. ifstream inData;
  25. ofstream outData;
  26. string filename;
  27. char option;
  28.  
  29.  
  30. getfile(inData, filename);
  31. do{
  32. printmenu();
  33. option = getoption();
  34. if(option =='N')
  35. newentry(inData,outData,filename);
  36. else if(option =='P')
  37. print(inData, filename);
  38. else if(option == 'S')
  39. NewSearch(inData);
  40. else if(option == 'Q')
  41. cout << "Thank you for using Your Class Schedule have a great day";
  42. }while(option != 'Q');
  43.  
  44. return 0;
  45. }
  46.  
  47. void getfile(ifstream& inData, string& filename)
  48. {
  49. char choice;
  50.  
  51. cout << "Do you have a new txt schedule file you wish to load from [Y] or [N]" <<endl<< "*For default Class.txt please select [N]*";
  52.  
  53. cin >> choice;
  54. choice = toupper(choice);
  55. if(choice == 'Y'){
  56. do{
  57. cout << "Please enter a .txt filename you wish to load from.";
  58. cin >> filename;
  59. inData.open(filename.c_str());
  60. if (!inData)
  61. cout << "Please enter a valid file name" << endl;
  62. }while(!inData);
  63. }
  64. else
  65. filename = "class.txt";
  66. inData.close();
  67.  
  68. }
  69.  
  70. void printmenu()
  71. {
  72. cout << "Welcome To Your Class Schedule! " << endl;
  73. cout << "To Add New Entry: [N]" << endl;
  74. cout << "To search: [S]" << endl;
  75. cout << "To print schedule: [P]" << endl;
  76. cout << "To Exit: [Q] " << endl;
  77. }
  78.  
  79. Classes newentry(ifstream& inData, ofstream& outData, string& filename)
  80. {
  81. Classes clas;
  82. Time tim;
  83. outData.open(filename.c_str(), ios::app);
  84. cout << "Please enter class Name: ";
  85. cin >> clas.day;
  86. outData << clas.day <<','<< " ";
  87. cout << "Please enter class Number: ";
  88. cin >> clas.coursenumber;
  89. outData << clas.coursenumber <<','<< " ";
  90. cout << "Please enter the day of the class: ";
  91. cin >> clas.day;
  92. outData << clas.day <<','<< " ";
  93. cout << "Please enter the location of the class: ";
  94. cin >> clas.location;
  95. outData << clas.location <<','<< " ";
  96. cout << "Please enter the hour of the class: ";
  97. cin >> tim.hour;
  98. outData << tim.hour << ':';
  99. cout << "Please enter the minutes:";
  100. cin >> tim.minutes;
  101. outData << tim.minutes << endl << endl;
  102. outData.close();
  103. return clas;
  104.  
  105. }
  106. char getoption()
  107. {
  108. char option;
  109.  
  110. cin >> option;
  111. option = toupper(option);
  112. while(option != ('Q')&&(option != ('N'))&&(option != ('S'))&&(option !=('P'))){
  113. cout << "please enter valid option:" << endl;
  114. cin >> option;
  115. option = toupper(option);
  116. }
  117. return option;
  118. }
  119. void print(ifstream& inData, string& filename)
  120. {
  121. string line;
  122. inData.open(filename.c_str());
  123. while(inData){
  124. getline(inData,line);
  125. cout << line << endl;
  126. }
  127. inData.close();
  128. }
  129. void NewSearch(ifstream& inData)
  130. {
  131. string line, compare;
  132.  
  133. cout << "How would you like to search:" << endl;
  134. cout << "class Name:[N]" << endl;
  135. cout << "Class location: [L]" << endl;
  136. cout << "class number:[#]" << endl;
  137. cout << "class time: [T]" << endl;
  138. cout << "Day of Class:[D]" << endl;
  139. cin >> compare;
  140.  
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement