I have been fooling around with classes lately, but so far the only variables I've been able to successfully return are integral ones, (mostly of type int and float). I am not exactly sure how to make this program work the way I want it to, and I could use a little assistance.
//Simple class program, self explanatory. Uses inline definitions//
#include <iostream.h>
#include <string.h>
class cat
{
public:
char getname() {return itsname[10];}
void setname(char name[10]) {itsname[10] = name[10];}
int getage() {return itsage;}
void setage(int age) {itsage = age;}
int getheight() {return itsheight;}
void setheight(int height) {itsheight = height;}
private:
int itsage;
int itsheight;
char itsname[10];
};
int main()
{
int age;
int height;
char name[10];
cout << "\nWhat is your cat's name?";
cin >> name;
cout << "\nHow old is your cat?";
cin >> age;
cout << "\nHow tall is your cat?";
cin >> height;
cat one;
one.setname(name);
one.setage(age);
one.setheight(height);
cout << "\nCat one's name is " << one.getname();
cout << "\nOne's age is " << one.getage() << " years old";
cout << "\nOne's height is " << one.getheight() << " cm tall";
return 0;
}
This program compiles fine, but when I enter the name, no matter what I put, it always comes out as a @ (yes, the 'at' symbol). It does the same thing whether or not I use #include <string.h>
ok, thanks for your time