Make sure your definition of MexicanRestaurant supports the following kinds of c
ID: 3626560 • Letter: M
Question
Make sure your definition of MexicanRestaurant supports the following kinds of constructors:// By default, a restaurant named "Baja Fresh" that seats 55
// located at "2750 Olympic Boulevard"
MexicanRestaurant bajafresh;
// A restaurant named "Alcapulco" that seats 120 located at
// "45 Ocean Park"
MexicanRestaurant alcapulco( 120, "Alcapulco", "45 Ocean Park" );
The Class Restaurant represents some kind of eating establishment.
The instances McDonalds and Starbucks were created by saying:
Restaurant McDonalds( "McDonalds", 100, "1200 Pico Boulevard" );
// a McDonalds that seats 100 and located at 1200 Pico Boulevard
Restaurant Starbucks( "Starbucks", 20, "555 Santa Monica Boulevard" );
// a Starbucks seats 20 and located at 555 Santa Monica Boulevard
Each Restaurant is defined by its name, seating capacity and location. For the constructors shown above, here is the class definition (.h)
//Class definition
class Restaurant {
public:
Restaurant ();
Restaurant ( string name, int capacity, string location );
int getCapacity() const;
string getLocation() const;
string getName() const;
private:
string my_Location; // the street address
int my_Capacity; // the seating capacity
string my_Name; // the name
};
//Class Diagram
Restaurant
Restaurant ();
Restaurant ( string name, int capacity, string location );
int getCapacity() const;
string getLocation() const;
string getName() const;
std::string my_Location, my_Name;
int my_Capacity
//constructor
Restaurant::Restaurant() {
my_Location = "";
my_Capacity = 0;
my_Name = "";
}
Restaurant::Restaurant( string name,int capacity,string location ) {
my_Location = location;
my_Capacity = capacity;
my_Name = name;
}
string Restaurant::getLocation() const {
return my_Location;
}
int Restaurant::getCapacity() const {
return my_Capacity;
}
string Restaurant::getName() const {
return my_Name;
}
Explanation / Answer
// Restaurant.cpp : Defines the entry point for the console application.
#include<iostream>
#include<string>
using namespace std;
//Class definition
class Restaurant
{
public:
Restaurant ();
Restaurant(int capacity,string name,string location );
Restaurant ( string name, int capacity, string location );
int getCapacity() const;
string getLocation() const;
string getName() const;
private:
string my_Location; // the street address
int my_Capacity; // the seating capacity
string my_Name; // the name
};
//constructor
Restaurant::Restaurant() {
my_Location = "";
my_Capacity = 0;
my_Name = "";
}
Restaurant::Restaurant(int capacity,string name,string location )
{
my_Location = location;
my_Capacity = capacity;
my_Name = name;
}
Restaurant::Restaurant( string name,int capacity,string location ) {
my_Location = location;
my_Capacity = capacity;
my_Name = name;
}
string Restaurant::getLocation() const
{
return my_Location;
}
int Restaurant::getCapacity() const {
return my_Capacity;
}
string Restaurant::getName() const {
return my_Name;
}
void main()
{
//creating instances for different restaurent
Restaurant McDonalds( "McDonalds", 100, "1200 Pico Boulevard" );
//printing data
cout<<"Restaurant:"<< McDonalds.getName()<<" Capacity:"<< McDonalds.getCapacity()<<" Location:"<< McDonalds.getLocation()<<endl;
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.