-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbikeClassesMultipInherit.cpp
216 lines (202 loc) · 6.59 KB
/
bikeClassesMultipInherit.cpp
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
//Rikard Grossman-Nielsen 2 oct 2022
//Description:
//Bikeclass with multiple inhertance
//My own class that has general class bike and classes that represents different types of bikes
//The classes that represents different types of bikes inherts the base class, adding some properties,
//which the base class doesn't have
#include <iostream>
using namespace std;
//Base class Bike, base class inherited by classes that represent different base classes
class Bike{
protected:
float frameHeightCentiMetre, wheelSizeInch, warrantyYrs;
public:
Bike(){}
void setFrameHeightCm(float frameHeightCentiMetre){
Bike::frameHeightCentiMetre=frameHeightCentiMetre;
}
float retFrameHeightCm(void){
return frameHeightCentiMetre;
}
void setWheelSizeInch(float wheelSizeInch){
Bike::wheelSizeInch = wheelSizeInch;
}
float retWheelSizeInch(void){
return wheelSizeInch;
}
void setWarrantYrs(float warrantyYrs){
Bike::warrantyYrs=warrantyYrs;
}
float retWarrantyYrs(void){
return warrantyYrs;
}
~Bike(){
cout << "Constructor executed!";
//to do add lines for deleting pointers
};
};
//base class StoreItem inherted by all classes that represent different types of Bikes, since all bikes are items
//ypu buy in a store.
//to do:
//27th oct 2022
//change items storeItem:artNr and so on....
class storeItem{
protected:
int artNr;
float priceEurExcVAT, vatPercent;
string store, shelf, city;
public:
storeItem(){}
void setArtNr(int artNr){
storeItem::artNr = artNr;
}
int retArtNr(void){
return artNr;
}
void setPriceEurExcVAT(float priceEurExcVat){
storeItem::priceEurExcVAT = priceEurExcVat;
}
float retPriceEur(void){
return priceEurExcVAT;
}
float retPriceEurIncVat(void){
return (1+vatPercent)*priceEurExcVAT;
}
void setVatPercent(float vatPercent){
storeItem::vatPercent = vatPercent;
}
float retVatPercent(void){
return vatPercent;
}
void setStore(string store){
storeItem::store=store;
}
string retStore(void){
return store;
}
void setShelf(string shelf){
storeItem::shelf = shelf;
}
string retShelf(void){
return shelf;
}
void setCity(string city){
storeItem::city = city;
}
string retCity(void){
return city;
}
};
class regularBike: public Bike, public storeItem{
protected:
int nrOfSpeeds;
public:
regularBike(){}
void setNrOfSpeeds(int nrOfSpeeds){
regularBike::nrOfSpeeds = nrOfSpeeds;
}
int retNrOfSpeeds(void){
return nrOfSpeeds;
}
};
class racingBike: public Bike, public storeItem{
protected:
float topSpeedKph, weightKg;
int nrOfSpeeds;
public:
racingBike(){}
void setTopSpeedKph(float topSpeedKph){
topSpeedKph=topSpeedKph;
}
float retTopSpeedKph(void){
return topSpeedKph;
}
void setWeight(float weightKg){
weightKg = weightKg;
}
float retWeight(void){
return weightKg;
}
void setNrOfSpeeds(int nrOfSpeeds){
racingBike::nrOfSpeeds=nrOfSpeeds;
}
int retNrOfSpeeds(void){
return nrOfSpeeds;
}
};
int main(void){
regularBike regBike1;
racingBike raceBike1;
//set parameters for regularBike1
//This object represent a typical Regular 3 speed Bike for women with 28inch wheels
regBike1.setFrameHeightCm(55.0);
regBike1.setWheelSizeInch(28);
regBike1.setWarrantYrs(2);
regBike1.setArtNr(100101);
regBike1.setPriceEurExcVAT(400);
regBike1.setVatPercent(0.25);
regBike1.setStore("Northtown shopping centre");
regBike1.setCity("Gothenburg");
regBike1.setNrOfSpeeds(3);
//set parameters for raceBike1
//This repsents a racebike sould for roughly 1300 euros in a swedish sporting goods store
raceBike1.setFrameHeightCm(58.0);
raceBike1.setWheelSizeInch(28);
raceBike1.setWarrantYrs(2);
raceBike1.setArtNr(200112);
raceBike1.setPriceEurExcVAT(11200);
raceBike1.setVatPercent(0.25);
raceBike1.setStore("Backebol shopping centre");
raceBike1.setCity("Gothenburg");
raceBike1.setNrOfSpeeds(12);
raceBike1.setTopSpeedKph(50.5);
//print values of objects
//print values of regularBike
cout << "Values of regularBike1: " << "\n";
cout << "------------------------" << "\n";
cout << "Frameheight: " << "\n";
cout << regBike1.retFrameHeightCm() <<" cm" << "\n";
cout << "Wheelsize: " << "\n";
cout << regBike1.retWheelSizeInch() <<" inch" << "\n";
cout << "Warranty:" << "\n";
cout << regBike1.retWarrantyYrs() << " yrs" << "\n";
cout << "Article number:" << "\n";
cout << regBike1.retArtNr() << "\n";
cout << "Price excl VAT:" << "\n";
cout << regBike1.retPriceEur() << "\n";
cout << "Price incl VAT:" << "\n";
cout << regBike1.retPriceEurIncVat() << "\n";
cout << "Vat percent:" << "\n";
cout << regBike1.retVatPercent() << "\n";
cout << "Store:" << "\n";
cout << regBike1.retStore() << "\n";
cout << "City:" << "\n";
cout << regBike1.retCity() << "\n";
cout << "Nr of speeds:" << "\n";
cout << regBike1.retNrOfSpeeds() << "\n";
//blank line
cout << "\n";
cout << "Values of regularBike1: " << "\n";
cout << "------------------------" << "\n";
cout << "Frameheight: " << "\n";
cout << raceBike1.retFrameHeightCm() <<" cm" << "\n";
cout << "Wheelsize: " << "\n";
cout << raceBike1.retWheelSizeInch() <<" inch" << "\n";
cout << "Warranty:" << "\n";
cout << raceBike1.retWarrantyYrs() << " yrs" << "\n";
cout << "Article number:" << "\n";
cout << raceBike1.retArtNr() << "\n";
cout << "Price excl VAT:" << "\n";
cout << raceBike1.retPriceEur() << "\n";
cout << "Price incl VAT:" << "\n";
cout << raceBike1.retPriceEurIncVat() << "\n";
cout << "Vat percent:" << "\n";
cout << raceBike1.retVatPercent() << "\n";
cout << "Store:" << "\n";
cout << raceBike1.retStore() << "\n";
cout << "City:" << "\n";
cout << raceBike1.retCity() << "\n";
cout << "Nr of speeds:" << "\n";
cout << raceBike1.retNrOfSpeeds() << "\n";
return 0;
}