Someone to help me please wiht an appointment progmram.

Hello Everyone!

I am trying to make an appointment program , and i make it 6 times, but doesn't work every time :(

Here is my code, please...

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
#include <iostream>
#include<fstream>
#include<windows.h>
#include<conio.h>
#include<stdio.h>


using namespace std;


class kabinet
{
    string day;
    int hour;
    string exam;
    char name[50];
    char address[50];
    int phone[10];
    int age[3];//години

public:

    void main_menu();//главно меню
    void type_examin();//вид преглед

    void setDay();//въвеждане на  ден
    void setHour();//назоваването на часа
    int check(int);

    void price_menu();//ценова листа на предлаганите услуги

    void showHour();//показване на свободните часове

    void edit();//опция за промяна

    void modifyHour();//промяна на часа
    void delete_hour();//изтриване на запазения час

    void showDisp();//изписване на информацията относно прегледа


};

void kabinet::main_menu()
{

    system("color D1");
    setlocale(LC_ALL, "bulgarian");    //за използване на български език
    system("chcp 1251>0");


    int choice = 0;

    while (choice != 5)
    {

        system("cls");

        
        cout << "                              /      1.Записване на час                 / /  /" << endl;
        cout << "                             /      2.Показване записани часове        / /  /" << endl;
        cout << "                            /      3.Промяна на час                   / /  /" << endl;
        cout << "                           /      4.Ценоразпис                       /  \_/" << endl;
        cout << "                          /      5.Изход                            /    *" << endl;
        cout << "                         /                                         /  " << endl;
        cout << "                        /                                         /  " << endl;
        cout << "                       /                                         /  " << endl;
        cout << "                      /_________________________________________/  " << endl

            << endl << endl << endl << "Моля въведете своя избор." << endl;
        cin >> choice;


        switch (choice) {

        case 1:system("cls");;
            type_examin();
            break;
        case 2: system("cls");;
            showHour();
            break;
        case 3: system("cls");;
            modifyHour();
            break;
        case 4: system("cls");;
            price_menu();
            break;
        case 5:
            default: {
            cout << "Благодарим Ви!";
            cout << "Благодарим Ви, че използвахте нашата система за записване." << endl;
            _getch();
        }
        }


    }
}

void kabinet::type_examin()
{
    system("cls");
    system("color F6");

    int choiExam = 0;
    string exam;

    while (choiExam != 7)
    {

        cout << endl << endl << endl;


        
        cout << "                               /     1.Медицински преглед                / /  / *" << endl;
        cout << "                              /     2.Диспансерен преглед               / /  /" << endl;
        cout << "                             /     3.Профилактичен преглед             / /  /" << endl;
        cout << "                            /     4.Детска консултация                / /  /" << endl;
        cout << "                           /     5.Женска консултация                /  \_/" << endl;
        cout << "                          /     6.Издаване на документи             /    *" << endl;
        cout << "                         /                                         /  " << endl;
        cout << "                        /     7.Изход                             /  " << endl;
        cout << "                       /                                         /  " << endl;
        cout << "                      /_________________________________________/  " << endl

            << endl << endl << endl << "Моля въведете своя избор." << endl;
        cin >> choiExam;

        string exam;

        switch (choiExam)
        {
        case 1:
            exam = "Медицински преглед";
            setDay(); break;
        case 2: exam = "Диспансерен преглед";
            setDay(); break;
        case 3: exam = "Профилактичен преглед ";
            setDay(); break;
        case 4: exam = "Детска консултация";
            setDay(); break;
        case 5: exam = "Женска консултация ";
            setDay(); break;
        case 6:  exam = "Издаване на документи ";
            setDay(); break;
        case 7:break;
        default:
        {
            cout << "Благодарим Ви!";
            _getch();

        }
        }
    }
}


Last edited on
Hello Asteris,

While I Look at your program take some time to read these links:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.

