May 25, 2014 at 10:12am UTC
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
using namespace std;
/******************Class Car*********************/
class Car
{
private:
string reportingMark;
int carNumber;
string kind;
bool loaded;
string destination;
public:
friend bool operator ==(const Car&, const Car&);
Car &operator =(const Car&);
//accessors
void setRep(string);
void setCarNumber(int);
void setKind(string);
void setLoaded(bool);
void setDestination(string);
//mutators
string getRep() const;
int getCarNumber() const;
string getKind() const;
bool getLoaded() const;
string getDestination() const;
//Class specific function
void output();
void setUp(string, int, string, bool, string);
//constructors
Car()
{
reportingMark = "";
carNumber = 0;
kind = "other";
loaded = false;
destination = "NONE";
}
Car(const Car& obj)
{
*this = obj;
}
Car(string mark, int num, string make, bool state, string dest)
{
setUp(mark, num, make, state, dest);
}
//Destructor
~Car()
{
}
};
void Car::setRep(string str) {reportingMark = str;}
void Car::setCarNumber(int num) {carNumber = num;}
void Car::setKind(string type) {kind = type;}
void Car::setLoaded(bool load) {loaded = load;}
void Car::setDestination(string dest) {destination = dest;}
string Car::getRep() const {return reportingMark;}
int Car::getCarNumber() const {return carNumber;}
string Car::getKind() const {return kind;}
bool Car::getLoaded() const {return loaded;}
string Car::getDestination() const {return destination;}
Car &Car::operator=(const Car & carB)
{
reportingMark = carB.reportingMark;
carNumber = carB.carNumber;
kind = carB.kind;
loaded = carB.loaded;
destination = carB.destination;
return *this;
}
void Car::output()
{
cout << "\nreportingMark\t" << getRep()
<< "\ncarNumber\t" << getCarNumber()
<< "\nkind\t" << getKind() << endl;
if(getLoaded())
cout << "loaded\t" << "true" << endl;
else
cout << "loaded\t" << "false" << endl;
cout << "destination\t" << getDestination() << endl;
}
void Car::setUp(string mark, int num, string make, bool state, string dest)
{
setRep(mark);
setCarNumber(num);
setKind(make);
setLoaded(state);
setDestination(dest);
}
#endif // CAR_H_INCLUDED
May 25, 2014 at 10:16am UTC
Please put your code in code tags, and explain what the errors are..?
May 25, 2014 at 10:32am UTC
main.cpp|14|error: 'string' does not name a type
May 25, 2014 at 10:33am UTC
I want show me the out put but does not show me can anyone please correct fr me iam confused and i do not have any idea i get a headache !!
May 25, 2014 at 10:35am UTC
At the beginning of your header file, after the include guards, add the following line:
#include <string>
Also, because it is a header file, get rid of your line saying using namespace std; , and change all your places where you have string to std::string - it means that you don't force the users of your header file to import the entire standard namespace into their code.
May 25, 2014 at 6:06pm UTC
yes iam adding string and what ever you said but did not show me output?