Class Help

D

DrNoose

Hi!

I've got a program that's almost done, but I'm getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck Class.

I'm a newbie and keep looking at the code but can't seem to see the
error. I don't understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Here is the code:

#include <iostream>
#include <string>

using namespace std;

//===============================
// Declaration of Person Class
//===============================
class Person
{
public:
Person();
Person (string theName);
Person (const Person& theObject);
string getName() const;
void setName(string newName);
Person& operator=(const Person& rtSide);
friend istream& operator >>(istream& inStream,
Person& personObject);
friend ostream& operator <<(ostream& outStream,
const Person& personObject);
private:
string name;
};


//================================
// Declaration of Vehicle Class
//================================
class Vehicle
{
public:
Vehicle();
Vehicle(string m, int cyl, Person p);
Vehicle(const Vehicle& theObject);
string getManufacturer() const;
int getCylinders() const;
Person getOwner() const;
void setManufacturer(string maker);
void setCylinders(int cylinders);
void setOwner (Person p);

void output();
// Outputs the data members of the class appropriately labeled

Vehicle& operator=(const Vehicle& rtSide);
private:
string manufacturer;
int numCylinders;
Person owner;
};


//===============================
// Declaration of Truck Class
//===============================
class Truck : public Vehicle
{
public:
Truck();
Truck(string m, int cyl, Person p, double load, int tow);
Truck(const Truck& theObject);
double getLoadCapacity() const;
int getTowingCapacity() const;
void setLoadCapacity(double newLoad);
void setTowingCapacity(int newTowing);

void output();
// Outputs the data members appropriately labeled.

Truck& operator=(const Truck& rtSide);
private:
double loadCapacity;
int towingCapacity;
};


//===================
// main function
//===================
int main()
{
//
// Variable declarations
//
string ownerName;
string manufacturerName;
int numCyl;
double load;
int towingCapacity;

cout << endl;
cout << "Testing Truck and Person classes..." << endl;
cout << endl;

cout << "First create 3 trucks..." << endl;
cout << "Truck A ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCyl;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;

Truck truckA;
Person ownerA;
cout << "Using the mutator functions to set up the owner and truck
A..." << endl;
ownerA.setName(ownerName);
truckA.setOwner(ownerA);
truckA.setManufacturer(manufacturerName);
truckA.setCylinders(numCyl);
truckA.setLoadCapacity(load);
truckA.setTowingCapacity(towingCapacity);

cout << endl;
cout << "Enter data for Truck B ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCyl;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;
cout << endl;

cout << "Using the constructor with 5 arguments to create Truck B..."
<< endl;
Person ownerB(ownerName);
Truck truckB(manufacturerName, numCyl, ownerB, load, towingCapacity);

cout << "Using the copy constructor to create Truck C as a copy of
Truck A..." << endl;
Truck truckC(truckA);

cout << "Using the accessor functions to print the truck info ..." <<
endl;
cout << endl;
cout << "Truck A ..." << endl;
cout << "Owner: " << truckA.getOwner() << endl;
cout << "Manufacturer: " << truckA.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckA.getCylinders() << endl;
cout << "Load Capacity: " << truckA.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckA.getTowingCapacity() << endl;
cout << endl;

cout << "Truck B ..." << endl;
cout << "Owner: " << truckB.getOwner() << endl;
cout << "Manufacturer: " << truckB.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckB.getCylinders() << endl;
cout << "Load Capacity: " << truckB.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckB.getTowingCapacity() << endl;
cout << endl;

cout << "Truck C ..." << endl;
cout << "Owner: " << truckC.getOwner() << endl;
cout << "Manufacturer: " << truckC.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckC.getCylinders() << endl;
cout << "Load Capacity: " << truckC.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckC.getTowingCapacity() << endl;
cout << endl;

cout << "Enter a new owner name for Truck C: ";
Person ownerC;
cin >> ownerC;
truckC.setOwner(ownerC);

cout << "Enter a new towing capacity for Truck C: ";
cin >> towingCapacity;
truckC.setTowingCapacity(towingCapacity);

cout << "Enter a new manufacturer for Truck B: ";
cin >> manufacturerName;
truckB.setManufacturer(manufacturerName);
cout << endl << endl;

cout << "Truck B after the changes..." << endl;
truckB.output();
cout << endl;

cout << "Truck C after the changes..." << endl;
truckC.output();
cout << endl;

cout << "Testing the assignment operators..." << endl;
cout << "Testing truckA = truckB" << endl;
cout << endl;

truckA = truckB;

cout << "Press any letter to see the results...";
cin >> ownerName;
cout << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();
cout << endl;

cout << "Making some changes..." << endl;
cout << "Enter a load capacity for truck A: ";
cin >> load;
truckA.setLoadCapacity(load);
cout << "Setting the owner of truck A to Bo" << endl;
truckA.setOwner(Person ("Bo"));
cout << "Changing owner of truck B to the ower of truck C" << endl;
ownerB = ownerC;
truckB.setOwner(ownerB);
cout << "Enter a new number of cylinders for truck B: ";
cin >> numCyl;
truckB.setCylinders(numCyl);
cout << endl;

cout << "After the changes ..." << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();

cout << endl << "The end..." << endl;

return 0;
}

