In: Computer Science
Write a complete C++ program that defines, implements, and utilizes a Lion class and a Pine class. Definition of classes from the implementation of the classes should be split. The program is made of five files: Lion.h, Lion.cpp, Pine.h, Pine.cpp, and TestLionPine.cpp. The components of Lion class are defined in the Lion.h file; however, all constructors and methods should not have any implementation code in this header file. All implementation code, i.e. constructor body and method body, should be written in Lion.cpp, which refers to the Lion.h using an include directive. The Lion class consists of the following components:
The components of Pine class are defined in the Pine.h file; however, all constructors and methods should not have any implementation code in this header file. All implementation code, i.e. constructor body and method body, should be written in Pine.cpp, which refers to the Pine.h using an include directive. The Pine class consists of following components.
The TestLionPine.cpp files contains only the main function for testing the Lion class and Pine class. In the main() function, create two Lion objects and two Pine objects respectively. For each class, create one from the no-argument constructor, another from the standard constructor. Before calling the standard constructor, two values should be read from the user with proper prompts. At the end, call every method from each object. Preferably, follow the sequence below:
Lion.h
#ifndef LION_H
#define LION_H
class Lion
{
private:
double weight;
double height;
public:
Lion();
Lion(double w, double h);
double getWeight();
void setWeight(double w);
double getHeight();
void setHeight(double h);
void toPrint();
void eat();
};
#endif
Pine.h
#ifndef PINE_H
#define PINE_H
class Pine
{
private:
int age;
double height;
public:
Lion();
Lion(int a, double h);
int getAge();
void setAge(int a);
double getHeight();
void setHeight(double h);
void toPrint();
void produceCone();
};
#endif
Lion.cpp
#include "Lion.h"
void Lion::setHeight(double h)
{
height = h;
}
void Lion::setWeight(double w)
{
weight = w;
}
Lion::Lion()
{
setWeight(0);
setHeight(0);
}
Lion::Lion(double w, double h)
{
setWeight(w);
setHeight(h);
}
double Lion::getWeight()
{
return weight;
}
double Lion::getHeight()
{
return height;
}
void Lion::toPrint()
{
double w = getWeight();
double h = getHeight();
cout << "height : " << h << "\n";
cout << "weight : " << w << "\n";
}
void Lion::eat()
{
cout << "eat every 48 hours\n";
}
Pine.cpp
#include "Pine.h"
void Pine::setHeight(double h)
{
height = h;
}
void Pine::setAge(int a)
{
age = a;
}
Pine::Pine()
{
setAge(0);
setHeight(0.0);
}
Pine::Pine(int a, double h)
{
setWeight(w);
setHeight(h);
}
int Pine::getAge()
{
return age;
}
double Pine::getHeight()
{
return height;
}
void Pine::toPrint()
{
int a = getAge();
double h = getHeight();
cout << "height : " << h << "\n";
cout << "age : " << a << "\n";
}
void Pine::produceCone()
{
cout << "produces cone annually\n";
}
TestLionPine.cpp
#include"Lion.h"
#include"Pine.h"
public static int main()
{
cout << "Enter lion 2's weight";
double w,h;
int a;
cin >> w;
cout << "Enter lion 2's height";
cin >> h;
Lion L1;
Lion L2(w,h);
Pine P1;
cout << "Enter pine 2's age";
cin >> a;
cout << "Enter pine 2's height";
cin >> h;
Pine P2(a,h);
cout << "Lion 1's weight : " << L1.getWeight();
cout << "Lion 2's weight : " << L2.getWeight();
cout << "Lion 1's height : " << L1.getHeight();
cout << "Lion 2's height : " << L2.getHeight();
cout << "Pine 1's height : " << P1.getHeight();
cout << "Pine 2's height : " << P2.getHeight();
cout << "Pine 1's age : " << P1.getAge();
cout << "Pine 2's age : " << P2.getAge();
cout << "Enter lion 1's weight : ";
cin >> w;
cout << "Enter lion 1's height : ";
cin >> h;
L1.setHeight(h);
L1.setWeight(w);
cout << "Enter lion 2's weight : ";
cin >> w;
cout << "Enter lion 2's height : ";
cin >> h;
L2.setHeight(h);
L2.setWeight(w);
cout << "Enter pine 1's age : ";
cin >> a;
cout << "Enter pine 1's height : ";
cin >> h;
P1.setAge(a);
P1.setHeight(h);
cout << "Enter pine 2's age : ";
cin >> a;
cout << "Enter pine 2's height : ";
cin >> h;
P2.setAge(a);
P2.setHeight(h);
cout << "Lion 1's new properties:-\n";
L1.toPrint();
cout << "Lion 2's new properties:-\n";
L2.toPrint();
cout << "Pine 1's new properties:-\n";
P1.toPrint();
cout << "Pine 2's new properties:-\n";
P2.toPrint();
L1.eat();
L2.eat();
P1.produceCone();
P2.produceCone();
}