Monday, April 6, 2020

C++ question: I make a class (class Car) and I need to know how to write a certain method in it...?

Clark Lachowski: JockyMc has got a good answer, but he has failed to see that the getCarInfo function is actually inside the Car class.Wht you should do is this:class Car {public:string make;string model;int year;float price;void getCarInfo(); // I have a semi colon at the end of the function declaration};void Car::getCarInfo() // I am defining the function here. I have used Car:: at the start so the compiler knows the fuction belongs in the Car class.{cout cin >> make;cout cin >> model;cout cin >> year;cout cin >> price;}If that is how you are supposed to get the info for the car.P.S. You do not include how the function works in the class, as it would be interpreted as an inline function, which you do not want. That is why I put it outside of the class....Show more

Romana Stiman: include #include using namespace std;class Car { // NOTE: member variables should ideally be private and accessed with public member functionspublic: string make;string model;int year;! float price;};void getCarInfo(){ Car theCar; cout cin >> theCar.make; cout cin >> theCar.model; cout cin >> theCar.year; cout cin >> theCar.price;}...Show more

Toney Flaten: A. 36 x 4.20 pounds = 151.20 pounds then 28 x 4.50 pounds = 126 pounds then 8 x 3 pounds = 24 pounds then 126 pounds + 24 pounds = one hundred fifty pounds then 151.20 pounds - one hundred fifty pounds = a million.20 pounds loss.

No comments:

Post a Comment