Andy
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
void kabinet::setDay()
                {

                    system("cls");
                    system("color B2");

                    int day;
                    string date;

                    while (day!=5) {

                        cout << endl << endl << endl;

                        cout << "                                  __________________________________   " << endl;
                        cout << "                                 /                                 /  " << endl;
                        cout << "                                /                                 /  " << endl;
                        cout << "                               /     1.Понеделник                /  " << endl;
                        cout << "                              /     2.Вторник                   /  " << endl;
                        cout << "                             /     3.Сряда                     /  " << endl;
                        cout << "                            /     4.Четвъртък                 /  " << endl;
                        cout << "                           /     5.Петък                     /  " << endl;
                        cout << "                          /                                 /  " << endl;
                        cout << "                         /                                 /  " << endl;
                        cout << "                        /_________________________________/  " << endl

                            << endl << endl << endl << "Моля въведете своя избор." << endl;

                        cin >> day;


                        switch (day)
                        {
                        case 1:
                            date = " Понеделник ";
                            setHour();
                            break;
                        case 2: date = " Вторник ";
                            setHour();
                            break;
                        case 3: date = " Сряда ";
                            setHour();
                            break;
                        case 4: date = " Четвъртък ";
                            setHour();
                            break;
                        case 5: date = " Петък ";
                            setHour();
                            break;
                        default:{
                            cout << "Грешен избор";
                            _getch();
                        }
                    }
                }
            }


            void kabinet::setHour()
            {
                system("cls");
                system("color C3");

                string custumer;
                string day;


                int c, flag;


                ofstream fout("Записани", ios::app);

                cout << endl << endl << " Въведете час: ";
                cin >> c;
                flag = check(c);

                if (flag)
                {
                    cout << "-----------------------------------" << endl;
                    cout << "   Избраният от Вас час е зает.    " << endl;
                    cout << "-----------------------------------" << endl;
                    cout << "      Моля, въведете друг.         " << endl;
                    cout << "-----------------------------------" << endl;
                }

                else
                {
                hour = c;

                cout << endl << endl << "Въведете име и фамилия: ";

                gets(name);

                cout << "Адрес: ";
                gets(address);

                cout << " Телефонен номер: ";

                gets(phone);

                cout << endl << endl << "Възраст: ";
                gets(age);

                fout.write((char*)this, sizeof(kabinet));

                cout << "Успешно записан час!";
            }
                cout << "Натиснете, който и да е клавиш, за да продължите!!!";
                _getch();
                fout.close();
        }

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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
void kabinet::price_menu()
                {


                    cout << endl << endl << endl;

                    cout << "                                  _______________________________________________  " << endl;
                    cout << "                                 /                                              /  " << endl;
                    cout << "                                /                                              /  " << endl;
                    cout << "                               /  Медицинско за работа - 15 лева.             /  " << endl;
                    cout << "                              /  Медицинско за шофьорска книжка              /  " << endl;
                    cout << "                               /                        - 20 лева.            /  " << endl;
                    cout << "                            /  Оформяне на документи за застраховка        /  " << endl;
                    cout << "                           /                       - 50 лева.             /  " << endl;
                    cout << "                          /   Потребителски такси:                       /  " << endl;
                    cout << "                         /           за пенсионери - 1лев.              /  " << endl;
                    cout << "                        /            за осигурени лица - 2,90лева.     /  " << endl;
                    cout << "                       /                                              /  " << endl;
                    cout << "                      /   Преглед за лица, които не са осигурени     /  " << endl;
                    cout << "                     /                       - 20 лева.             /  " << endl;
                    cout << "                    /  1.Назад към главното меню                   /  " << endl;
                    cout << "                   /______________________________________________/  " << endl;

                    cout << "Натиснете, който и да е клавиш, за да продължите!!!";
                    _getch();
                    fout.close();

        }
        void kabinet::showHour();
        {
            system("cls");
            system("color B1");
            ifstream fin("Записани данни: ", ios::in);
            int c, flag;

            cout << "Въведете запазен час: ";
            cin >> c;
            while (!fin.eof())

            {
                fin.read((char*)this, sizeof(kabinet));
                if (hour == c)
                {
                    system("cls");
                    cout << " Данни на пациента. ";
                    cout << "--------------------" << endl;
                    cout << "Имена: " << name;
                    cout << "Адрес: " << address;
                    cout << "Телефонен номер: " << phone;
                    cout << "Записан час за: " << date << "Час: " << hour;

                    flag = 1;
                    break;

                }

            }
            if (nomb== 0)
                cout << "Търсеният от вас номер не фигурира!!!";

            cout << "Натиснете, който и да е клавиш, за да продължите!!!";
            _getch();
            fin.close();
        }


        void kabinet::edit()
        {
            system("cls");
            system("color A3");
            int c, flag;


            cout << "\n Меню за промяна";
            cout << "\n ***************";
            cout << "\n 1.Промяна на час ";
            cout << "\n 2.Изтриване на запазен час";

            cout << "Моля, изберете: ";
            cin >> choise;

            system("cls");
            cout << "\n Въведете запазен час: ";
            cin >> c;

            switch (choice)
            {
            case 1: modifyHour(c);
                break;
            case 2:
                 delete_hour(c);//изтриване на запазения час
                break;
            default: cout << "\n Грешен избор!!";
            }

            cout << "\n  Натиснете, който и да е клавиш, за да продължите!!!";
            _getch();
        }

        int kabinet::check(int c)
        {
            system("color F2");
            int flag = 0;
            ifstream fin("Записи: ", ios::in);
            while (!fin.eof())
            {
                fin.read((char*)this, sizeof(hotel));
                if (hour== c)
                {
                    flag = 1;
                    break;
                }
            }

            fin.choice();
            return (flag);

}

        void kabinet::modifyHour(int c)

        {
            system("color C3");
            long pos, flag = 0;
            fstream file("Record.dat", ios::in | ios::out | ios::binary);

            while (!file.eof())
            {
                pos = file.tellg();
                file.read((char*)this, sizeof(kabinet));
                if (hour == c)
                {
                    cout << "\n Въведете данните наново";
                    cout << "\n ***********************";
                    cout << "\n Име: ";
                    gets(name);
                    cout << " Адрес: ";
                    gets(address);
                    cout << " Телефонен номер: ";
                    gets(phone);

                    file.seekg(pos);
                    file.write((char*)this, sizeof(kabinet));
                    cout << "\n Данните Ви са променени!!!";
                    flag = 1;
                    break;
                }
            }

            if (flag == 0)
                cout << "\n Часът не е намерен!";

            file.close();


        }

        void kabinet::delete_hour(int c)

            int flag = 0;
        char ch;
        ifstream fin("Record.dat", ios::in);
        ofstream fout("temp.dat", ios::out);

        while (!fin.eof())
        {
            fin.read((char*)this, sizeof(kabinet));
            if (hour == c)
            {
                cout << "\n Име: " << name;
                cout << "\n Адрес: " << address;
                cout << "\n Телефонен номер: " << phone;
                cout << "\n\n Искате ли да изтриете данните? (y/n): ";
                cin >> ch;

                if (ch == 'n')
                    fout.write((char*)this, sizeof(kabinet));

                flag = 1;
            }
            else
                fout.write((char*)this, sizeof(kabinet));
        }
        fin.close();
        fout.close();

        if (flag == 0)
            cout << "\n Часът не е намерен.";
        else
        {
            remove("Record.dat");
            rename("temp.dat", "Record.dat");
        }
}

