hi guys, i have got all but one last instance. here's my code:
void main()
{
Animal bozo("Bozo", 408, 400); // name, cagenumber, weight
cout << "This animal's name is " << bozo.getName() << endl;
bozo.destroy();
}
i've declared the class for Animal and functions like name, cageno and weight. as the qns requires the last function "destroy", i'm really stuck with how to define it.
its a void so i cant return. i think it should be a delete[] but i am stuck defining it.
any help?
i am given the codes from void main() part, and i am required to write the application to use class Animal.
here's my code:
#include <iostream>
using namespace std;
class Animal
{
public:
// constructor
Animal(char* name[20], int cagenumber, int weight)
{
new_name = new char[strlen(name) +1];
strcpy(new_name, name); // string copy to set the name
}
// destructor
~Animal()
{
delete[] new_name;
}
// functions
char* getName() { return new_name; }
int getCagenumber() { return cagenumber; }
int getWeight() { return weight; }
protected:
char* new_name;
int cagenumber;
int weight;
};
void main()
{
Animal bozo("Bozo", 408, 400); // name, cagenumber, weight
cout << "This animal's name is " << bozo.getName() << endl;
bozo.destroy();
}
basically if i comment out bozo.destroy, everything's working fine, otherwise, it errors.
dang. my tutor said to ignore the destroy function altogether since its function was not mentioned n the qns.
sorry for the trouble guys.