//================================
// Vehicle Class Definitions
//================================

Vehicle::Vehicle()
{
}


Vehicle::Vehicle (string m, int cyl, Person p):manufacturer(m),
numCylinders(cyl), owner(p)
{
}


Vehicle::Vehicle(const Vehicle& theObject)
{
manufacturer = theObject.manufacturer;
numCylinders = theObject.numCylinders;
owner = theObject.owner;
}


string Vehicle::getManufacturer() const
{
return manufacturer;
}


int Vehicle::getCylinders() const
{
return numCylinders;
}


Person Vehicle::getOwner() const
{
return owner;
}


void Vehicle::setManufacturer (string m)
{
manufacturer = m;
}


void Vehicle::setCylinders(int n)
{
numCylinders = n;
}


void Vehicle::setOwner(Person p)
{
owner = p;
}

void Vehicle::eek:utput()
{
cout << "Owner: " << owner << endl;
cout << "Manufacturer: " << manufacturer << endl;
cout << "Number of Cylinders: " << numCylinders << endl;
}


Vehicle& Vehicle::eek:perator=(const Vehicle& rtSide)
{
manufacturer = rtSide.manufacturer;
numCylinders = rtSide.numCylinders;
owner = rtSide.owner;

return *this;
}


//==============================
// Truck Class Definitions

Truck::Truck()
{
}

Truck::Truck(string m, int cyl, double load, int tow, Person
p):manufacturer(m), numCylinders(cyl), LoadCapacity(load),
TowingCapacity(tow), owner(p)
{
}

Truck::Truck(const Truck& theObject)
{
loadCapacity = theObject.loadCapacity;
towingCapcity = theObject.towingCapacity;
}

double Truck::getLoadCapacity()const
{
return loadCapacity;
}

int Truck::getTowingCapacity()const
{
return towingCapacity;
}

void Truck::setLoadCapacity(double newLoad)
{
LoadCapacity=newLoad;
}

void Truck::setTowingCapacity(int newTowing)
{
TowingCapacity=newTowing;
}

void Truck::eek:utput()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

return *this;
}

//==============================
// Person Class Definitions

Person::person()
{
}

Person::person(string theName):newName(theName)
{

}

Person::person(const Person& theObject)
{
newName=theObject.newName;
}

string Person::getnewName()const
{
return newName;
}



void Person::setnewName(string theName)
{
newName=n;
}

void Person::eek:utput()
{
cout<<"Name:"<<newName<<endl;
return *this;
}
 
V

Victor Bazarov

DrNoose said:
I've got a program that's almost done, but I'm getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck
Class.

I'm a newbie and keep looking at the code but can't seem to see the
error. I don't understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Here is the code:
[...]

And which lines in it are '317' and '319'? And what compile errors do
you get?

V
 
D

DrNoose

Victor said:
DrNoose said:
I've got a program that's almost done, but I'm getting compile errors
in two lines: 317 & 319. I think the main error has to do with the
Truck Class.

I'm a newbie and keep looking at the code but can't seem to see the
error. I don't understand a lot of the fancy stuff so if you can keep
it simple for me!!!! Any help is appreciated!

Here is the code:
[...]


And which lines in it are '317' and '319'? And what compile errors do
you get?

V
The line was:

Truck::Truck(string m, int cyl, double load, int tow, Person
p):manufacturer(m), numCylinders(cyl), LoadCapacity(load),
TowingCapacity(tow), owner(p)

It should have been this I belive:

