Whats wrong with my classes
May 15, 2015 at 7:56pm UTC
Can anybody tell me what is wrong with my classes. I get a error I don't know if you can't declare strings like that or not. Help Me
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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Dog
{
public :
Dog();
void setspeed(int DogSpeed);
void setFurColor(string DogFurColor);
void setNumofLegs(int DogNumOfLegs);
int GetSpeed();
string GetFurColor();
int GetNumOfLegs;
private :
string FurColor;
double NumOfLegs;
double speed;
double WeightInPounds;
};
Dog::Dog()
{
FurColor;
NumOfLegs = 4;
speed = 0;
WeightInPounds = 0;
}
void Dog::setspeed(int DogSpeed)
{
speed=DogSpeed;
}
void Dog::setFurColor(string DogFurColor)
{
FurColor=DogFurColor;
}
void Dog::GetFurColor()
{
return FurColor;
}
int Dog::GetSpeed()
{
return speed;
}
int main()
{
int inputSpeed = 0;
string inputFurColor = "" ;
Dog PersonDog;
cout << "Enter in the dog's speed " ;
cin >> inputSpeed;
cout << "Enter dogs fur color" ;
getline(cin,inputFurColor);
PersonDog.setspeed(inputSpeed);
PersonDog.setFurColor(inputFurColor);
cout << "Dog runs a total of " << PersonDog.GetSpeed() << " MPH" << endl;
cout << "Dog fur color is" << PersonDog.GetFurColor() << endl;
cin.ignore();
return 0;
}
--Justin
Last edited on May 15, 2015 at 7:57pm UTC
May 15, 2015 at 8:00pm UTC
Post the error.
May 15, 2015 at 8:05pm UTC
Also the error is that you are returning nothing in the GetFurColor()
function when you delcared it to return a string
... So change it from void Dog::GetFurColor()
to string Dog::GetFurColor()
May 15, 2015 at 8:07pm UTC
Void Dog::GetFurColor doesn't match any type in Dog();
Topic archived. No new replies allowed.