Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. /***********************************************************************---------------------------------------------------------------------------*
  2. * PROGRAM: assignment2.cpp *
  3. * This is a menu driven calendar schedule program application
  4. * that alows the user to create up to 31 days of storage for an event.
  5. * Users can create a new event by adding a new day, time, and event. ******CHANGE ALL OF THISSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS****
  6. * The user has the option to see all events scheduled.
  7. * The user has the option to see all the events scheduled in a given range.
  8. *
  9. * AUTHOR: Jonathan Sell
  10. * Date: 01/25/2012
  11. ***********************************************************************/
  12. #include <iostream>
  13. #include <string.h>
  14.  
  15. using namespace std;
  16. /***********************************************************************
  17. * NAME: calandarSchedule
  18. * INPUT: None.
  19. * OUTPUT: None.
  20. * FUNCTION: Creates the struct of type calendarSchedule
  21. ***********************************************************************/
  22. class Calendar {
  23.  
  24. public:
  25.  
  26. int dayNumberChoice;
  27. int time; //time is stored in mins from midnight
  28. char eventNameChoice[6];
  29. };
  30.  
  31.  
  32.  
  33. class linkedListClass {
  34.  
  35. public:
  36.  
  37. linkedListClass(int newvalue) {
  38. myCalendar = newvalue;
  39. next = NULL;
  40. }
  41.  
  42. linkedListClass(int newvalue, linkedListClass *newNext) {
  43. myCalendar = newvalue;
  44. next = newNext;
  45. }
  46.  
  47. int getdvalue() {
  48. return (myCalendar);
  49. }
  50.  
  51. void addAfter(int newvalue) {
  52. linkedListClass *newnode = new linkedListClass(newvalue);
  53.  
  54. newnode -> next = next;
  55. next = newnode;
  56. }
  57.  
  58. void printlist() {
  59. cout << "\tcurrent node is " << myCalendar << endl;
  60. if (next != NULL)
  61. next->printlist();
  62. }
  63.  
  64. private:
  65. ;
  66. Calendar myCalendar;
  67. linkedListClass *next;
  68.  
  69. };
  70.  
  71. class realList {
  72. public:
  73. realList() {
  74. first = NULL;
  75. }
  76.  
  77. realList(int nodevalue) {
  78. first = new linkedListClass(nodevalue);
  79. }
  80.  
  81. void addbehind(int newvalue) {
  82.  
  83. if (first == NULL)
  84. first = new linkedListClass(newvalue);
  85. else
  86. first->addAfter(newvalue);
  87. }
  88.  
  89. void addinfront(int newvalue) {
  90. linkedListClass *newnode;
  91.  
  92. if (first == NULL)
  93. first = new linkedListClass(newvalue);
  94. else {
  95. newnode = new linkedListClass(newvalue, first);
  96. first = newnode;
  97. }
  98. }
  99.  
  100. int getdvalue() {
  101. if (first == NULL)
  102. return -1;
  103. else
  104. return(first->getdvalue());
  105. }
  106.  
  107. void printlist() {
  108. if (first == NULL)
  109. cout << "The List is currently empty.\n";
  110. else {
  111. cout << "\nHere is the current list: \n";
  112. first->printlist();
  113. }
  114. }
  115.  
  116. private:
  117.  
  118. linkedListClass *first;
  119. };
  120.  
  121.  
  122.  
  123. void processMenuChoiceTwo();
  124. void processMenuChoiceThree();
  125. void printTime(int time);
  126. int dayNumber, menuChoice, startDay, endDay, eventSched = 0;
  127. /***********************************************************************
  128. * NAME: main
  129. * INPUT: User enters a menu choice and/or additional entries depending on menu choice.
  130. Including a day number, time, and event.
  131. * OUTPUT: All scheduled events: Day, Time, Event.
  132. * FUNCTION: Gives the user a menu to choose which operation to execute.
  133. User can store 1 event per day, with 31 days of storage.
  134. Event is stored in the following format: Day, Time 00:00, and Event Name
  135. ***********************************************************************/
  136. int main()
  137. {
  138.  
  139. cout << "Welcome to my calendar program!\n";
  140.  
  141. do
  142. {
  143. cout << "Please select an option:" << endl;
  144. cout << " 1. Add a new event" << endl;
  145. cout << " 2. Display all scheduled events" << endl;
  146. cout << " 3. Display events within range" << endl;
  147. cout << " 4. Quit program" << endl;
  148. cin >> menuChoice;
  149.  
  150.  
  151. if(menuChoice == 1)
  152. { cout <<"Please enter the day number:" << endl;
  153. cin >> dayNumber;
  154.  
  155. if(dayNumber >=1 && dayNumber <=31)
  156. {
  157. char input[4];
  158. int mins, hours;
  159.  
  160. dayNumberChoice = dayNumber;
  161. cout << "Please enter the time in 24 hour notation:" << endl;
  162. cin >> input;
  163.  
  164. sscanf (input,"%i:%i",&hours,&mins); // parses the hours and minutes
  165.  
  166. if(hours < 01 || hours > 24 || mins < 0 || mins > 59)
  167. {
  168. cout << "Please enter a valid time in 24 hour format 00:00." << endl;
  169. cout << "Hour values: 00-24, Minute values: 00-59" << endl;
  170.  
  171. }
  172.  
  173.  
  174. else
  175. {Test[dayNumber].time = (hours*60)+mins; // converts 24 hour time format to minutes from midnight
  176. }
  177.  
  178. cout << "Please enter the name of the event:" << endl;
  179. cin >> Test[dayNumber].eventNameChoice;
  180.  
  181. eventSched++;
  182. }
  183. else
  184. {
  185. cout << "Please enter a valid day between 1-31" << endl;
  186. }
  187.  
  188. }
  189. else if(menuChoice == 2)
  190. { processMenuChoiceTwo();
  191. }
  192. else if(menuChoice == 3)
  193. { processMenuChoiceThree();
  194. }
  195. else if(menuChoice == 4)
  196. { cout << "Good Bye!" << endl;
  197. }
  198. else
  199. { cout << "You chose an invalid entry." << endl;
  200. }
  201.  
  202. }while(menuChoice!=4);
  203. }
  204.  
  205.  
  206.  
  207. void processMenuChoiceTwo()
  208. {
  209. if( eventSched == 0)
  210. {cout << "There are no scheduled events." << endl;
  211. }
  212. else
  213. {
  214. for(int i = 1; i <= 31; i++)
  215. {
  216. if(Test[i].time)
  217. {cout << "Day " << Test[i].dayNumberChoice << " Time: " << Test[i].time << " Event: " << Test[i].eventNameChoice << endl;
  218. }
  219.  
  220. }
  221.  
  222. }
  223. }
  224.  
  225. void processMenuChoiceThree()
  226. {
  227. cout << "Please enter the start day:" << endl;
  228. cin >> startDay;
  229.  
  230. if(startDay <=0 || startDay > 31)
  231. { cout << "Please enter a valid day 1-31." << endl;
  232. }
  233. else
  234. {cout << "Please enter the end day:" << endl;
  235. cin >> endDay;
  236. }
  237. if(endDay <= 0 || endDay > 31)
  238. {cout << "Please enter a valid day 1-31" << endl;
  239. }
  240. else
  241. {
  242. for(int i = startDay; i <= endDay; i++)
  243. {
  244. if(Test[i].time)
  245. {cout << "Day " << i << " Time: ";
  246. printTime(Test[i].time);
  247. cout << " Event: " << Test[i].eventNameChoice << endl;
  248. }
  249. }
  250. }
  251. }
  252.  
  253. /***********************************************************************
  254. * NAME: printTime
  255. * INPUT: Minutes from Midnight variable time.
  256. * OUTPUT: The time in 24 hour notation.
  257. * FUNCTION: This method converts the variable time, which is stored as minutes from midnight, back to it's original 24 hour format 00:00
  258. ***********************************************************************/
  259.  
  260. void printTime(int time)
  261. {
  262. char out[6];
  263. int mins;
  264. int hours;
  265.  
  266. mins = time%60;
  267. hours = time/60;
  268. sprintf (out, "%02d:%02d", hours, mins);
  269. cout << out;
  270. }
Add Comment
Please, Sign In to add comment