473,569 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Help

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(in t 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 getTowingCapaci ty() const;
void setLoadCapacity (double newLoad);
void setTowingCapaci ty(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 manufacturerNam e;
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 >> manufacturerNam e;
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.setManuf acturer(manufac turerName);
truckA.setCylin ders(numCyl);
truckA.setLoadC apacity(load);
truckA.setTowin gCapacity(towin gCapacity);

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 >> manufacturerNam e;
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(ownerNam e);
Truck truckB(manufact urerName, 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 << "Manufactur er: " << truckA.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckA.getCylin ders() << endl;
cout << "Load Capacity: " << truckA.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckA.getTowin gCapacity() << endl;
cout << endl;

cout << "Truck B ..." << endl;
cout << "Owner: " << truckB.getOwner () << endl;
cout << "Manufactur er: " << truckB.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckB.getCylin ders() << endl;
cout << "Load Capacity: " << truckB.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckB.getTowin gCapacity() << endl;
cout << endl;

cout << "Truck C ..." << endl;
cout << "Owner: " << truckC.getOwner () << endl;
cout << "Manufactur er: " << truckC.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckC.getCylin ders() << endl;
cout << "Load Capacity: " << truckC.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckC.getTowin gCapacity() << 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.setTowin gCapacity(towin gCapacity);

cout << "Enter a new manufacturer for Truck B: ";
cin >> manufacturerNam e;
truckB.setManuf acturer(manufac turerName);
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.setLoadC apacity(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.setCylin ders(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::Vehicl e()
{
}
Vehicle::Vehicl e (string m, int cyl, Person p):manufacturer (m),
numCylinders(cy l), owner(p)
{
}
Vehicle::Vehicl e(const Vehicle& theObject)
{
manufacturer = theObject.manuf acturer;
numCylinders = theObject.numCy linders;
owner = theObject.owner ;
}
string Vehicle::getMan ufacturer() const
{
return manufacturer;
}
int Vehicle::getCyl inders() const
{
return numCylinders;
}
Person Vehicle::getOwn er() const
{
return owner;
}
void Vehicle::setMan ufacturer (string m)
{
manufacturer = m;
}
void Vehicle::setCyl inders(int n)
{
numCylinders = n;
}
void Vehicle::setOwn er(Person p)
{
owner = p;
}

void Vehicle::output ()
{
cout << "Owner: " << owner << endl;
cout << "Manufactur er: " << manufacturer << endl;
cout << "Number of Cylinders: " << numCylinders << endl;
}
Vehicle& Vehicle::operat or=(const Vehicle& rtSide)
{
manufacturer = rtSide.manufact urer;
numCylinders = rtSide.numCylin ders;
owner = rtSide.owner;

return *this;
}
//=============== ===============
// Truck Class Definitions

Truck::Truck()
{
}

Truck::Truck(st ring m, int cyl, double load, int tow, Person
p):manufacturer (m), numCylinders(cy l), LoadCapacity(lo ad),
TowingCapacity( tow), owner(p)
{
}

Truck::Truck(co nst Truck& theObject)
{
loadCapacity = theObject.loadC apacity;
towingCapcity = theObject.towin gCapacity;
}

double Truck::getLoadC apacity()const
{
return loadCapacity;
}

int Truck::getTowin gCapacity()cons t
{
return towingCapacity;
}

void Truck::setLoadC apacity(double newLoad)
{
LoadCapacity=ne wLoad;
}

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

void Truck::output()
{
cout<<"Load Capaciy:"<<Load Capacity<<endl;
cout<<"Tow Capacity:"<<Tow ingCapacity<<en dl;

return *this;
}

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

Person::Person( )
{
}

Person::Person( string theName):newNam e(theName)
{

}

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

string Person::getnewN ame()const
{
return newName;
}

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

void Person::output( )
{
cout<<"Name:"<< newName<<endl;
return *this;
}
Nov 22 '05 #1
11 2384
DrNoose wrote:
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
Nov 22 '05 #2
Victor Bazarov wrote:
DrNoose wrote:
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(st ring m, int cyl, double load, int tow, Person
p):manufacturer (m), numCylinders(cy l), LoadCapacity(lo ad),
TowingCapacity( tow), owner(p)

It should have been this I belive:

Truck::Truck(st ring m, int cyl, Person p, double load, int
tow):manufactur er(m), numCylinders(cy l), owner(p), LoadCapacity(lo ad),
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=ne wLoad; (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(st ring m, int cyl, Person p, double load, int
tow):manufactur er(m), numCylinders(cy l), owner(p), LoadCapacity(lo ad),
TowingCapacity( tow)
{
}

Truck::Truck(co nst Truck& theObject)
{
loadCapacity = theObject.loadC apacity;
towingCapacity = theObject.towin gCapacity;
}

double Truck::getLoadC apacity()const
{
return loadCapacity;
}

int Truck::getTowin gCapacity()cons t
{
return towingCapacity;
}

void Truck::setLoadC apacity(double newLoad)
{
LoadCapacity=ne wLoad;
}

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

void Truck::output()
{
cout<<"Load Capaciy:"<<Load Capacity<<endl;
cout<<"Tow Capacity:"<<Tow ingCapacity<<en dl;

}

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 getTowingCapaci ty() const;
void setLoadCapacity (double newLoad);
void setTowingCapaci ty(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!!!!!

Nov 22 '05 #3
DrNoose wrote:
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::output()
{
cout<<"Load Capaciy:"<<Load Capacity<<endl;
cout<<"Tow Capacity:"<<Tow ingCapacity<<en dl;

return *this;
}
This is an error, you cannot return anything from a void function.

void Person::output( )
{
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
Nov 22 '05 #4
DrNoose wrote:
Victor Bazarov wrote:
DrNoose wrote:
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(st ring m, int cyl, double load, int tow, Person
p):manufacturer (m), numCylinders(cy l), LoadCapacity(lo ad),
TowingCapacity( tow), owner(p)

It should have been this I belive:

Truck::Truck(st ring m, int cyl, Person p, double load, int
tow):manufactur er(m), numCylinders(cy l), owner(p), LoadCapacity(lo ad),
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(st ring m, int cyl, Person p, double load, int tow):
Vehicle(m, cyl, p), loadCapacity(lo ad), 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
Nov 22 '05 #5
DrNoose wrote:
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.
Nov 22 '05 #6

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:RC******** ********@newsfe 1-win.ntli.net...

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
Nov 22 '05 #7
Mike Wahler wrote:
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:RC******** ********@newsfe 1-win.ntli.net...
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.


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.
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.


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.

-Mike


john
Nov 22 '05 #8
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>>(istr eam& inStream,
Person& personObject);
friend ostream& operator<<(ostr eam& 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(in t 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 getTowingCapaci ty() const;
void setLoadCapacity (double newLoad);
void setTowingCapaci ty(int newTowing);

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

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

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

Vehicle::Vehicl e()
{
}
Vehicle::Vehicl e (string m, int cyl, Person p):manufacturer (m),
numCylinders(cy l), owner(p)
{
}
Vehicle::Vehicl e(const Vehicle& theObject)
{
manufacturer = theObject.manuf acturer;
numCylinders = theObject.numCy linders;
owner = theObject.owner ;
}
string Vehicle::getMan ufacturer() const
{
return manufacturer;
}
int Vehicle::getCyl inders() const
{
return numCylinders;
}
Person Vehicle::getOwn er() const
{
return owner;
}
void Vehicle::setMan ufacturer (string m)
{
manufacturer = m;
}
void Vehicle::setCyl inders(int n)
{
numCylinders = n;
}
void Vehicle::setOwn er(Person p)
{
owner = p;
}

void Vehicle::output ()
{
cout << "Owner: " << owner << endl;
cout << "Manufactur er: " << manufacturer << endl;
cout << "Number of Cylinders: " << numCylinders << endl;
}
Vehicle& Vehicle::operat or=(const Vehicle& rtSide)
{
manufacturer = rtSide.manufact urer;
numCylinders = rtSide.numCylin ders;
owner = rtSide.owner;

return *this;
}
//=============== ===============
// Truck Class Definitions
//=============== ===============

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

Truck::Truck(st ring m, int cyl, Person p, double load, int tow)
:Vehicle(m, cyl, p), loadCapacity(lo ad), towingCapacity( tow)
{
}

Truck::Truck(co nst Truck& theObject)
{
loadCapacity = theObject.loadC apacity;
towingCapacity = theObject.towin gCapacity;
}

double Truck::getLoadC apacity()const
{
return loadCapacity;
}

int Truck::getTowin gCapacity()cons t
{
return towingCapacity;
}

void Truck::setLoadC apacity(double newLoad)
{
loadCapacity=ne wLoad;
}

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

void Truck::output()
{
cout<<"Load Capaciy:"<<load Capacity<<endl;
cout<<"Tow Capacity:"<<tow ingCapacity<<en dl;

}
Truck& Truck::operator =(const Truck& rtSide)
{

loadCapacity=rt Side.loadCapaci ty;
towingCapacity= rtSide.towingCa pacity;

return *this;
}
//=============== ===============
// Person Class Definitions
//=============== ===============

Person::Person( )
{
}

Person::Person( string theName):name(t heName)
{
}

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

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

Person& Person::operato r=(const Person& rtSide)
{
name=rtSide.nam e;

return *this;
}

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

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

{
return outStream;
}

//=============== ====
// main function
//=============== ====
int main()
{
//
// Variable declarations
//
string ownerName;
string manufacturerNam e;
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 >> manufacturerNam e;
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.setManuf acturer(manufac turerName);
truckA.setCylin ders(numCylinde rs);
truckA.setLoadC apacity(load);
truckA.setTowin gCapacity(towin gCapacity);

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 >> manufacturerNam e;
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(ownerNam e);
Truck truckB(manufact urerName, 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 << "Manufactur er: " << truckA.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckA.getCylin ders() << endl;
cout << "Load Capacity: " << truckA.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckA.getTowin gCapacity() << endl;
cout << endl;

cout << "Truck B ..." << endl;
cout << "Owner: " << truckB.getOwner () << endl;
cout << "Manufactur er: " << truckB.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckB.getCylin ders() << endl;
cout << "Load Capacity: " << truckB.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckB.getTowin gCapacity() << endl;
cout << endl;

cout << "Truck C ..." << endl;
cout << "Owner: " << truckC.getOwner () << endl;
cout << "Manufactur er: " << truckC.getManuf acturer() << endl;
cout << "Number of Cylinders: " << truckC.getCylin ders() << endl;
cout << "Load Capacity: " << truckC.getLoadC apacity() << endl;
cout << "Towing Capacity: " << truckC.getTowin gCapacity() << 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.setTowin gCapacity(towin gCapacity);

cout << "Enter a new manufacturer for Truck B: ";
cin >> manufacturerNam e;
truckB.setManuf acturer(manufac turerName);
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.setLoadC apacity(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.setCylin ders(numCylinde rs);
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!
Nov 26 '05 #9
DrNoose wrote:
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>>(istr eam& inStream,
Person& personObject)
{
return inStream;
}
Well this is wrong, this function is supposed to read personObject from
inStream, instead it does nothing!!!

ostream& operator<<(ostr eam& 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
Nov 26 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1625
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if this is elsewhere in the newsgroup & please reply with links to threads or something? (I dont know what to look for :( ) (Terms are prob. all wrong...
1
297
by: Naren | last post by:
Victor Bazarov <v.Abazarov@comAcast.net> wrote: >Naren wrote: >> MyServer class conatins a list of Mysock class. >> >> class Myserver >> { >> private: >> list<Mysock> L1; >> }; >>
5
2129
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator=' in '*this = CTest::operator+(CTest&)((+t2))' test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&) make: *** Error 1
4
1997
by: Mike | last post by:
Please help this is driving me nuts. I have 2 forms, 1 user class and I am trying to implement a singleton class. Form 1 should create a user object and populate some properties in user. Form2 should then have access to those user properties. I am not getting the property value from user that was set in form1. Sorry for posting so much...
5
6895
by: Jeff Bunting | last post by:
I'm trying to serialize a class I have and have been getting: An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll There was an error reflecting type MyClass. I noticed in the help for the SerializableAttribute Class the following: "Indicates that a class can be serialized. This class cannot be...
1
1423
by: Joe Carner via .NET 247 | last post by:
First time posting, thanks in advance for any help you can give me. Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i created. But, I can't get the friend class to work. For example (this is not actually my code): template <typename Key, typename Value> class...
16
1994
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just learning and really need some help bad. Public Shared Function GetAll() As ArrayList Dim dsCustomer As New DataSet() Dim sqlQuery As String = "SELECT...
11
2854
by: Darren.Ratcliffe | last post by:
Hi guys Posted what was probably a rather confusing post about this the other day, so I am going to have another go and see if I can make more sense. This sis purely a I've got a base class called animal, and from within animal you can access lots more classes such as feline, canine, reptile and amphibian.....
4
1809
by: Pupeno | last post by:
Hello, I want to jump over a method in the class hierarchy, that is: If I have class A(object), clas B(A), class C(B) and in C, I want a method to do exactly what A does but not what B does in its reimplementation, would it be correct to do: super(A, super(B, self)).method() in C ? Thank you. -- Pupeno <pupeno@pupeno.com(http://pupeno.com)
6
4016
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new types of objects (classes) can only be defined in Class modules.
0
7931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7682
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3663
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3655
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
954
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.