//The following program compiles fine but will not run // Your deliverable is an
ID: 3532347 • Letter: #
Question
//The following program compiles fine but will not run // Your deliverable is an operational program without modifying the class declaration // You should not change the driver program either #include using namespace std; class CAT { public: CAT(); // default constructor CAT (const CAT &); // copy constructor ~CAT(); // destructor int GetAge() const { return *itsAge; } //inline int GetWeight() const { return *itsWeight; } //inline void SetAge(int age) { *itsAge = age; } void SetWeighte(int Weight) { *itsWeight= Weight; } //inline private: int *itsAge; int *itsWeight; }; // **** End class declaration ********* CAT::CAT() { } CAT::CAT(const CAT & rhs) { } CAT::~CAT() { } // **** Driver program keep as is ********* int main() { char Char; CAT Garfield; cout << "Garfield's age: " << Garfield.GetAge() << endl; cout << "Setting Garfield to 6... "; Garfield.SetAge(6); cout << "Creating Felix from Garfield "; CAT Felix(Garfield); cout << "Garfield's age: " << Garfield.GetAge() << endl; cout << "Felix' age: " << Felix.GetAge() << endl; cout << "setting Garfield to 7... "; Garfield.SetAge(7); cout << "Garfield's age: " << Garfield.GetAge() << endl; cout << "boot's age: " << Felix.GetAge() << endl; cin>>Char; return 0; }Explanation / Answer
//The following program compiles fine but will not run
// Your deliverable is an operational program without modifying the class declaration
// You should not change the driver program either
#include <iostream>
using namespace std;
class CAT {
public: CAT(); // default constructor
CAT (const CAT &);// copy constructor
~CAT(); // destructor
void SetAge(int age) { *itsAge = age; }
int GetAge() const { return *itsAge; } //inline
int GetWeight() const { return *itsWeight; } //inline
void SetWeighte(int Weight)
{
*itsWeight= Weight; } //inline private:
int *itsAge;
int *itsWeight; }; // **** End class declaration *********
CAT::CAT() {}
CAT::CAT(const CAT & rhs) { }
CAT::~CAT() { } // **** Driver program keep as is *********
int main()
{ char Char;
CAT Garfield;
cout << "Setting Garfield to 6... "; Garfield.SetAge(6);
cout << "Garfield's age: " << Garfield.GetAge() << endl;
cout << "Creating Felix from Garfield ";
CAT Felix(Garfield);
cout << "Garfield's age: " << Garfield.GetAge() << endl;
cout << "Felix' age: " << Felix.GetAge() << endl;
cout << "setting Garfield to 7... ";
Garfield.SetAge(7);
cout << "Garfield's age: " << Garfield.GetAge() << endl;
cout << "boot's age: " << Felix.GetAge() << endl;
cin>>Char;
return 0; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.