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

In referring to this problem: /computer-science-answers-5-651599-cpi0.aspx I\'m

ID: 3615075 • Letter: I

Question

In referring to this problem: /computer-science-answers-5-651599-cpi0.aspx
I'm trying to split that program into 3 files: Car specification (Car.h) file Car implementation file (Car.cpp) Car client code file (UseCar.cpp)
However, when I try, I fail miserably. I get around 25 errorsand I dont know what I'm doing wrong. ________________________________________________________________________ Heres what I have:
Contents of Car.h: #ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
}; #endif
__________________________ Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;

//function definition for accelerate void Car::accelerate() { speed +=5; }
//function definition for brake void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for getYearModel int Car::GetYear() { return yearModel; }
______________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }




I'm trying to split that program into 3 files: Car specification (Car.h) file Car implementation file (Car.cpp) Car client code file (UseCar.cpp)
However, when I try, I fail miserably. I get around 25 errorsand I dont know what I'm doing wrong. ________________________________________________________________________ Heres what I have:
Contents of Car.h: #ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
}; #endif
__________________________ Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;

//function definition for accelerate void Car::accelerate() { speed +=5; }
//function definition for brake void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for getYearModel int Car::GetYear() { return yearModel; }
______________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }



Car specification (Car.h) file Car implementation file (Car.cpp) Car client code file (UseCar.cpp)
However, when I try, I fail miserably. I get around 25 errorsand I dont know what I'm doing wrong. ________________________________________________________________________ Heres what I have:
Contents of Car.h: #ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
}; #endif
__________________________ Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;

//function definition for accelerate void Car::accelerate() { speed +=5; }
//function definition for brake void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for getYearModel int Car::GetYear() { return yearModel; }
______________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }



#ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
}; #endif
__________________________ Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;

//function definition for accelerate void Car::accelerate() { speed +=5; }
//function definition for brake void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for getYearModel int Car::GetYear() { return yearModel; }
______________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }


#include <string> #include "Car.h" #include <iostream> using namespace std;

//function definition for accelerate void Car::accelerate() { speed +=5; }
//function definition for brake void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for getYearModel int Car::GetYear() { return yearModel; }
______________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }


#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; }



Explanation / Answer


Contents of Car.h
#ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car::Car(string, int);
void accelerate(); void brake(); int GetYear(); string GetMake(); int GetSpeed();
}; #endif
_______________________
Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;
//constructor Car::Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
//function definition for accelerate //adds 5 to speed each time function is called void Car::accelerate() { speed +=5; }
//function definition for brake //subtracts 5 from speed each time function is called void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for GetYear int Car::GetYear() { return yearModel; }
___________________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; } #ifndef CAR_H #define CAR_H #include <string> using namespace std;
class Car { private: int yearModel; string make; int speed; public: Car::Car(string, int);
void accelerate(); void brake(); int GetYear(); string GetMake(); int GetSpeed();
}; #endif
_______________________
Contents of Car.cpp
#include <string> #include "Car.h" #include <iostream> using namespace std;
//constructor Car::Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
//function definition for accelerate //adds 5 to speed each time function is called void Car::accelerate() { speed +=5; }
//function definition for brake //subtracts 5 from speed each time function is called void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for GetYear int Car::GetYear() { return yearModel; }
___________________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; } #include <string> #include "Car.h" #include <iostream> using namespace std;
//constructor Car::Car(string carMake, int year) { speed = 0; yearModel=year; make=carMake; }
//function definition for accelerate //adds 5 to speed each time function is called void Car::accelerate() { speed +=5; }
//function definition for brake //subtracts 5 from speed each time function is called void Car::brake() { speed -=5; }
//function definition for GetSpeed int Car::GetSpeed() { return speed; }

//function defintion for GetMake string Car::GetMake() { return make; }
//function definition for GetYear int Car::GetYear() { return yearModel; }
___________________________________
Contents of UseCar.cpp
#include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
return 0; } #include <iostream> #include <string> #include "Car.h" using namespace std;
int main() { Car car1("Infiniti",2005); cout << car1.GetYear() << " " <<car1.GetMake(); cout << " Initial speed: " << car1.GetSpeed()<< endl;
for(int count=0;count<5;count++) { car1.accelerate(); cout << "After " << count + 1 << "accelerations, current speed is: " << car1.GetSpeed() <<endl; } for(int counter=0;counter<5;counter++) { car1.brake(); cout << "After " << counter + 1 << " brakes,current speed is: " <<car1.GetSpeed() << endl; }
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