Appointment program

Hi
I have to code a menu based program using functions and parallel arrays to keep track of weekly appointments from monday to friday. The user should be able to add/change or cancel an appointment.

So i have 5 arrays, one for each day of the week where every index represents an hour but i'm having trouble to figure out how i can store the inputs to the right array (day) and index (time), also i'm not sure how i'm going to get it to store two inputs (name and type of treatment) into the same array and index.

if anyone could help me figure this out it would be appreciated.

Last edited on
Why not use a 2D array, where columns are days and rows are hours?
Use as inspiration: https://www.google.com/calendar/render#main_7

Why not use a struct to hold the two (or more) values at each index in the array?
I've tried a few things last night and i'm stuck again with my arrays, the program compiles but the inputs seem to be overwriting themselves instead of telling me that hour has already been taken.
I like the idea of 2D arrays and struct but i'm not quite familiar with it as I have only covered standard arrays so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using namespace std;

#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <string>
#include <stdlib.h>


const unsigned short numComponents = 10;

unsigned short prices[numComponents];
string treatments[numComponents];

void welcome ();
void showMenu ();
void priceList ();
void makeAppointment ();
void openAppointments();
void checkTime();

char choice;
int day;
string date, customer, treatment;
string appBook[5][8][3];

int main () {
       welcome ();
       openAppointments();

   do {
        showMenu ();
        switch (toupper(choice)) {
            case 'A': makeAppointment(); break;
            case 'P': priceList (); break;
            case 'Q': cout << "\\ntThank you for using this application.\n"; break;
            default: cout << "\t\a\a\aInvalid choice.\n\n";
        }
   }
   while (toupper(choice) != 'Q');
   return 0;

}

void welcome () {
// Welcome the user to the program.

     cout << "\n\t\t\t   **************************\n\t\t\t   Curl Up and Dye Hair Salon\n\t\t\t   **************************\n\n";
}

void showMenu () {
// Output the menu to the user.

    cout << "\n\n\t\tSelect one of the following options:\n"
         << "\t\t------------------------------------\n\n"
         << "\t\tA:Make an Appointment\n"
         << "\t\tP: Price List\n"
         << "\t\t\t";
     cin >> choice;
    }

void openAppointments(){

}

void priceList () {
/*
   Reads in the treatments and corresponding prices from the Treatments.txt and PriceList.txt files respectively. The prices are held in the array "prices"
   and the treatments are stored in the array "treatments". You do not need to know how to do this, this is simply for convenience.
*/

    ifstream treatmentFile("treatments.txt"), priceFile("priceList.txt");

    for (unsigned short i = 0; i<numComponents-1; i++) {
       getline (treatmentFile,treatments[i],'\n');
       priceFile >> prices[i];
       }
    treatmentFile.close ();
    priceFile.close ();
    }

void printPrices (string treatments, unsigned short prices[]) {

    for (unsigned short i = 0; i < numComponents; i++) {
      cout << setw (50) << setiosflags(ios::left) << treatments[i] << prices[i] << "\n";
    if (i% 20 == 0 && i != 0)
         getch ();
      }

    }

void showDays () {
// Output the menu to the user.

    cout << "\n\n\t\tSelect one of the following days:\n"
         << "\t\t------------------------------------\n\n"
         << "\t\t0:Monday\n"
         << "\t\t1:Tuesday\n"
         << "\t\t2:Wednesday\n"
         << "\t\t3:Thursday\n"
         << "\t\t4:Friday\n"
         << "\t\t\t";
     cin >> day;
    }

void makeAppointment () {
// Asks the user for the day of the appointment
    showDays();
    switch(day){
    case 0:
        date = "Monday";
        checkTime();
        break;
    case 1:
        date = "Tuesday";
        checkTime();
        break;
    case 2:
        date = "Wednesday";
        checkTime();
        break;
    case 3:
        date = "Thursday";
        checkTime();
        break;
    case 4:
        date = "Friday";
        checkTime();
        break;
    default:
        showMenu();
        break;
    }
}

void checkTime(){
// Checks the arrays for free time and stores the inputs.
    int time;
    bool checkSum = false;

    do{
        cout << "\n\n\t\tEnter time for appointment:\n"
         << "\t\t------------------------------------\n\n";
        cin >> time;
        if(appBook[day][time-9][0] == ""){
           cout << "\n\n\t\tEnter the customer name:\n"
                 << "\t\t------------------------------------\n\n";
            cin >> customer;
            cout << "\n\n\t\tEnter the treatment for "<< customer <<":\n"
                 << "\t\t------------------------------------\n\n";
            cin >> treatment;
            appBook[day][time-9][0] = date;
            appBook[day][time-9][1] = customer;
            appBook[day][time-9][2] = treatment;
            checkSum = true;
        } else {
            cout << "\t\t-----------------------\n\n"
                 << "\n\n\t\tThat time is taken!\n"
                 << "\t\t-----------------------\n\n";
        }
    }while(checkSum == false);

    cout << appBook[day][time-9][1] << " is getting a " << appBook[day][time-9][2] << " at " << time << " on " << appBook[day][time-9][0];
}
Last edited on
looks like someone was too lazy to write a post and decided to copy mine...

Anyways, can anyone give me a hint on why my arrays aren't storing the input?
What evidence do you have that suggest to you that your arrays are not storing the input?
Topic archived. No new replies allowed.