In: Computer Science
You are assigned to implement the following baggage-check-in system at the airport.
The system keeps track of data for the following information: passenger, bags, and tickets.
The program must maintain passenger details like name, address, phone number, and the number of bags. Each passenger can have multiple bags and each bag has length, width, height, and weight. The passenger also has a ticket. The tickets are of two types, either a first-class ticket or an economy-ticket. The maximum weight allowed for a first-class ticket is 40 Kilos and the maximum weight allowed for an economy-ticket is 30 Kilos. The program must display all the details of the passenger, ticket, and number of bags and allowed weight. If the weight exceeds that of the respective ticket class, then the program will give appropriate message to indicate that the passenger cannot travel. Your program must throw an exception to indicate the failure.
Requirements
bag.h
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class bag_check_system
{
private:
char name[25];
string address;
string phn_no;
int no_bags[20];
int bag_len;
int bag_weight;
int bag_hei;
int ticket_no;
int no;
public:
bag_check_system();
void checkOverweigth();
string checkPassengerClass();
void displayPassengerDetails();
void accept();
const char* getName();
string getAddress();
string getPhn_no();
int getNo_bags();
int getBag_len();
int getBag_wei();
int getBag_hei();
int getNo();
int getTicket_no();
void setName(const char*);
void setAddress(string);
void setPhn_no(string);
void setNo_bags(int);
void setBag_len(int);
void setBag_wei(int);
void setBag_hei(int);
void setNo(int);
void setTicket_no(int);
};
bag.cpp
#include"bag.h"
bag_check_system:: bag_check_system()
{
strcpy(this-> name,"\0");
this->address="\0";
this->phn_no="\0";
//this->no_bags=null;
this->bag_len=0;
this->bag_weight=0;
this->bag_hei=0;
this->ticket_no=0;
this->no=0;
}
void bag_check_system::setName(const char* name )
{
strcpy(this->name,name);
}
void bag_check_system::setAddress(string address)
{
this->address=address;
}
void bag_check_system::setPhn_no(string phn_no)
{
this->phn_no=phn_no;
}
void bag_check_system::setBag_len(int bag_len)
{
this->bag_len=bag_len;
}
void bag_check_system::setBag_hei(int bag_hei)
{
this->bag_hei=bag_hei;
}
void bag_check_system::setBag_wei(int bag_weight)
{
this->bag_weight=bag_weight;
}
int bag_check_system::getTicket_no()
{
return this->ticket_no;
}
const char* bag_check_system::getName()
{
return this->name;
}
string bag_check_system::getAddress()
{
return this->address;
}
string bag_check_system::getPhn_no()
{
return this->phn_no;
}
int bag_check_system::getBag_len()
{
return this->bag_len;
}
int bag_check_system::getBag_hei()
{
return this->bag_hei;
}
int bag_check_system::getBag_wei()
{
for(int i=1;i<=no;i++)
{
this->bag_weight=this->bag_weight+no_bags[i];
}
return this->bag_weight;
}
void bag_check_system::checkOverweigth()
{
if(this->checkPassengerClass()=="First Class")
{
if(this->getBag_wei() <=40)
{
cout<<"Weight of bags is:
"<<this->getBag_wei();
cout<<"Bags are allowed in the plane";
}
else
{
cout<<"Decrease the weight below 40kg";
}
}
else if(this->checkPassengerClass()=="Economy class")
{
if(this->getBag_wei() <=30)
{
cout<<"Weight of bags is:
"<<this->getBag_wei();
cout<<"Bags are allowed in the plane";
}
else
{
cout<<"Decrease the weight below 40kg";
}
}
}
string bag_check_system::checkPassengerClass()
{
if(this->ticket_no >0 &&this->ticket_no
<=50)
{
cout<<"First class" ;
return "First class";
}
if(this->ticket_no >50&& this->ticket_no
<=150)
{
cout<<"Economy class" ;
return "Economy class";
}
}
void bag_check_system::accept()
{
cout<<"enter Passenger Name: "<<endl;
cin>>this->name;
cout<<"enter Address: "<<endl;
cin>>address;
cout<<"enter Phone no: "<<endl;
cin>>phn_no;
cout<<"enter Number of Bags:
"<<endl;
cin>>no;
no_bags[no];
for(int i=1;i<=no;i++)
{
cout<<"enter Weight of bag "<<i<<":
"<<endl;
cin>>no_bags[i];
}
cout<<"Enter Ticket NO.: "<<endl;
cin>>this->ticket_no;
}
void bag_check_system::displayPassengerDetails()
{
cout<<"Passenger Name: "<<name<<endl;
cout<<"enter Address:
"<<address<<endl;
cout<<"Phone no: "<<this->phn_no<<endl;
cout<<"Ticket no:
"<<this->ticket_no<<endl;
cout<<"Number of Bags:
"<<this->no<<endl;
cout<<"Weight of bag/s is:
"<<this->getBag_wei()<<endl;
}
main.cpp
#include "bag.h"
using namespace std;
int main()
{
bag_check_system bag;
bag.accept();
cout<<"Details of Passenger are: "<<endl;
bag.displayPassengerDetails();
bag.checkPassengerClass();
bag.checkOverweigth();
_getch();
return 0;
}