Truck::Truck(string m, int cyl, Person p, double load, int
tow):manufacturer(m), numCylinders(cyl), owner(p), LoadCapacity(load),
TowingCapacity(tow)

I had put the definitions in the wrong order from the declaration which
I have now fixed, but it just opened up a boat load more errors!!!!!!!


Now for that line that I just fixed I'm getting these errors:

(318): error C2614: 'Truck' : illegal member initialization:
'TowingCapacity' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'LoadCapacity' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization: 'owner' is
not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'numCylinders' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'manufacturer' is not a base or member


For this line:

LoadCapacity=newLoad; (line 339) I get this error:

(339): error C2065: 'LoadCapacity' : undeclared identifier

TowingCapacity=newTowing; (line 344) I get this error:

(344): error C2065: 'TowingCapacity' : undeclared identifier


There are more errors....

It all seems to do with this definition:

//==============================
// Truck Class Definitions

Truck::Truck()
{
}

Truck::Truck(string m, int cyl, Person p, double load, int
tow):manufacturer(m), numCylinders(cyl), owner(p), LoadCapacity(load),
TowingCapacity(tow)
{
}

Truck::Truck(const Truck& theObject)
{
loadCapacity = theObject.loadCapacity;
towingCapacity = theObject.towingCapacity;
}

double Truck::getLoadCapacity()const
{
return loadCapacity;
}

int Truck::getTowingCapacity()const
{
return towingCapacity;
}

void Truck::setLoadCapacity(double newLoad)
{
LoadCapacity=newLoad;
}

void Truck::setTowingCapacity(int newTowing)
{
TowingCapacity=newTowing;
}

void Truck::eek:utput()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

}

This is the declaration for the same class:

//===============================
// Declaration of Truck Class
//===============================
class Truck : public Vehicle
{
public:
Truck();
Truck(string m, int cyl, Person p, double load, int tow);
Truck(const Truck& theObject);
double getLoadCapacity() const;
int getTowingCapacity() const;
void setLoadCapacity(double newLoad);
void setTowingCapacity(int newTowing);

void output();
// Outputs the data members appropriately labeled.

Truck& operator=(const Truck& rtSide);
private:
double loadCapacity;
int towingCapacity;
};


To think when I first compiled this I only had 2 errors!!!!!
 
J

John Harrison

DrNoose said:
Hi!

I've got a program that's almost done, but I'm getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck
Class.

I'm a newbie and keep looking at the code but can't seem to see the
error. I don't understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Well I don;t what lines are 317 or 319, and you didn;t think to quote
the error messages but anyway

[snip]
void Truck::eek:utput()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

return *this;
}

This is an error, you cannot return anything from a void function.
void Person::eek:utput()
{
cout<<"Name:"<<newName<<endl;
return *this;
}

Ditto.

