• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

appointment book program

I am interested in putting together a program that will organize events on certain dates.  I was thinking each appointment would contain a subject, location, date, time (start and end), and a description of the meeting.  I want the interface to be a menu-driven system that you can add an appointment, delete an appointment, print a certain appointment, print all the appointments, and finally exit the program.  I hope someone can help me with this program.  Thanks.
0
greyfacemagilicuty
Asked:
greyfacemagilicuty
1 Solution
 
mactep13Commented:
Well, I can steer you into a direction. You'll need the placeholder for your data. A struct or a class that will contain Subject, location, fate, time, description, etc. Once you have that class, you'll need to place data in it. You will need some type of menu interface. SOmething like this:

do
{
cout << "Main Menu << endl;
cout << endl;
cout << "1. Add Appointment" << endl;
cout << "2. Delete Appointment" << endl;
cout << "3. Print Appointment" << endl;
etc...
cout << "0. Exit" << endl;
int nNum = -1;
cout << "Enter Selection: ";
cin >> nNum;

switch (nNum)
{
   case 1:
               AddAppointment();
               break;
    case 2:
              DeleteAppointment()
              break;
    default:
                 // None of the above, print error and repeat
                PrintWrongSelection();
                break;
}
}
while (nNum != 0);

This should get you started. Once you get a record populated (filled in), you'll need to store it in the collection. The most logical collection for this type of program is a map.
Check STL documentation for a map.
Map will allow you to search based on a key, like name or something.

If you're having difficulties understanding some of this, let me know.
Hope this helps.
Mactep
0
 
novitiateCommented:
if you can start designing/coding and share your ideas, we can help.

_novi_
0
 
dog_Commented:
I would start by creating a base class for a generic appointment type that contains base information germain to all appointments such as date and time. That way you can derive off of it in the future but still maintain your processing by polymorphic behavior. Who knows, maybe you will want to create a special DoctorAppointment in the futire that notifies you further in advance than say a meetingAppointment....

You can derive a GeneralAppointment from that and start testing. You will need a list to hold all of your appointments. Use a sorted list so you don't have to do too much work on the list.

I would also use a GUI to add, delete and view appointments. Use MFC and you can get a monthly calendar tool that will make your life simpler.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
greyfacemagilicutyAuthor Commented:
I have used the help you have given me and put together the beginning to this program using a linked list.  In my original program design I included a search string to find a specific appointment based on its subject. I was having trouble and took the search out - I'm not sure whether taking it out has affected my current program.  I would appreciate any help you could give me in fixing this code.  Thanks

//NOTE: app_book.txt is automatically read as the program starts.  Data is saved in saved.txt when the program ends.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

struct app_book
{
     string subject;
     string location;
     int date;
     string description;    
     string start;
     string finish;
     book* next;
     book(string, string, int, string, string, string, app_book*);
};

app_book::app_book(string tempSubject, string tempLocation, int tempDate, string tempDescription, string tempStart, string tempFinish, app_book* tempNext)
:subject(tempSubject), location(tempLocation), date(tempDate), description(tempDescription), start(tempStart), finish(tempFinish), next(tempNext)
{}

typedef app_book* app_bookPtr;

void getline(istream &stream, string &str, char delimiter)
{     char temp[500];

     stream.get(temp, 500, delimiter);
     stream.ignore(500, delimiter);
     str = temp;
}

void getline(istream &stream, int &num, char delimiter)
{     int temp;

     stream >> temp;
     stream.ignore(500, delimiter);
     num= temp;
}

void readFile(app_bookPtr &root);
void insert (app_bookPtr &root);
void delSubject(app_bookPtr &root);
bookPtr locateNode(app_bookPtr temp, string tit);
void delDate(app_bookPtr &root);
bookPtr locateNodeDate(app_bookPtr temp, string isb);
void searchDate(app_bookPtr temp);
void printList(app_bookPtr temp);
void printLocation(app_bookPtr temp);
void saveFile(app_bookPtr temp);
int countNodes(app_bookPtr temp);

int main()
{
     int choice;
     app_bookPtr root = NULL;
     readFile(root);

     do
     {
          cout << "Menu: Select your option\n\n";
          cout << "(1) Add an appointment\n";
          cout << "(2) Delete an appointment based on Subject\n";
          cout << "(3) Print appointment(s) based on Subject\n";
          cout << "(4) Print all appointments\n";
          cout << "(5) Quit.\n\n";
          cout << "Enter your choice ---> ";

          cin >> choice;

          if (1 <= choice && choice <= 4)
          {    
               switch (choice)
               {
               case 1:
                    insert(root);
                    break;
               case 2:
                    delSubject(root);
                    break;
               case 3:
                    printSubject(root);
                    break;
               case 4:
                    printList(root);
                    break;              
               default:
                    cout << "Invalid choice.  Enter again.\n\n";
                    break;
               }
          }    
     }
     while (choice != 5);
     saveFile(root);
     return 0;
}

