Ok I am making a simple program that deals with inheritance. The program basically works except for when I output the names of the god and the person it puts out 50 characters with the last being the names that the user input. I am not sure what to do in order to fix this.
code:
-------------------------------------------------------------------------------
#include <iostream.h>
#include <string.h>
class god
{
public:
virtual void speak() { cout << "\nGod is speaking!\n";}
virtual void setname(char* name) {strncpy(itsname, name, 50);}
virtual char *getname() {return itsname;}
protected:
char itsname[50];
};
class person: public god
{
public:
void speak() {cout << "\nThe person is speaking!\n";}
};
int main()
{
char name[50];
char name1[50];
god thor;
person bob;
thor.speak();
bob.speak();
cout << "\n";
cout << "\nEnter a name for god ";
cin.getline(name, 50);
cout << "\nThe god's name is " << thor.getname();
cout << "\n";
cout << "\nEnter a name for the person";
cin.getline(name1, 50);
cout << "\nThe name of the person is " << bob.getname();
return 0;
}
------------------------------------------------------------------------------8