Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So far I have this: #include <iostream> using namespace std; class Car{ private:

ID: 656164 • Letter: S

Question

So far I have this:

#include <iostream>
using namespace std;


class Car{
private:
   int year;
std::string make;
int speed;

public:
Car(int, string);
int getYear();
std::string getMake();
int getSpeed();
};
Car::Car(int inputYear, std::string inputMake)
{
year = inputYear;
make = inputMake;
speed = 0;
}

int Car::getYear()
{
return year;
}

int main ()
{

   system ("pause");
   return 0;
}

Car Class (simple C++ Class) with comments on what it does.

Please implement a class named Car in C++ that has the following member variables:
1. year. An int that holds the car

Explanation / Answer

#include <iostream>
using namespace std;


class Car{
private:
int year;
std::string make;
int speed;

public:
Car(int, string);
int getYear();
std::string getMake();
int getSpeed();
void accelerate();
void break();
};
Car::Car(int inputYear, std::string inputMake)
{
year = inputYear;
make = inputMake;
speed = 0;
}

int Car::getYear()
{
return year;
}

String Car::getMake()
{
return make;
}

int Car::getSpeed()
{
return speed;
}

void Car::accelerate()
{
   speed = speed + 5;
}

void Car::break()
{
   speed = speed - 5;
}


int main ()
{
   int y,s;
   String m;

   Car o(2007,"maruti");
   y=o.getYear();
   s=o.getSpeed();
   m=o.getMake();

   cout<<"Year"<<y;
   cout<<"Make"<<m;
   cout<<"Speed"<<s;

   s=o.accelerate();
   cout<<"Speed"<<s;

   s=o.break();
   cout<<"Speed"<<s;


system ("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote