peter
02-05-2002, 11:00 AM
hello and thanks for your help - see prog below
even though thr program below compile i think i have my print object and
my main needs to some changes cause it will not link
can you please help
thanks P
define dogyrs = 7 ; // mult a # by 7 to actual dog years
#include <iostream>
using namespace std;
int dage,human_yrs, amt_pups;
class Dog //base
{
public:
Dog(const string & dgname , const string & dgtype);
Dog(const Dog & rhs);
Dog();
~Dog();
Dog & operator= (const Dog &rhs);
Dog & operator+= (const Dog &rhs);
int Dogage(int &human_yrs);
//int Set_Dogage();
bool have_litter( int & amt_pups);
void Dog_bark();
void DogPrint();
private:
string name_;
string type_;
int age_;
bool pups_;
};
#include "hdog.h"
#include <iostream>
void main()
{
Dog obj1("rex","lab");
int theage;
cout << " enter dog's age" << endl;
cin >> theage;
obj1.Dogage(theage);
obj1.DogPrint() ;
}
#include "hdog.h"
#include <iostream>
#include <string>
using namespace std;
Dog::Dog(const string & dgname , const string & dgtype )
:name_(dgname), type_(dgtype), pups_(false)
{
age_ = dage;
}
Dog::Dog(const Dog & rhs)
:name_(rhs.name_), type_(rhs.type_), age_(rhs.age_), pups_(rhs.pups_)
{
}
Dog::Dog()
:name_("default name"), type_("mongrel"), age_(0), pups_(false)
{
}
Dog & Dog::operator = (const Dog &rhs)
{
// do check no same name
name_ = rhs.name_;
type_ = rhs.type_;
return * this;
}
Dog & Dog::operator+= (const Dog & rhs)
{
return * this;
}
int Dog::Dogage( int &human_yrs)
{
dage = human_yrs * 7;//dogyrs;
age_ = dage;
return age_;
}
bool Dog::have_litter( int & amt_pups)
{
int puppies;
puppies = amt_pups;
if (!pups_ )
{
cout << " I already have " << puppies << "lil ones" << endl;
cout << "cannot have anymore" << endl;
pups_ = true;
return true;
}
else if (pups_ && puppies > 0)
{
puppies = amt_pups;
cout << " I now have " << puppies<<" lil ones" << endl;
pups_ = true;
return true;
}
else
{
cout << " i have no puppies " << endl;
return false;
}
}
void Dog::Dog_bark()
{
cout << "woof ! woof !" << endl;
}
void Dog::DogPrint()
{
cout <<" my name is "<< name_ << " i'm a "<<type_ << " i am "<< "\n"
<< Dogage(human_yrs) <<" years old "<< have_litter(amt_pups) << endl;
Dog_bark() ;
}
even though thr program below compile i think i have my print object and
my main needs to some changes cause it will not link
can you please help
thanks P
define dogyrs = 7 ; // mult a # by 7 to actual dog years
#include <iostream>
using namespace std;
int dage,human_yrs, amt_pups;
class Dog //base
{
public:
Dog(const string & dgname , const string & dgtype);
Dog(const Dog & rhs);
Dog();
~Dog();
Dog & operator= (const Dog &rhs);
Dog & operator+= (const Dog &rhs);
int Dogage(int &human_yrs);
//int Set_Dogage();
bool have_litter( int & amt_pups);
void Dog_bark();
void DogPrint();
private:
string name_;
string type_;
int age_;
bool pups_;
};
#include "hdog.h"
#include <iostream>
void main()
{
Dog obj1("rex","lab");
int theage;
cout << " enter dog's age" << endl;
cin >> theage;
obj1.Dogage(theage);
obj1.DogPrint() ;
}
#include "hdog.h"
#include <iostream>
#include <string>
using namespace std;
Dog::Dog(const string & dgname , const string & dgtype )
:name_(dgname), type_(dgtype), pups_(false)
{
age_ = dage;
}
Dog::Dog(const Dog & rhs)
:name_(rhs.name_), type_(rhs.type_), age_(rhs.age_), pups_(rhs.pups_)
{
}
Dog::Dog()
:name_("default name"), type_("mongrel"), age_(0), pups_(false)
{
}
Dog & Dog::operator = (const Dog &rhs)
{
// do check no same name
name_ = rhs.name_;
type_ = rhs.type_;
return * this;
}
Dog & Dog::operator+= (const Dog & rhs)
{
return * this;
}
int Dog::Dogage( int &human_yrs)
{
dage = human_yrs * 7;//dogyrs;
age_ = dage;
return age_;
}
bool Dog::have_litter( int & amt_pups)
{
int puppies;
puppies = amt_pups;
if (!pups_ )
{
cout << " I already have " << puppies << "lil ones" << endl;
cout << "cannot have anymore" << endl;
pups_ = true;
return true;
}
else if (pups_ && puppies > 0)
{
puppies = amt_pups;
cout << " I now have " << puppies<<" lil ones" << endl;
pups_ = true;
return true;
}
else
{
cout << " i have no puppies " << endl;
return false;
}
}
void Dog::Dog_bark()
{
cout << "woof ! woof !" << endl;
}
void Dog::DogPrint()
{
cout <<" my name is "<< name_ << " i'm a "<<type_ << " i am "<< "\n"
<< Dogage(human_yrs) <<" years old "<< have_litter(amt_pups) << endl;
Dog_bark() ;
}