hi i am trying to "divide" the following code...so that it has a header file and the main file. i tried to seperate the it but when i do it says "nothing to do at all" or "nothing happened at all"(one of them)
ere is the original code. can you pls seperate it into one that a "dog.h" and "dog.cpp"
p.s. i'll appreciate it if you could do this as fast as you can cuz i have a test that i'm supposed to do the same to a similar code.

#include <iostream>
using namespace std;
class Dog {
private:
    int age;
    int weight;
public:
    Dog();牋牋牋//Constructor
    ~Dog();牋牋//Destructor
    void setAge(int age);
    int getAge();
    void setWeight(int weight);
    int getWeight();
    void speak();
};
Dog::Dog()
{
    age = 0;
    weight = 0;
    cout << "Dog Constructor Called" << endl;
}
Dog::~Dog()
{
    cout << "Dog Destructor Called" << endl;
}
void Dog::setAge(int age)
{
    this->age = age;
}
int Dog::getAge()
{
    return age;
}
void Dog::setWeight(int weight)
{
    this->weight = weight;
}
int Dog::getWeight()
{
    return weight;
}
void Dog::speak()
{
cout << "BARK!!" << endl;
}
int main()
{
    Dog fido;
    Dog rover;
    cout << "Rover is " << rover.getAge() << " years old." << endl;
    cout << "He weighs " << rover.getWeight() << " lbs." << endl;
    cout << endl;
    cout << "Updating Rover's Age and Weight" << endl;
    rover.setAge(1);
    rover.setWeight(10);
    cout << "Rover is " << rover.getAge() << " years old." << endl;
    cout << "He weighs " << rover.getWeight() << " lbs." << endl;
    cout << endl;
    cout << "Fido is " << fido.getAge() << " years old." << endl;
    cout << "He weighs " << fido.getWeight() << " lbs." << endl;
    cout << "Setting Fido to be the same as Rover" << endl;
    fido = rover;
    cout << "Fido is " << fido.getAge() << " years old." << endl;
    cout << "He weighs " << fido.getWeight() << " lbs." << endl;
    rover.speak();
    fido.speak();
    return 0;
}

Quickie:

class Dog {
private:
    int age;
    int weight;
public:
    Dog();牋牋牋//Constructor
    ~Dog();牋牋//Destructor
    void setAge(int age);
    int getAge();
    void setWeight(int weight);
    int getWeight();
    void speak();
};
#include <iostream>
using namespace std;
Dog::Dog()
{
    age = 0;
    weight = 0;
    cout << "Dog Constructor Called" << endl;
}
Dog::~Dog()
{
    cout << "Dog Destructor Called" << endl;
}
void Dog::setAge(int age)
{
    this->age = age;
}
int Dog::getAge()
{
    return age;
}
void Dog::setWeight(int weight)
{
    this->weight = weight;
}
int Dog::getWeight()
{
    return weight;
}
void Dog::speak()
{
cout << "BARK!!" << endl;
}
int main()
{
    Dog fido;
    Dog rover;
    cout << "Rover is " << rover.getAge() << " years old." << endl;
    cout << "He weighs " << rover.getWeight() << " lbs." << endl;
    cout << endl;
    cout << "Updating Rover's Age and Weight" << endl;
    rover.setAge(1);
    rover.setWeight(10);
    cout << "Rover is " << rover.getAge() << " years old." << endl;
    cout << "He weighs " << rover.getWeight() << " lbs." << endl;
    cout << endl;
    cout << "Fido is " << fido.getAge() << " years old." << endl;
    cout << "He weighs " << fido.getWeight() << " lbs." << endl;
    cout << "Setting Fido to be the same as Rover" << endl;
    fido = rover;
    cout << "Fido is " << fido.getAge() << " years old." << endl;
    cout << "He weighs " << fido.getWeight() << " lbs." << endl;
    rover.speak();
    fido.speak();
    return 0;
}

It is, of course, missing an #include in the cpp, but I'm being understandably lazy.

thanks! wierd hing is i did the exact same thing earlier but it gave me that error thingy. ok small thing the code u wrote works (even with the #include dog.h but it just gives me a black screen and "press any key to continue". any ideas?
thanks!!!

i always use system("pause"); to hold the black srceen open. but it has no effect. u can reply to this if you have any other suggestion but i wont be able to answer for another hour or so...but pls any help will be greatly appreciated!

i always use system("pause"); to hold the black srceen open. but it has no effect. u can reply to this if you have any other suggestion but i wont be able to answer for another hour or so...but pls any help will be greatly appreciated!

Why use system("pause"); to call the operating system and execute an OS command when a simple cin will stop execution until you press ENTER? Isn't cin actually part of the language itself?

Why use system("pause"); to call the operating system and execute an OS command when a simple cin will stop execution until you press ENTER? Isn't cin actually part of the language itself?

cuz system("pause") holds the screen , even after i have input everything i need to input into the black screen.

Member Avatar for iamthwee

What IDE are you using?

What IDE are you using?

i use Dev C++.

cuz system("pause") holds the screen , even after i have input everything i need to input into the black screen.

I don't understand. How does cin fail to "hold the screen"? And where does the "black screen" come from using system("pause")?

I don't understand. How does cin fail to "hold the screen"? And where does the "black screen" come from using system("pause")?

cin doesnt fail to hold the screen. it's just i prefer system ("pause").
the difference between them(that i know of) is ...cin requires input after the code is compiled and run, while system("pause") just holds it without any"demand" and pressing any key closes the screen.
main thing is i prefer system("pause").

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.