void readFile(app_bookPtr &root)
{
     int numAppts, date;
     string sub, loc, srt, fin;
     ifstream infile ("app_book.txt", ios::in);
     infile >> numAppts;
     infile.ignore(500,'\n');
     for (int count = 0; count < numAppts; count++)
     {
          getline(infile, sub, '\n');
          getline(infile, loc, '\n');
          getline(infile, date, '\n');
          getline(infile, srt, '\n');
          getline(infile, fin, '\n');

          root = new app_book (sub, loc, date, srt, fin, root);
     }
}

void insert (app_bookPtr &root)
{
     string sub, loc, srt, fin;
     int date;

     cout << "Subject:\t\t\t";
     cin.ignore(500,'\n');
     getline(cin, sub, '\n');
     cout << "Location:\t\t\t";
     getline(cin, loc, '\n');
     cout << "Date:\t\t";
     getline(cin, date, '\n');
     cout << "Start:\t\t\t";
     getline(cin,srt, '\n');
     cout << "Finish:\t\t\t";
     getline(cin, fin, '\n');

     root = new app_book (sub, loc, date, srt, fin, root);
}

void delSubject(app_bookPtr &root)
{
     string sub;
     
     cout << "Appointment Subject:\t\t\t";
     cin.ignore(500,'\n');
     getline(cin, sub, '\n');

     app_bookPtr p = locateNode(root, tit);

     if (p == NULL)
          cout << "\nDeletion cannot be done.\n\n";
     else if (root == p)
          root = p->next;
     else
     {
          app_bookPtr q = root;
          while (q->next != p)
               q = q->next;
          q->next = p->next;
     }
     delete p;
}

app_bookPtr locateNode(app_bookPtr temp, string sub)
{
     while (temp != NULL)
     {
          if (temp->subject == sub)
          {
               return temp;
          }
          temp = temp->next;
     }
     return NULL;
}
------------------------------------------------------------------------------------------------------------------
void delSubject(app_bookPtr &root)
{
     string isb;
     
     cout << "Subject of appointment:\t\t\t";
     cin.ignore(500,'\n');
     getline(cin, isb, '\n');

     app_bookPtr p = locateNodeSubject(root, sub);

     if (p == NULL)
          cout << "\nDeletion cannot be done.\n\n";
     else if (root == p)
          root = p->next;
     else
     {
          app_bookPtr q = root;
          while (q->next != p)
               q = q->next;
          q->next = p->next;
     }
     delete p;
}

app_bookPtr locateNodeSubject(app_bookPtr temp, string sub)
{
     while (temp != NULL)
     {
          if (temp->subject == sub)
          {
               return temp;
          }
          temp = temp->next;
     }
     return NULL;
}

void printList(app_bookPtr temp)
{
     while (temp != NULL)
     {
          cout << temp->subject << "\n";
          cout << temp->location << "\n";
          cout << temp->date << "\n";
          cout << temp->description << "\n";
          cout << temp->start << "\n";
          cout << temp->finish << "\n\n";
          temp = temp->next;
     }
     cout << "\n";
}

void printSubject(app_bookPtr temp)
{
     string sub;

     cout << "Subject name:\t\t\t";
     cin.ignore(500,'\n');
     getline(cin, aut, '\n');
     
     while (temp != NULL)
     {
          if (temp->author == aut)
          {
               cout << temp->subject << "\n";
               cout << temp->location << "\n";
               cout << temp->date << "\n";
               cout << temp->description << "\n";
               cout << temp->start << "\n";
               cout << temp->finish << "\n\n";
          }
          temp = temp->next;
     }
     cout << "\n";
}

void saveFile(app_bookPtr temp)
{
     int count = countNodes(temp);
     ofstream outFile("saved.txt",ios::out);
     
     outFile << count << "\n";
     while (temp != NULL)
     {
          outFile << temp->subject << "\n";
          outFile << temp->location << "\n";
          outFile << temp->date << "\n";
          outFile << temp->description << "\n";
          outFile << temp->start << "\n";
          outFile << temp->finish << "\n";
          temp = temp->next;
     }
     cout << "\n";
}

int countNodes(app_bookPtr temp)
{
     int countB = 0;
     while (temp != NULL)
     {
          countB++;
          temp = temp->next;
     }
     return countB;
}
0
 
greyfacemagilicutyAuthor Commented:
I would greatly appreciate a response as soon as possible.  Unfortunately I have a meeting early tomorrow and need to have covered this program's material.  Your suggestions have been very helpful so far.  Thanks again and I hope to hear from you soon.
0
 
greyfacemagilicutyAuthor Commented:
I do not understand why my question is not being answered!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now