Write a C++ class Park with the following data members: name (string), area (in
ID: 3625345 • Letter: W
Question
Write a C++ class Park with the following data members: name (string), area (in acres, type double), location (string), visitors (int) indicating the number of visitors, thus far, to the park, trails (double) indicating the mileage of the equestrian trails in the park, and ski (bool) indicating if there is cross country skiing in the park.
The class should have a constructor that takes in arguments for initializing all the member variables and the following overloaded operators:
To test your class, write a main program that sets up four park objects with following values:
Name
Area
Location
Visitors
Eq. Tr.
Has skiing?
Itasca
32690
NC
10000
0
Yes
Whitewater
2745
SE
8800
0
Yes
Afton
1695
CE
7693
5
Yes
Interstate
298
CE
6870
0
No
Display these Park objects using the << operator. Then add 100 to the number of visitors for Whitewater Park, 200 to Itasca, 120 to Interstate, and 150 to Afton. Display the Park objects again.
Name
Area
Location
Visitors
Eq. Tr.
Has skiing?
Itasca
32690
NC
10000
0
Yes
Whitewater
2745
SE
8800
0
Yes
Afton
1695
CE
7693
5
Yes
Interstate
298
CE
6870
0
No
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
class Park
{
private: string name;
double area;
string location;
int visitors;
double trails;
bool ski;
public:
Park()
{}
Park(string nm,double ac,string loc,int vis,
double mil,bool sk)
{
name=nm;
location=loc;
area=ac;
visitors=vis;
trails=mil;
ski=sk;
}
Park operator+(const Park &obj);
};
ostream& operator<<(ostream &strm,const Park &obj)
{
strm<<obj.name<<" "<<obj.area<<" "<<obj.location
<<" "<<obj.visitors
<<" "<<obj.trails<<" ";
(obj.ski)?strm<<"Yes":strm<<"No";
return strm;
}
Park Park::operator+(const Park &obj)
{
Park temp;
temp.name=name;
temp.location=location;
temp.area=area;
temp.visitors=visitors+obj.visitors;
temp.trails=trails;
temp.ski=ski;
return temp;
}
void main()
{
Park park1("Itasca",32690,"NC",10000,0,true);
Park park2("Whitewater",2745,"SE",8800,0,true);
Park park3("Afton",1695,"CE",7693,5,true);
Park park4("Interstate",298,"CE",6870,0,false);
cout<<"Name"<<" Area Location Visitors Eq. Tr
Has skiing?"<<endl;
cout<<park1<<" "<<park4<<" "<<park3<<endl;
//pause system fora while
system("pause");
}//end main
Hope this will help you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.