Overall the code is good, better than average newbie code. Very
methodical (that's good), and a good understanding of several important
concepts (I'm assuming that you didn't just copy from a book).

You have some misconceptions, you could delete every copy constructor
and assignment operator defined in your code without changing it's
meaning at all. You should look up in your book about the compiler
generated copy constructor and the compiler generated assignment
operator. You see the compiler will write these functions for you, and
for many classes the ones that the compiler writes are exactly the ones
that you want.

john
 
J

John Harrison

DrNoose said:
Victor said:
DrNoose said:
I've got a program that's almost done, but I'm getting compile errors
in two lines: 317 & 319. I think the main error has to do with the
Truck Class.

I'm a newbie and keep looking at the code but can't seem to see the
error. I don't understand a lot of the fancy stuff so if you can keep
it simple for me!!!! Any help is appreciated!

Here is the code:
[...]



And which lines in it are '317' and '319'? And what compile errors do
you get?

V

The line was:

Truck::Truck(string m, int cyl, double load, int tow, Person
p):manufacturer(m), numCylinders(cyl), LoadCapacity(load),
TowingCapacity(tow), owner(p)

It should have been this I belive:

Truck::Truck(string m, int cyl, Person p, double load, int
tow):manufacturer(m), numCylinders(cyl), owner(p), LoadCapacity(load),
TowingCapacity(tow)

I had put the definitions in the wrong order from the declaration which
I have now fixed, but it just opened up a boat load more errors!!!!!!!

That's normal.
Now for that line that I just fixed I'm getting these errors:

(318): error C2614: 'Truck' : illegal member initialization:
'TowingCapacity' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'LoadCapacity' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization: 'owner' is
not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'numCylinders' is not a base or member
(318): error C2614: 'Truck' : illegal member initialization:
'manufacturer' is not a base or member

TowingCapacity is not a base or a member, but towingCapacity is.
Similarly loadCapacity not LoadCapacity.

owner, numCylinders and manufacturer should be passed to the base
Vehicle class. Like this

Truck::Truck(string m, int cyl, Person p, double load, int tow):
Vehicle(m, cyl, p), loadCapacity(load), towingCapacity(tow)
{
}

m, cyl, and p are used to construct the base Vehicle object.
To think when I first compiled this I only had 2 errors!!!!!

john
 
R

Ron Natalie

DrNoose said:
Hi!

I've got a program that's almost done, but I'm getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck
Class

"Almost done" and he hasn't got the compile errors out. This is
indicative of the problem with todays CS education.
 
M

Mike Wahler

John Harrison said:
Overall the code is good, better than average newbie code. Very methodical
(that's good), and a good understanding of several important concepts (I'm
assuming that you didn't just copy from a book).

He almost did. :)

This began as a 'skeleton' from his instructor, as he points out in
the thread he started at acllc-c++ about this exact issue.
You have some misconceptions, you could delete every copy constructor and
assignment operator defined in your code without changing it's meaning at
all. You should look up in your book about the compiler generated copy
constructor and the compiler generated assignment operator. You see the
compiler will write these functions for you, and for many classes the ones
that the compiler writes are exactly the ones that you want.

I don't at all like the way this assignment was presented to him. He told
me it was a provided 'skeleton' after my advice to 'start small'. I think
he left all that in there because he's not sure what it means and is afraid
to 'break' it.

I tried to encourage him to start with small pieces of this and to
experiment, in the interest of true learning.

-Mike
 
J

John Harrison

Mike said:
He almost did. :)

This began as a 'skeleton' from his instructor, as he points out in
the thread he started at acllc-c++ about this exact issue.

Oh well. But does that mean the copy constructors and assignment
operators were part of the skeleton? They're not only unnecessary but
the copy constructors are badly written because they don't use
initialiser lists.
I don't at all like the way this assignment was presented to him. He told
me it was a provided 'skeleton' after my advice to 'start small'. I think
he left all that in there because he's not sure what it means and is afraid
to 'break' it.

We see a lot of newbies who in tying to write a whole program end up
with a horrible mess of bogus code, or who just say 'I don't know where
to begin'. I suppose a skeleton approach prevents that.

To make a possibly bogus analogy you could say that asking a newbie to
write a whole program is like throwing a non-swimmer in at the deep end
while using a skeleton is like not letting them out of the paddling
pool. I can see merits to both.
I tried to encourage him to start with small pieces of this and to
experiment, in the interest of true learning.

Overcoming the fear seems to be one of the essential parts of teaching
newbies.

john
 
D

DrNoose

My program (code below) compiles without errors now, but isn't producing
valid data from the data input when the program is run. The "owner"
name does not show up and some of the data from Truck C is garbage.

Can someone take a look at the code and see if you can see something
that I'm not seeing that is causing the program to not produce valid data.

Here is the latest code:

#include <iostream>
#include <string>

using namespace std;

//===============================
// Declaration of Person Class
//===============================
class Person
{
public:
Person();
Person (string theName);
Person (const Person& theObject);
string getName() const;
void setName(string newName);
Person& operator=(const Person& rtSide);
friend istream& operator>>(istream& inStream,
Person& personObject);
friend ostream& operator<<(ostream& outStream,
const Person& personObject);
private:
string name;
};


//================================
// Declaration of Vehicle Class
//================================
class Vehicle
{
public:
Vehicle();
Vehicle(string m, int cyl, Person p);
Vehicle(const Vehicle& theObject);
string getManufacturer() const;
int getCylinders() const;
Person getOwner() const;
void setManufacturer(string maker);
void setCylinders(int cylinders);
void setOwner (Person p);

void output();
// Outputs the data members of the class appropriately labeled

Vehicle& operator=(const Vehicle& rtSide);
private:
string manufacturer;
int numCylinders;
Person owner;
};


