Can this run ?????

I need to store and print out the car details

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
#include <iostream>
#include <string>

class Vehicle
{
    protected:
        std::string Manufacturer;
        std::string Type;
        int Numseats = 0 ;

    public:
        Vehicle() = default ;

        Vehicle( std::string manufacturer, std::string type, int numberofseats )
            : Manufacturer(manufacturer), Type(type), Numseats(numberofseats) {} // initialise members

        // accessors and modifiers
        // ...
};

class Car: public Vehicle
{
    protected:
        std::string Carplatenumber;
        std::string Model;

    public:
        Car() = default ;

        Car( std::string manufacturer, std::string type, int numberofseats, // for the base class
             std::string carplatenumber, std::string model )
            : Vehicle( manufacturer, type, numberofseats ), // initialise base class object
              Carplatenumber(carplatenumber), Model(model) {} // initialise members of car

        // accessors and modifiers
        // ...
};

int main ()
{
    const int MAX_SIZE = 80 ;
    Car vehicles[MAX_SIZE] ;
    int choose;
    std::cout << "How many car of information to you want to key in: ";
    int size = 0;
    std::cin >> size;
    if( size > MAX_SIZE ) size = MAX_SIZE ;

    std::string  manufacturer;
    std::string  type;
    int seats;
    std::string  carplatenumber;
    std::string  model;

    for( int i = 0; i < size; ++i )
    {
        std::cout << "Enter manufacturer: ";
        std::cin >> manufacturer;
        std::cout << "Enter vehicle type: ";
        std::cin >> type;
        std::cout << "Enter number of seats: ";
        std::cin >> seats;
        std::cout << "Enter Carplatenumber: ";
        std::cin >> carplatenumber;
        std::cout << "Enter Model: ";
        std::cin >> model;

        vehicles[i] = Car( manufacturer, type, seats, carplatenumber, model ) ;
    }
    while (size>=choose){
    cout<< "Which car do you want to see: ";
    cin>> choose;
    cout<<vehicles[choose]= Car(manufacturer,type,seats,carplatenumber,model);    
    
    }
    // ...
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/192206/
http://www.cplusplus.com/forum/beginner/192198/
Topic archived. No new replies allowed.