I dont know what I'm doing wrong. The program is supposed to have three variables: string name, float weight, int age. It supposed to have 3 methods: a constructor, destructor, and void displayDog(in which the name,weight, and age of the dog should be displayed).
In main i am supposed to have two objects: myDog(Spot,5.5,3) & yourDog(Jack,4.5,3). Im supposed to overload these operators: >+, <, ==, <<. and overload the operator << so that cout << yourDog; works. I have met all these requirements and I feel like i'm doing it right so why wont my program run. Help please.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// ==================================
// "Dog.h"
#include<iostream>
#include<string>
using namespace std;
#ifndef DOG_H
#define DOG_H
class Dog
{
private:
string name;
float weight;
int age;
public:
bool operator >=(Dog & dog)
{
if (age >=2)
return true;
else
return false;
}
bool operator <(Dog & dog)
{
if ( yourDog > myDog)
return true;
else
return false;
}
bool operator ==( Dog & dog)
{
if (yourDog == myDog)
return true;
else
return false;
}
bool operator <<(Dog & dog)
{
yourDog.displayDog();
}
Dog(string,float,int)
{ weight = 0; age = 0; }
~Dog();
void displayDog()
{ cout << "NAME: " << name << endl <<
cout << "WEIGHT: " << weight << endl <<
cout << "AGE: " << age << endl; }
};
#endif
// "main.cpp"
#include"Dog.h"
int main()
{
Dog myDog("Spot",5.5, 3);
myDog.displayDog();
Dog yourDog("Jack",4.5,3);
yourDog.displayDog();
if (myDog >=2)
cout << "The dog is at least 2 years old.\n\n";
else
cout << "The dog is less than 2 years old.";
if (yourDog < myDog)
cout << "Your dog weighs less than my dog.\n\n";
if (myDog < yourDog)
cout << "They have the same name.\n\n";
else
cout << "They do not have the same name.\n\n";
return 0;
}
|
these are the errors it shows:
------ Build started: Project: HW 9a, Configuration: Debug Win32 ------
main.cpp
c:\users\\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(30): error C2065: 'yourDog' : undeclared identifier
c:\users\\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(30): error C2065: 'myDog' : undeclared identifier
c:\users\\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(37): error C2065: 'yourDog' : undeclared identifier
c:\users\suha\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(37): error C2065: 'myDog' : undeclared identifier
c:\users\suha\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(44): error C2065: 'yourDog' : undeclared identifier
c:\users\\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(44): error C2228: left of '.displayDog' must have class/struct/union
type is ''unknown-type''
c:\users\\documents\visual studio 2010\projects\hw 9a\hw 9a\main.cpp(11): error C2679: binary '>=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
c:\users\suha\documents\visual studio 2010\projects\hw 9a\hw 9a\dog.h(21): could be 'bool Dog::operator >=(Dog &)'
while trying to match the argument list '(Dog, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========