/*
QUESTION:
You are hired by a Garage owner to design a Garage Management System (GMS). To avoid the
Traffic jams, yous GMS will tell the new customers coming to the garage at the garage entrance
how many places are left in the Garage and whether there is place for their car in the Garage or
not (You GMS will be also conveying this information to Garage owner as well). To design this
Garage Management System you will write two classes those are Car and Garage classes.
Details of the functionality desired by these classes is dictated by the GMS requirements. So
1. Write a class named as ‘Car’ having following Attributes:
● ‘make’ of type string
● ‘car_model’ of type string
● ‘reg_no’ of type string
● ‘color’ of type string
● ‘year’ of type int
Car Class will provide following interface.
i. Write a constructor to initialize the attributes of car.
ii. Write init (string ,string, string, string, int ) function to initialize the attributes of
car.
iii. Write a destructor for car class
2. Now write class Garage of your GMS having the following attributes
● ‘name’ of type string
● ‘index’ of type int
● ‘capacity’ of type int
● Array of objects of ‘car’ class with maximum size equals to ‘capacity’
Provide following functionality/interface for Garage class
i. Write a constructor for class ‘Garage’ to initialize its attributes. Initially consider
that the Garage has capacity of 10 cars.
ii. IsEmpty(): Returns true if garage is empty and false otherwise
iii. IsFull(): Returns true if garage is full and false otherwise.
iv. Push(car c): Implement that function to park a new car c in garage, considering
that the garage is not full.
v. Find(string reg): Function should return true if that car is parked in garage and
false otherwise
vi. Remove(string reg): Function should remove the car object from garage having
reg_no equals to the given in the parameter. Returns true if car is successfully
removed and false otherwise and display messages accordingly.
(Hint: You can compare two strings using == equality operator in the same way
you compare two numerical variables)
vii. Display(): Displays all the cars parked in garage currently.
3. Menu should looks like as follows:
Exercise 7.2:
1. Add Car in Garage
2. Remove car from garage
3. Display parked cars
4. Find car
5. Check if garage is full
CODE:
*/
#include<iostream>
#include<string>
using namespace std;
/////////////////////////////CAR CLASS ////////////////////////////////////
class car{
string make;
string car_model;
string reg_no;
string color;
int year;
public:
car(){
make = "";
car_model= "";
reg_no= "";
color = "";
}
void init(){
cout<<"\nEnter Make: "; cin>>make;
cout<<"\nEnter Car MOdel: ";cin>>car_model;
cout<<"\nEnter COLOR: ";cin>>color;
cout<<"\nEnter Registration no: "; cin>>reg_no;
cout<<"\nEnter Year: "; cin>>year;
}
string getReg(){
return reg_no;
}
void cDisplay(){
cout<<make<<endl;
cout<<car_model<<endl;
cout<<reg_no<<endl;
cout<<color<<endl;
}
~car(){
//cout<<"\n\nDEstructor called\n";
}
};
/////////////////////////////////GARAGE CLASS ////////////////////////////
class Garage{
string name;
int index;
const int capacity;
car *ptr;
public:
Garage():capacity(2){
name = " ";
//index = 0;this can also be done if we skip setting index
ptr = new car[capacity];
}
void seti()//set index
{
index=0;
}
bool IsEmpty(){
if(index != capacity)
return true;
else
return false;
}
bool IsFull(){
if(index == capacity)
return true;
else
return false;
}
void push(){
bool x;
x = IsEmpty();
if (x==1){
cout<<"\n\nCar can be parked\n";
ptr[index].init();
index++;
}
else
cout<<"\n Garage is Full: \n";
}
bool Find(string reg){
for(int i=0; i<capacity;i++){
if(ptr[i].getReg() == reg){
cout<<"\nCar found \n";
return true;
}
}
return false;
}
bool Remove(string reg){
for(int i=0; i<10;i++){
if(ptr[i].getReg() == reg){
cout<<"\nCar found and removed\n";
--index;
return true;
}
}
return false;
}
void Display(){
for (int i=0;i<index;i++){
ptr[i].cDisplay();
}
}
};
///////////////////////MAIN//////////////////////////////
void main(){
Garage obj1;
obj1.seti();
while(1){
int opt;
cout<<"\n******************************************\n";
cout<<"\nEnter \n";
cout<<"1. Add car in GARAGE\n";
cout<<"2. Remove car from GARAGE\n";
cout<<"3. Display parked cars\n";
cout<<"4. FInd a car\n";
cout<<"5. Check If garage is ful\n";
cout<<"-------------------------------------------\n";
int year;
string col,make,reg,model;
cin>>opt;
switch(opt){
case 1:
{
obj1.push();
}
break;
case 2:
{
cout<<"\nEnter registration no of the car to be removed: ";
cin>>reg;
obj1.Remove(reg);
}
break;
case 3:
obj1.Display();
break;
case 4:
{cout<<"\nEnter registeration no: ";
cin>>reg;
bool a = obj1.Find(reg);
if (a==1)
cout<<"\nCar found \n";
}
break;
case 5:
{
bool a = obj1.IsFull();
if (a==1){
cout<<"\nGarage is full \n";
}
else
cout<<"\nGArage is not full \n";
}
break;
default:
break;
}
}
}
QUESTION:
You are hired by a Garage owner to design a Garage Management System (GMS). To avoid the
Traffic jams, yous GMS will tell the new customers coming to the garage at the garage entrance
how many places are left in the Garage and whether there is place for their car in the Garage or
not (You GMS will be also conveying this information to Garage owner as well). To design this
Garage Management System you will write two classes those are Car and Garage classes.
Details of the functionality desired by these classes is dictated by the GMS requirements. So
1. Write a class named as ‘Car’ having following Attributes:
● ‘make’ of type string
● ‘car_model’ of type string
● ‘reg_no’ of type string
● ‘color’ of type string
● ‘year’ of type int
Car Class will provide following interface.
i. Write a constructor to initialize the attributes of car.
ii. Write init (string ,string, string, string, int ) function to initialize the attributes of
car.
iii. Write a destructor for car class
2. Now write class Garage of your GMS having the following attributes
● ‘name’ of type string
● ‘index’ of type int
● ‘capacity’ of type int
● Array of objects of ‘car’ class with maximum size equals to ‘capacity’
Provide following functionality/interface for Garage class
i. Write a constructor for class ‘Garage’ to initialize its attributes. Initially consider
that the Garage has capacity of 10 cars.
ii. IsEmpty(): Returns true if garage is empty and false otherwise
iii. IsFull(): Returns true if garage is full and false otherwise.
iv. Push(car c): Implement that function to park a new car c in garage, considering
that the garage is not full.
v. Find(string reg): Function should return true if that car is parked in garage and
false otherwise
vi. Remove(string reg): Function should remove the car object from garage having
reg_no equals to the given in the parameter. Returns true if car is successfully
removed and false otherwise and display messages accordingly.
(Hint: You can compare two strings using == equality operator in the same way
you compare two numerical variables)
vii. Display(): Displays all the cars parked in garage currently.
3. Menu should looks like as follows:
Exercise 7.2:
1. Add Car in Garage
2. Remove car from garage
3. Display parked cars
4. Find car
5. Check if garage is full
CODE:
*/
#include<iostream>
#include<string>
using namespace std;
/////////////////////////////CAR CLASS ////////////////////////////////////
class car{
string make;
string car_model;
string reg_no;
string color;
int year;
public:
car(){
make = "";
car_model= "";
reg_no= "";
color = "";
}
void init(){
cout<<"\nEnter Make: "; cin>>make;
cout<<"\nEnter Car MOdel: ";cin>>car_model;
cout<<"\nEnter COLOR: ";cin>>color;
cout<<"\nEnter Registration no: "; cin>>reg_no;
cout<<"\nEnter Year: "; cin>>year;
}
string getReg(){
return reg_no;
}
void cDisplay(){
cout<<make<<endl;
cout<<car_model<<endl;
cout<<reg_no<<endl;
cout<<color<<endl;
}
~car(){
//cout<<"\n\nDEstructor called\n";
}
};
/////////////////////////////////GARAGE CLASS ////////////////////////////
class Garage{
string name;
int index;
const int capacity;
car *ptr;
public:
Garage():capacity(2){
name = " ";
//index = 0;this can also be done if we skip setting index
ptr = new car[capacity];
}
void seti()//set index
{
index=0;
}
bool IsEmpty(){
if(index != capacity)
return true;
else
return false;
}
bool IsFull(){
if(index == capacity)
return true;
else
return false;
}
void push(){
bool x;
x = IsEmpty();
if (x==1){
cout<<"\n\nCar can be parked\n";
ptr[index].init();
index++;
}
else
cout<<"\n Garage is Full: \n";
}
bool Find(string reg){
for(int i=0; i<capacity;i++){
if(ptr[i].getReg() == reg){
cout<<"\nCar found \n";
return true;
}
}
return false;
}
bool Remove(string reg){
for(int i=0; i<10;i++){
if(ptr[i].getReg() == reg){
cout<<"\nCar found and removed\n";
--index;
return true;
}
}
return false;
}
void Display(){
for (int i=0;i<index;i++){
ptr[i].cDisplay();
}
}
};
///////////////////////MAIN//////////////////////////////
void main(){
Garage obj1;
obj1.seti();
while(1){
int opt;
cout<<"\n******************************************\n";
cout<<"\nEnter \n";
cout<<"1. Add car in GARAGE\n";
cout<<"2. Remove car from GARAGE\n";
cout<<"3. Display parked cars\n";
cout<<"4. FInd a car\n";
cout<<"5. Check If garage is ful\n";
cout<<"-------------------------------------------\n";
int year;
string col,make,reg,model;
cin>>opt;
switch(opt){
case 1:
{
obj1.push();
}
break;
case 2:
{
cout<<"\nEnter registration no of the car to be removed: ";
cin>>reg;
obj1.Remove(reg);
}
break;
case 3:
obj1.Display();
break;
case 4:
{cout<<"\nEnter registeration no: ";
cin>>reg;
bool a = obj1.Find(reg);
if (a==1)
cout<<"\nCar found \n";
}
break;
case 5:
{
bool a = obj1.IsFull();
if (a==1){
cout<<"\nGarage is full \n";
}
else
cout<<"\nGArage is not full \n";
}
break;
default:
break;
}
}
}
No comments:
Post a Comment