//===============================
// Declaration of Truck Class
//===============================
class Truck : public Vehicle
{
public:
Truck();
Truck(string m, int cyl, Person p, double load, int tow);
Truck(const Truck& theObject);
double getLoadCapacity() const;
int getTowingCapacity() const;
void setLoadCapacity(double newLoad);
void setTowingCapacity(int newTowing);

void output();
// Outputs the data members appropriately labeled.

Truck& operator=(const Truck& rtSide);
private:
double loadCapacity;
int towingCapacity;
};

//================================
// Vehicle Class Definitions
//================================

Vehicle::Vehicle()
{
}


Vehicle::Vehicle (string m, int cyl, Person p):manufacturer(m),
numCylinders(cyl), owner(p)
{
}


Vehicle::Vehicle(const Vehicle& theObject)
{
manufacturer = theObject.manufacturer;
numCylinders = theObject.numCylinders;
owner = theObject.owner;
}


string Vehicle::getManufacturer() const
{
return manufacturer;
}


int Vehicle::getCylinders() const
{
return numCylinders;
}


Person Vehicle::getOwner() const
{
return owner;
}


void Vehicle::setManufacturer (string m)
{
manufacturer = m;
}


void Vehicle::setCylinders(int n)
{
numCylinders = n;
}


void Vehicle::setOwner(Person p)
{
owner = p;
}

void Vehicle::eek:utput()
{
cout << "Owner: " << owner << endl;
cout << "Manufacturer: " << manufacturer << endl;
cout << "Number of Cylinders: " << numCylinders << endl;
}


Vehicle& Vehicle::eek:perator=(const Vehicle& rtSide)
{
manufacturer = rtSide.manufacturer;
numCylinders = rtSide.numCylinders;
owner = rtSide.owner;

return *this;
}


//==============================
// Truck Class Definitions
//==============================

Truck::Truck() : Vehicle(), loadCapacity(0), towingCapacity(0)
{
}

Truck::Truck(string m, int cyl, Person p, double load, int tow)
:Vehicle(m, cyl, p), loadCapacity(load), towingCapacity(tow)
{
}

Truck::Truck(const Truck& theObject)
{
loadCapacity = theObject.loadCapacity;
towingCapacity = theObject.towingCapacity;
}

double Truck::getLoadCapacity()const
{
return loadCapacity;
}

int Truck::getTowingCapacity()const
{
return towingCapacity;
}

void Truck::setLoadCapacity(double newLoad)
{
loadCapacity=newLoad;
}

void Truck::setTowingCapacity(int newTowing)
{
towingCapacity=newTowing;
}

void Truck::eek:utput()
{
cout<<"Load Capaciy:"<<loadCapacity<<endl;
cout<<"Tow Capacity:"<<towingCapacity<<endl;

}


Truck& Truck::eek:perator=(const Truck& rtSide)
{

loadCapacity=rtSide.loadCapacity;
towingCapacity=rtSide.towingCapacity;

return *this;
}


//==============================
// Person Class Definitions
//==============================

Person::person()
{
}

Person::person(string theName):name(theName)
{
}

Person::person(const Person& theObject)
{
name=theObject.name;
}

string Person::getName()const
{
return name;
}


void Person::setName(string newName)
{
name=newName;
}

Person& Person::eek:perator=(const Person& rtSide)
{
name=rtSide.name;

return *this;
}



istream& operator>>(istream& inStream,
Person& personObject)
{
return inStream;
}

ostream& operator<<(ostream& outStream,
const Person& personObject)

{
return outStream;
}

