I think I got it a little bit further, but I still don't really understand what you mean. I asked my teacher in lab today about it and got a little more of it understood, but there must still be something i'm missing. Now I have many more errors but their all variations of the same problem, so I think it's just with my variables.
lab12a.cpp: In member function âint Car::getSpeed()â:
lab12a.cpp:27: error: âSpeedâ was not declared in this scope
lab12a.cpp: In member function âint Car::getYear()â:
lab12a.cpp:31: error: âYearâ was not declared in this scope
lab12a.cpp: In member function âstd::string Car::getMake()â:
lab12a.cpp:35: error: âMakeâ was not declared in this scope
lab12a.cpp: In member function âint Car::Accelerate()â:
lab12a.cpp:39: error: âSpeedâ was not declared in this scope
lab12a.cpp: In member function âint Car::Brake()â:
lab12a.cpp:44: error: âSpeedâ was not declared in this scope
lab12a.cpp: In function âint main()â:
lab12a.cpp:64: error: request for member âgetSpeedâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:66: error: request for member âAccelerateâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:68: error: request for member âAccelerateâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:70: error: request for member âAccelerateâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:72: error: request for member âAccelerateâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:74: error: request for member âAccelerateâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:76: error: request for member âBrakeâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:78: error: request for member âBrakeâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:80: error: request for member âBrakeâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:82: error: request for member âBrakeâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
lab12a.cpp:84: error: request for member âBrakeâ in âClassCarâ, which is of non-class type âCar(int, int, std::string)â
Here's the code now:
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
|
// 2-1-2018
// Lab12A
// Uses a class named Car to perform accelarate and brake functions
#include <iostream>
#include <string>
using namespace std;
class Car
{
private:
int year,speed;
string make;
public:
Car(int year,int speed,string make)
{
int Year = year;
int Speed = speed;
string Make = make;
}
int getSpeed()
{
return Speed;
}
int getYear()
{
return Year;
}
string getMake()
{
return Make;
}
int Accelerate()
{
Speed = Speed + 5;
return Speed;
}
int Brake()
{
Speed = Speed - 5;
return Speed;
}
};
int main()
{
int Year;
int Speed;
string Make;
cout << "Please enter the year of your car: ";
cin >> Year;
cout << endl << "Please enter the make of your car: ";
cin >> Make;
Car ClassCar(int year,int speed,string make);
cout << endl << "Your car is currently going " << ClassCar.getSpeed()
<< "mph. It will now accelerate." << endl;
cout << "Your car is now going " << ClassCar.Accelerate() << "mph."
<< " Your car will Accelerate again." << endl;
cout << "Your car is now going " << ClassCar.Accelerate() << "mph."
<< " Your car will Accelerate again." << endl;
cout << "Your car is now going " << ClassCar.Accelerate() << "mph."
<< " Your car will Accelerate again." << endl;
cout << "Your car is now going " << ClassCar.Accelerate() << "mph."
<< " Your car will Accelerate again." << endl;
cout << "Your car is now going " << ClassCar.Accelerate() << "mph."
<< " Your car will now start to brake." << endl;
cout << "Your car is now going " << ClassCar.Brake() << "mph."
<< " Your car will brake again." << endl;
cout << "Your car is now going " << ClassCar.Brake() << "mph."
<< " Your car will brake again." << endl;
cout << "Your car is now going " << ClassCar.Brake() << "mph."
<< " Your car will brake again." << endl;
cout << "Your car is now going " << ClassCar.Brake() << "mph."
<< " Your car will brake again." << endl;
cout << "Your car is now going " << ClassCar.Brake() << "mph."
<< " End of program." << endl;
return 0;
}
|