int main()
{


    kabinet h;

    system("color A4"

        system("cls");
    cout << "\n\t\t\t*********************************";
    cout << "\n\t\t\t*    Проект за запис на час     *";
    cout << "\n\t\t\t*********************************";
    Sleep(200);

    char text[] = { "\n\n\n\n\t\t };
    for (int p = 0; p < strlen(text); p++)   
        cout << text[p];
        Sleep(40);
    }

    cout << "\n\n\tНатиснете който и да е клавиш!!";
    _getch();
    h.main_menu();
} 
Hello Asteris,

When I first tried to compile the program it gave me 125 errors and 14 warnings.

After I fixed a few thing at the beginning it went to 143 errors ans 13 warnings.

There are many small problems with your code that need to be fixed so the code will compile.

The line using namespace std; was a problem at first and still is for now, so I replaced it with:
1
2
3
4
using std::cin;
using std::cout;
using std::endl;
using std::string;

When I typed the last line I noticed that you are missing the header file "string".

I will use the functions that you posted and see what happens. And I will work on getting the code to compile.

While i am thinking about it in the switches the {}s in the "default" are OK, but not really needed here.

I do recall at least one line if not more that should start with "cout", but does not.

See what you can do about fixing the errors.

Hope that helps,

Andy
Thank you Andy!
With which compiler are you working?
Hello Asteris,

I am using Visual Studio 2017.

One thing I have noticed is that you are mixing C code with C++ code and sometimes it does not work. Especially when some of the C code is outdated.

Right now I am having a problem with "gets()" and at least three variables that are undefined.

Much better than the 142 errors I first had.

Andy
Hello Andy,

Thank you very much.
I am going to bild a new program again.
Thank you.
Hello Asteris,

I think that would be a good idea because what you have is not working very well.

I would keep the class for now, but I would put it in its own header file and the class functions in its own ".cpp" file. Since the class functions are written I would keep them and change if needed.

In "main" I like to use the variable int menuChoice{}; and have the "main_menu" function return a valid value to "main".

I would suggest that the "main_menu" function print the menu, input a choice and make sure it is a valid choice before returning it to "main".

You can leave this in "main", but I believe this is more of what you want:
1
2
3
cout << "**********************************" << '\n';
cout << "*       HOTEL RESERVATIONS       *" << '\n';
cout << "**********************************" << '\n';

Or something like it.

The use of "Sleep()" is nice, but the wait of 200 milliseconds or less than 1/4 of a second is not much of a delay that can be noticed. And the second "Sleep()" time is about the same as having nothing.

cout << text; does the same thing as the for loop, but I would scrap that as I do not see much use in it. Actually this is a good place to call the "main_menu" function.

Your code:
1
2
cout << "\n\n\t!!";
_getch();

Just leaves the unknowing use what is needed to be entered. "main" done properly there is really no need for it.

The switch that you have in "main_menu" is better put in "main" where it can be used to direct the program flow.

In "main_menu" a do while loop generally works the best to print the menu, get user input and make sure it is a valid choice. A do/while loop would also work in "main" to keep the program going more than once. The do while loop can be added later when the program is working.

Hope that helps,

Andy
Hello Asteris,

In case I was not clear in what I said. I only want you to work on the functions "main" and "main_menu" for now.

Until they are finished there is no point in going farther with the other functions.

Andy
Thank you very much!
Hello Andy!
I will take your advice.
And i am starting a new rrogram right now.
Have a nice evening. :)

Ester
Topic archived. No new replies allowed.