//===================
// main function
//===================
int main()
{
//
// Variable declarations
//
string ownerName;
string manufacturerName;
int numCylinders;
double load;
int towingCapacity;



cout << endl;
cout << "Testing Truck and Person classes..." << endl;
cout << endl;

cout << "First create 3 trucks..." << endl;
cout << "Truck A ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCylinders;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;

Truck truckA;
Person ownerA;
cout << "Using the mutator functions to set up the owner and truck
A..." << endl;
ownerA.setName(ownerName);
truckA.setOwner(ownerA);
truckA.setManufacturer(manufacturerName);
truckA.setCylinders(numCylinders);
truckA.setLoadCapacity(load);
truckA.setTowingCapacity(towingCapacity);

cout << endl;
cout << "Enter data for Truck B ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCylinders;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;
cout << endl;

cout << "Using the constructor with 5 arguments to create Truck B..."
<< endl;
Person ownerB(ownerName);
Truck truckB(manufacturerName, numCylinders, ownerB, load,
towingCapacity);

cout << "Using the copy constructor to create Truck C as a copy of
Truck A..." << endl;
Truck truckC(truckA);

cout << "Using the accessor functions to print the truck info ..." <<
endl;
cout << endl;
cout << "Truck A ..." << endl;
cout << "Owner: " << truckA.getOwner() << endl;
cout << "Manufacturer: " << truckA.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckA.getCylinders() << endl;
cout << "Load Capacity: " << truckA.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckA.getTowingCapacity() << endl;
cout << endl;

cout << "Truck B ..." << endl;
cout << "Owner: " << truckB.getOwner() << endl;
cout << "Manufacturer: " << truckB.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckB.getCylinders() << endl;
cout << "Load Capacity: " << truckB.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckB.getTowingCapacity() << endl;
cout << endl;

cout << "Truck C ..." << endl;
cout << "Owner: " << truckC.getOwner() << endl;
cout << "Manufacturer: " << truckC.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckC.getCylinders() << endl;
cout << "Load Capacity: " << truckC.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckC.getTowingCapacity() << endl;
cout << endl;

cout << "Enter a new owner name for Truck C: ";
Person ownerC;
cin >> ownerC;
truckC.setOwner(ownerC);

cout << "Enter a new towing capacity for Truck C: ";
cin >> towingCapacity;
truckC.setTowingCapacity(towingCapacity);

cout << "Enter a new manufacturer for Truck B: ";
cin >> manufacturerName;
truckB.setManufacturer(manufacturerName);
cout << endl << endl;

cout << "Truck B after the changes..." << endl;
truckB.output();
cout << endl;

cout << "Truck C after the changes..." << endl;
truckC.output();
cout << endl;

cout << "Testing the assignment operators..." << endl;
cout << "Testing truckA = truckB" << endl;
cout << endl;

truckA = truckB;

cout << "Press any letter to see the results...";
cin >> ownerName;
cout << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();
cout << endl;

cout << "Making some changes..." << endl;
cout << "Enter a load capacity for truck A: ";
cin >> load;
truckA.setLoadCapacity(load);
cout << "Setting the owner of truck A to Bo" << endl;
truckA.setOwner(Person ("Bo"));
cout << "Changing owner of truck B to the ower of truck C" << endl;
ownerB = ownerC;
truckB.setOwner(ownerB);
cout << "Enter a new number of cylinders for truck B: ";
cin >> numCylinders;
truckB.setCylinders(numCylinders);
cout << endl;

cout << "After the changes ..." << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();

cout << endl << "The end..." << endl;

return 0;
}

Thanks!
 
J

John Harrison

DrNoose said:
My program (code below) compiles without errors now, but isn't producing
valid data from the data input when the program is run. The "owner"
name does not show up and some of the data from Truck C is garbage.

Can someone take a look at the code and see if you can see something
that I'm not seeing that is causing the program to not produce valid data.
istream& operator>>(istream& inStream,
Person& personObject)
{
return inStream;
}

Well this is wrong, this function is supposed to read personObject from
inStream, instead it does nothing!!!
ostream& operator<<(ostream& outStream,
const Person& personObject)

{
return outStream;
}

And this function is supposed to write a personObject to outStream, but
again it does nothing!!!

I didn't look at all the code but fixing these would be a start.

Do you know how to use a debugger? If not you should learn, it would
pick up all your errors very quickly.

john
 
D

DrNoose

John said:
Well this is wrong, this function is supposed to read personObject from
inStream, instead it does nothing!!!



And this function is supposed to write a personObject to outStream, but
again it does nothing!!!

I didn't look at all the code but fixing these would be a start.

Do you know how to use a debugger? If not you should learn, it would
pick up all your errors very quickly.

john
Hi!

I'm using Visual Studio 7.1. I haven't usued it before and at this
point, only know the basics of how to make a new project, build it and
run it. If it doesn't compile, I look at the lines where there is a
problem and try fixing those until it compiles correctly.

I'll do some more reading on these areas of the ostream/instreams.

Thanks!
 
J

John Harrison

Hi!

I'm using Visual Studio 7.1. I haven't usued it before and at this
point, only know the basics of how to make a new project, build it and
run it. If it doesn't compile, I look at the lines where there is a
problem and try fixing those until it compiles correctly.

I'll do some more reading on these areas of the ostream/instreams.

Thanks!

Visual Studio has a excellent debugger. You should defintely learn how
to use it.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top