Create a stadium class. The class header file content (.h file) can go in this question, the class implementation (.cpp file) can go in the following question, and the main.cpp content can go in the third question.
static data members:
data members:
member functions:
main.cpp:
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You.
Stadium.h
#ifndef STADIUM_H_
#define STADIUM_H_
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Stadium{
private:
static int startingSeatNumber;
static int nextSeatNumber;
string stadiumName;
string nameOfHomeTeam;
string currentOpponent;
vector<int> seatSold;
public:
Stadium(string stdName);
Stadium();
static int getNextSeatNumber();
void changeHomeTeamName(string nameIn);
void changeCurrentOpponent(string currOppo);
void sellSeat();
void printSoldSeat();
friend ostream& operator<<(ostream& os,
Stadium &obj);
bool operator==(const Stadium & obj);
};
#endif /* STADIUM_H_ */
Stadium.cpp
#include "Stadium.h"
Stadium::Stadium(string stdName){
stadiumName = stdName;
}
Stadium::Stadium(){
stadiumName = "";
}
int Stadium::getNextSeatNumber(){
return nextSeatNumber;
}
void Stadium::changeHomeTeamName(string nameIn){
nameOfHomeTeam = nameIn;
}
void Stadium::changeCurrentOpponent(string currOppo){
currentOpponent = currOppo;
}
void Stadium::sellSeat(){
seatSold.push_back(nextSeatNumber);
nextSeatNumber++;
}
void Stadium::printSoldSeat(){
for(int i=0;i<seatSold.size();i++){
cout<<seatSold[i]<<endl;
}
}
bool Stadium::operator==(const Stadium & obj){
return currentOpponent==obj.currentOpponent;
}
ostream& operator<<(ostream& os, Stadium &obj)
{
cout<<"***************************************"<<endl;
cout<<"Welcome to
"<<obj.stadiumName<<" Stadium, Home team is :
"<<obj.nameOfHomeTeam<<endl;
cout<<"***************************************"<<endl;
return os;
}
int Stadium::nextSeatNumber = 1;
int Stadium::startingSeatNumber = 1;
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Stadium.h"
using namespace std;
int main(int argc, char * argv[]){
string stadiumName;
cout<<"Enter Stadium name : ";
cin>>stadiumName;
Stadium myStadium(stadiumName);
string homeTeam;
cout<<"Enter Home team name : ";
cin>>homeTeam;
myStadium.changeHomeTeamName(homeTeam);
string currentOppo;
cout<<"Enter Current Opponent name : ";
cin>>currentOppo;
myStadium.changeCurrentOpponent(currentOppo);
//serve 1000 customers
for(int i=0;i<1000;i++){
cout<<myStadium;
string customerName;
cout<<"Enter customer Name :
";
cin>>customerName;
cout<<"Customer name :
"<<customerName<<" seat allocated is :
"<<Stadium::getNextSeatNumber()<<endl;
myStadium.sellSeat();
}
cout<<"\nTotal seat allocated is as
below"<<endl;
myStadium.printSoldSeat();
return 0;
}
OUTPUT
Get Answers For Free
Most questions answered within 1 hours.