Help! Weird concept - having trouble

Hey Everyone, first time posting, long time reader.
I'm attempting to challenge myself and create a program for my own practice in c++ which would have a Vehicle class, which inherits a car and a truck class. Furthermore, there are separate classes such as: Window class, door class, engine class, tire class which would all have to coordinate with the car or truck class. First time attempting this so I am having a lot of trouble - don't understand how I could for example use the inflate function in the tire class on 1 tire inside the car class. Ill post the code I have so far - I'm wondering why none of these lines would work:
car.tire[0].inflate(10);
car.right.close();
car.left.window.rollup();
car.engine.start();

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
  "Main.cpp"

#include "Automobile.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{

Truck truck;
truck.weight = 30000;
Car car;

car.tire[0].inflate(10);
car.right.close();
car.left.window.rollup();
car.engine.start();


}

"Automobile.cpp"

#include "Automobile.h"
#include <iostream>
#include <string>
using namespace std;


const void Window::rolldown()
{
cout << "window is down";
}

const void Window::rollup()
{
cout << "window is up";
}

const void Engine::start()
{
cout << "engine started";
}

const void Engine::stop()
{
cout << "engine stopped";
}

int Tire::inflate(int psi)
{
pressure = pressure + psi;
return pressure;
}

const void Door::close()
{
cout << "door is closed";
}

const void Door::open()
{
cout << "door is open";
}

---------------------------------------------------------------------
"Automobile.h"

#ifndef AUTOMOBILE_H
#define AUTOMOBILE_H
#include <string>
using namespace std;

class Vehicle
{
public:
float weight = 0;

virtual void print() const = 0;
};

class Truck : public Vehicle
{
virtual void print() const
{
		cout << "Truck";
}
};

class Car : public Vehicle
{
public:
Engine engine;
Tire tire[4];
Door left;
Door right;


virtual void print() const
{
		cout << "Car";
}
};

class Engine
{
public:
const void start();
const void stop();
};

class Tire
{
public:
int pressure = 30;
int inflate(int);
};

class Window
{
public:
const void rollup();
const void rolldown();
};

class Door
{
public:
Window window;
const void open();
const void close();
};


#endif AUTOMOBILE_H
Topic archived. No new replies allowed.