Car Class (first time with classes)

Posted by user2967605 on Stack Overflow See other posts from Stack Overflow or by user2967605
Published on 2013-11-13T15:47:45Z Indexed on 2013/11/13 15:53 UTC
Read the original article Hit count: 129

Filed under:
|
|
|

For an assignment I needed to use a class named car and have it display the make and model, and also have the speed increase by 5 when you use accelerate and decrease by 5 when you brake. My teacher helped me along the way but when I got to the end I couldn't get it to run. Could someone correct me and tell my why it's wrong?

Imp---------

#include <iostream>
#include <string>
using namespace std;







void accelerate()
    { int speed;


        speed = speed + 5;

    }



    void brake()
    {  int speed;

        speed = speed - 5;
    }

Header

#include <iostream>
#include <string>
using namespace std;

class car
{
public:
    car(int getYear, string getMake);

    void accelerate();

    void brake();





private:
    int year;
    string make;
    int speed;


};

CarClass.cpp

#include <string>
#include "CarClass.h"


using namespace std;


int main()
{
    car.(2013,"Kia")
    car.accelerate()
    car.brake()


}

© Stack Overflow or respective owner

Related posts about c++

Related posts about function