Hello agirideep,
The problem is in line 50.
If that does not work explain your problem better. I have no idea where to start looking.
Why are you using "printf" in a C++ program?
Lines 15 - 18 you do not need a "cout" and "endl" for each line. That is what the insertion operator (>>) is for.
Andy
Lines 14 through 18 assign local variables instead of class member data.
Perhaps:
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
|
#include <iostream>
#include <string>
class Car {
int yearModel {};
std::string make;
int speed {};
public:
Car(int y, const std::string& m) : yearModel(y), make(m) {}
void accelerate() { speed += 5; }
void brake() { speed -= 5; }
int getyearModel() const { return yearModel; }
std::string getMake() const { return make; }
int getSpeed() const { return speed; }
};
int main()
{
Car sedan(2012, "Toyota");
sedan.accelerate();
sedan.accelerate();
sedan.accelerate();
sedan.brake();
const auto sze {printf("Car Information\n")};
std::cout << std::string(sze - 1, '-') << '\n' <<
"Maker: " << sedan.getMake() << '\n' <<
"Year: " << sedan.getyearModel() << '\n' <<
"Speed: " << sedan.getSpeed() << '\n';
}
|
Last edited on