Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************************---------------------------------------------------------------------------*
- * PROGRAM: assignment2.cpp *
- * This is a menu driven calendar schedule program application
- * that alows the user to create up to 31 days of storage for an event.
- * Users can create a new event by adding a new day, time, and event. ******CHANGE ALL OF THISSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS****
- * The user has the option to see all events scheduled.
- * The user has the option to see all the events scheduled in a given range.
- *
- * AUTHOR: Jonathan Sell
- * Date: 01/25/2012
- ***********************************************************************/
- #include <iostream>
- #include <string.h>
- using namespace std;
- /***********************************************************************
- * NAME: calandarSchedule
- * INPUT: None.
- * OUTPUT: None.
- * FUNCTION: Creates the struct of type calendarSchedule
- ***********************************************************************/
- class Calendar {
- public:
- int dayNumberChoice;
- int time; //time is stored in mins from midnight
- char eventNameChoice[6];
- };
- class linkedListClass {
- public:
- linkedListClass(int newvalue) {
- myCalendar = newvalue;
- next = NULL;
- }
- linkedListClass(int newvalue, linkedListClass *newNext) {
- myCalendar = newvalue;
- next = newNext;
- }
- int getdvalue() {
- return (myCalendar);
- }
- void addAfter(int newvalue) {
- linkedListClass *newnode = new linkedListClass(newvalue);
- newnode -> next = next;
- next = newnode;
- }
- void printlist() {
- cout << "\tcurrent node is " << myCalendar << endl;
- if (next != NULL)
- next->printlist();
- }
- private:
- ;
- Calendar myCalendar;
- linkedListClass *next;
- };
- class realList {
- public:
- realList() {
- first = NULL;
- }
- realList(int nodevalue) {
- first = new linkedListClass(nodevalue);
- }
- void addbehind(int newvalue) {
- if (first == NULL)
- first = new linkedListClass(newvalue);
- else
- first->addAfter(newvalue);
- }
- void addinfront(int newvalue) {
- linkedListClass *newnode;
- if (first == NULL)
- first = new linkedListClass(newvalue);
- else {
- newnode = new linkedListClass(newvalue, first);
- first = newnode;
- }
- }
- int getdvalue() {
- if (first == NULL)
- return -1;
- else
- return(first->getdvalue());
- }
- void printlist() {
- if (first == NULL)
- cout << "The List is currently empty.\n";
- else {
- cout << "\nHere is the current list: \n";
- first->printlist();
- }
- }
- private:
- linkedListClass *first;
- };
- void processMenuChoiceTwo();
- void processMenuChoiceThree();
- void printTime(int time);
- int dayNumber, menuChoice, startDay, endDay, eventSched = 0;
- /***********************************************************************
- * NAME: main
- * INPUT: User enters a menu choice and/or additional entries depending on menu choice.
- Including a day number, time, and event.
- * OUTPUT: All scheduled events: Day, Time, Event.
- * FUNCTION: Gives the user a menu to choose which operation to execute.
- User can store 1 event per day, with 31 days of storage.
- Event is stored in the following format: Day, Time 00:00, and Event Name
- ***********************************************************************/
- int main()
- {
- cout << "Welcome to my calendar program!\n";
- do
- {
- cout << "Please select an option:" << endl;
- cout << " 1. Add a new event" << endl;
- cout << " 2. Display all scheduled events" << endl;
- cout << " 3. Display events within range" << endl;
- cout << " 4. Quit program" << endl;
- cin >> menuChoice;
- if(menuChoice == 1)
- { cout <<"Please enter the day number:" << endl;
- cin >> dayNumber;
- if(dayNumber >=1 && dayNumber <=31)
- {
- char input[4];
- int mins, hours;
- dayNumberChoice = dayNumber;
- cout << "Please enter the time in 24 hour notation:" << endl;
- cin >> input;
- sscanf (input,"%i:%i",&hours,&mins); // parses the hours and minutes
- if(hours < 01 || hours > 24 || mins < 0 || mins > 59)
- {
- cout << "Please enter a valid time in 24 hour format 00:00." << endl;
- cout << "Hour values: 00-24, Minute values: 00-59" << endl;
- }
- else
- {Test[dayNumber].time = (hours*60)+mins; // converts 24 hour time format to minutes from midnight
- }
- cout << "Please enter the name of the event:" << endl;
- cin >> Test[dayNumber].eventNameChoice;
- eventSched++;
- }
- else
- {
- cout << "Please enter a valid day between 1-31" << endl;
- }
- }
- else if(menuChoice == 2)
- { processMenuChoiceTwo();
- }
- else if(menuChoice == 3)
- { processMenuChoiceThree();
- }
- else if(menuChoice == 4)
- { cout << "Good Bye!" << endl;
- }
- else
- { cout << "You chose an invalid entry." << endl;
- }
- }while(menuChoice!=4);
- }
- void processMenuChoiceTwo()
- {
- if( eventSched == 0)
- {cout << "There are no scheduled events." << endl;
- }
- else
- {
- for(int i = 1; i <= 31; i++)
- {
- if(Test[i].time)
- {cout << "Day " << Test[i].dayNumberChoice << " Time: " << Test[i].time << " Event: " << Test[i].eventNameChoice << endl;
- }
- }
- }
- }
- void processMenuChoiceThree()
- {
- cout << "Please enter the start day:" << endl;
- cin >> startDay;
- if(startDay <=0 || startDay > 31)
- { cout << "Please enter a valid day 1-31." << endl;
- }
- else
- {cout << "Please enter the end day:" << endl;
- cin >> endDay;
- }
- if(endDay <= 0 || endDay > 31)
- {cout << "Please enter a valid day 1-31" << endl;
- }
- else
- {
- for(int i = startDay; i <= endDay; i++)
- {
- if(Test[i].time)
- {cout << "Day " << i << " Time: ";
- printTime(Test[i].time);
- cout << " Event: " << Test[i].eventNameChoice << endl;
- }
- }
- }
- }
- /***********************************************************************
- * NAME: printTime
- * INPUT: Minutes from Midnight variable time.
- * OUTPUT: The time in 24 hour notation.
- * FUNCTION: This method converts the variable time, which is stored as minutes from midnight, back to it's original 24 hour format 00:00
- ***********************************************************************/
- void printTime(int time)
- {
- char out[6];
- int mins;
- int hours;
- mins = time%60;
- hours = time/60;
- sprintf (out, "%02d:%02d", hours, mins);
- cout << out;
- }
Add Comment
Please, Sign In to add comment