Do you think my output is ok when I run

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;



class Car

{

private:

string reportingMark;

int carNumber;

string kind;

bool loaded;

string destination;



public:

// make a defult constructor

Car();

Car(const string rm, const int nb, const string kd, const bool ld, const string dt);

// copy constructor p817

Car ( const Car &obj)

{

reportingMark = obj.reportingMark;

carNumber = obj.carNumber;

kind = obj.kind;

loaded = obj.loaded;

destination = obj.destination;

}








~Car();



void setUp (const string ,const int ,const string ,

const bool , const string);


bool operator ==(const Car &) const;

void output();



};








Car::Car ()

{

reportingMark = " ";

carNumber = 0;

kind = "other";

loaded = false;

destination = "NONE";



}




Car::Car (const string rm, const int nb, const string kd, const bool ld, const string dt)

{

setUp(rm ,nb ,kd ,ld ,dt );

}



Car::~Car()

{

cout<<"";

}





int main()

{



Car car1("SP", 34567, "box", true, "Salt Lake City");

Car car2(car1);

Car car3;


cout << "*********************************" <<endl;

cout << "Contents of car1: ";

car2.output();

cout << "*********************************" <<endl;



cout << "Contents of car2: ";

car2.output();

cout << "*********************************" <<endl;



cout << "Contents of car3: ";

car3.output();

cout << "*********************************" <<endl;



return 0;

}
/******output********************************************

********************************************************/

void Car::output()

{

cout<<"\n\nreportingMark "<<left<<setw(6)<<reportingMark<<endl;

cout<<"carNumber "<<left<<setw(6)<<carNumber<<endl;

cout<<"kind "<<left<<setw(6)<<kind<<endl;



if (loaded == true)

cout<<"loaded "<<left<<setw(6)<<"true"<<endl;

else

cout<<"loaded "<<left<<setw(6)<<"false"<<endl;



cout<<"destination "<<left<<setw(6)<<destination<<endl;

}

/******setup********************************************
107
********************************************************/

void Car::setUp(const string rm, const int nb, const string kd, const bool ld, const string dt)

{

reportingMark = rm;

carNumber = nb;

kind = kd;

loaded = ld;

destination = dt;

}

bool Car::operator ==(const Car & B) const

{

if(reportingMark ==B.reportingMark && carNumber == B.carNumber)

return true;

else

return false;



}



When you display car1, you're actually displaying car2. They're the same, so the output is the same, but it's still an error in your program.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.