Write a class called dog, which contains member variables indicating the name of the dog, the number of legs and the breed. Add a constructor to the class which sets the default number of legs to 4 (a reasonable number), the breed to "mongrel" and the name to a value specified by the user.
Add a destructor function to the class which displays a message just before the class is deleted.
Add another constructor to the class which sets the name of the dog to Rover if the user declares an instance of the dog class without specifying the name.
Why is it pointless to use a destructor to implement a "Are you sure you want to delete this object?" function?
A triangle is a shape with three straight sides. It is a fact that if you add any two sides of a triangle together, you always get a number which is bigger than the third side (so 3, 4 and 5 are sensible values for the sides of a triangle as 3 + 4 > 5, 3 + 5 > 4 and 4 + 5 > 3, but 1, 7 and 8 aren't because 1 + 7 isn't bigger than 8).
Declare a class to store the sides of a triangle. It should contain four constructors, one to set up the triangle assuming that the user has specified all three sides, one if the user specifies only two sides, one if the user specifies only one side and one if the user specifies no sides at all. In each case, the consrtuctors should prompt the user to enter any missing sides using cin statements. The values should be checked to make sure they are valid, and if they aren't the sides should be set to 0 and the user warned with a message.
Consider this program. What is the value displayed on the screen?
#include <iostream.h>
#include <cstring.h>
int calculate = 4;
class temp
{ public:
int x;
temp (int val)
{ x = val / 2;
calculate -= 3;
}
temp ()
{ x = 30;
calculate += 2;
}
};
temp first(12), second, third(8);
void main ()
{ cout << calculate + first.x + second.x + third.x << endl;
}
Why is it pointless to declare a destructor with parameters?