i need to write a class for driver.cpp file
// Chapter 13, Programming Challenge 3 Driver
//
#include "Car.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Loop counter
int count;
string myMake="Porsche";
// Create a car object.
Car porsche(2006, myMake);
// Display the car that was created
cout << "Car Year: " << porsche.getYearModel();
cout << " Make: " << porsche.getMake();
cout << " Speed: " << porsche.getSpeed() << endl << endl;
// Display the current speed.
cout << "Current speed: "
<< porsche.getSpeed()
<< endl;
// Accelerate five times.
for (count = 0; count < 5; count++)
{
// Accelerate and display the speed.
cout << "Accelerating...\n";
porsche.accelerate();
cout << "Current speed: "
<< porsche.getSpeed()
<< endl;
}
// Brake five times.
for (count = 0; count < 5; count++)
{
// Brake and display the speed.
cout << "Braking...\n";
porsche.brake();
cout << "Current speed: "
<< porsche.getSpeed()
<< endl;
}
}
here is the class that i wrote
#ifndef CAR_H
#define CAR_H
#include<string.h>
class Car
{
private:
int YearModel;
std::string Make;
int Speed;
public:
Car::Car(int year,std::string mk,int s=0)
{
YearModel=year;
Make=mk;
Speed=s;
}
int getYearModel() const
{
return YearModel;
}
std::string getMake() const
{
return Make;
}
int getSpeed()
{
return Speed;
}
int accelerate()
{
getSpeed();
return Speed=Speed+5;
}
int brake()
{
getSpeed();
return Speed=Speed-5;
}
};
#endif
i am using visual studio 2008
while linking it shows me this :
LINK : C:\Users\Ankit Arya\Documents\Visual Studio 2008\Projects\car\Debug\car.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
thought it then compiles and runs perfectly ryt after that....
i need to submit this HW on some WEB-CAT tool on which after submitting it gives me an error that it cannot compile my class...
The following specific error(s) were discovered while compiling reference tests against your submission:
Car.h:51:7: warning: no newline at end of file
<<reference tests>>:13: error: `string' undeclared (first use this function)
can anybody has any idea what is wrong with my class coz it runs f9 on visual studio.