bus seat reservation program

For my assignment, I need to create a program that will allow user to reserve a seat in one of two bus (one smoker and one non-smoker). There must be a menu that looks like this:
For smoker press 1
for non smoker press 2

Then the program gives a seat from 1-40 (if smoker), or from 1 to 40 (if non smoker). If the bus is full, the user must be motified.

After the reservation, the user must have a little document with the number of the seat, the bus (smoker or non-smoker) and the number of people in the bus.

I did all the coding of this using a Do While, thing is I must use classes (im a total noob with that). From what my teacher told me, there should be a class named bus with the functions like printing the document, bus full, add a passenger, set type, get type.

I just don't know where to start so a little help would be appreciated.


Here's my code if it can be useful (Do While method)
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
  #include <iostream>
#include <string>

using namespace std;

int main()
{
    int choix, passagerF=0, passagerNF=0 ;
    string nom, prenom;
    char rep;

   cout << "\t\t\t\t" << "Autobus NY" << endl;
   cout << "\t" << "Bienvenue dans le programme d'assignation des places" << endl;
   cout << endl;

do{
   cout << "Entrez votre nom: " ;
   cin >> nom; cout << endl;
   cout << "Entrez votre prenom: " ;
   cin >> prenom; cout << endl;


   cout << "Appuyez sur 1 pour non-fumeurs." << endl;
   cout << "Appuyez sur 2 pour fumeurs." << endl;

   cin >> choix ;


   if (choix==1)
    {
        passagerNF++ ;
        if (passagerNF<=40)
            {
            cout <<"**************************************" ; cout << endl;
            cout << "Nom du passager: " << prenom <<" " << nom << endl;
            cout << "Siege: " << passagerNF <<" dans l'autobus non-fumeurs. " << endl;
            cout << "Nombre total de passagers: " << passagerNF; cout << endl;
            cout <<"**************************************" ; cout << endl;
            } else
                {
                    cout << "*** ATTENTION: L'autobus non-fumeurs est complete. ***" ; cout << endl;
                }
    }

   if (choix==2)
    {
         passagerF++ ;
        if (passagerF<=40)
        {
       cout <<"**************************************" ; cout << endl;
       cout << "Nom du passager: " << prenom <<" " << nom << endl;
       cout << "Siege: " << passagerF <<" dans l'autobus fumeurs. " << endl;
       cout << "Nombre total de passagers: " << passagerF; cout << endl;
       cout <<"**************************************" ; cout << endl;
        }else
                {
                    cout << "*** ATTENTION: L'autobus fumeurs est complete. ***" ; cout << endl;
                }
    }
cout << endl;
  cout << "Voulez-vous faire une autre reservation? (Y ou N)" << endl;
  cin >> rep ;

} while(rep=='Y'||rep=='y') ;

}
A good starting place for learning how to make a class in C++ is the tutorial on this site http://www.cplusplus.com/doc/tutorial/
There is an entire section of the tutorial dedicated to classes.

Before you read about C++ classes, I recommend you read about C++ functions. The same tutorial link has information about functions. Small sections of your main code will become functions in the bus class that you will create.
Alright! Thank you ill start by looking at this.
closed account (E0p9LyTq)
Another site with good tutorials is http://www.learncpp.com/
I've been havings lots of difficulty with the class, the only thing I have to "study" is some random PDF that doesn't explain anything. Im all minxed up with class, functions and what I should put in the int main.
"Studying" is one of the most important parts of learning a new language. Whether that language is a human one or a computer one is irrelevant. I urge you to spend more time "studying" the syntax of classes and functions in the tutorials linked above. But once you have a grasp on the syntax, you should start with class Bus {}; above your main function. Inside of this empty class you can write functions that "printing the document, bus full, add a passenger, set type, get type". These functions sound like they should be in the public: section of your Bus class. To give those functions the variables that they need, some of the variables declared in main will need to be moved to the Bus class, and they should be placed in the private: section. Your main code will need to have a new variable of type Bus. The Bus variable is what you use to call functions in the Bus class.
1
2
Bus bus;
<type> t = bus.getType(); //I don't know your assignment enought to know what <type> should be 

get functions usually just have one line inside of them that returns a variable.
set functions usually just have one line that assigns a parameter that is passed to a variable.

One key thing you have to realize with classes is that variables in a class are shared between all the functions inside of that class. However, the variables in one Bus variable are not the same as another Bus variable.
Bus busCool, busFast; //busCool and busFast would not share the same variables, their variables are seperate
Topic archived. No new replies allowed.