Make a class diagram of your Design. Code: The code is as follows. Date.h #define DATE_H #include using namespace std; class Date { public: std::string depart_date; std::string arrival_date; Date() { depart_date = "12-03"; arrival_date = "12-03"; } void setDepartureDate(string d) { depart_date = d; } std::string getDepartureDate() { return depart_date; } void setArrivalDate(string a) { arrival_date = a; } std::string getArrivalDate() { return arrival_date; } }; Time.h #define TIME_H class Time { public: int depart_h, depart_m; float arrival_h, arrival_m; Time() { depart_h = 12; depart_m = 20; arrival_h = 2; arrival_m = 50; } void setDepartureHour(int dh) { depart_h = dh; } int getDepartureHour() { return depart_h; } void setDepartureMin(int dm) { depart_m = dm; } int getDepartureMin() { return depart_m; } void setArrivalHour(int ah) { arrival_h = ah; } int getArrivalHour() { return arrival_h; } void setArrivalMin(int am) { arrival_m = am; } int getArrivalMin() { return arrival_m; } }; Flight class and main() method #include #include #include "Date.h" #include "Time.h" using namespace std; class Flight { public: int flightID; int total_seats; int reserved_seats; bool isDirect; Date d; Time t; Flight() { flightID=0; total_seats=0; reserved_seats=0; isDirect = false; } void setFlightId(int id) { flightID = id; } int getFlightId() { return flightID; } void setTotalSeats(int t) { total_seats = t; } int getTotalSeats() { return total_seats; } void setReservedSeats(int r) { reserved_seats = r; } int getReservedSeats() { return reserved_seats; } void setIsFlightDirect(bool b) { isDirect = b; } bool getIsFlightDirect() { return isDirect; } void delayFlight(int min) { t.arrival_m = t.arrival_m + min; if(t.arrival_m > 59) { t.arrival_h = t.arrival_h + 1; if(t.arrival_h > 12) { t.arrival_h = t.arrival_h - 12; } t.arrival_m = t.arrival_m - 60; } std::cout << "Arrival time updated!" << std::endl; } void reserveSeat(int n) { reserved_seats = reserved_seats + n; if(reserved_seats > total_seats) { std::cout << "Sorry! Seats are not available!" << std::endl; reserved_seats = reserved_seats - n; } else { std::cout << "Seats reserved successfully!" << std::endl; } } void display() { std::cout << "Flight Details" << std::endl; std::cout << "Flight ID: " << getFlightId() << endl; cout << "Departure date: " << d.getDepartureDate() << std::endl; std::cout << "Departure time: " << t.getDepartureHour() << " hours and " << t.getDepartureMin() << " minutes." << std::endl; cout << "Arrival date: " << d.getArrivalDate() << std::endl; std::cout << "Arrival time: " << t.getArrivalHour() << " hours and " << t.getArrivalMin() << " minutes." << std::endl; } }; int main() { Flight f; f.setFlightId(1); f.setIsFlightDirect(true); f.setTotalSeats(100); f.setReservedSeats(90); int m; std::cout << "Enter the delay in flight in minutes: "; std::cin >> m; f.delayFlight(m); int s; std::cout << "Enter the number of seats to be reserved: "; std::cin >> s; f.reserveSeat(s); f.display(); return 0; }
Make a class diagram of your Design.
Code:
The code is as follows.
Date.h
#define DATE_H
#include <string>
using namespace std;
class Date
{
public:
std::string depart_date;
std::string arrival_date;
Date()
{
depart_date = "12-03";
arrival_date = "12-03";
}
void setDepartureDate(string d)
{
depart_date = d;
}
std::string getDepartureDate()
{
return depart_date;
}
void setArrivalDate(string a)
{
arrival_date = a;
}
std::string getArrivalDate()
{
return arrival_date;
}
};
Time.h
#define TIME_H
class Time
{
public:
int depart_h, depart_m;
float arrival_h, arrival_m;
Time()
{
depart_h = 12;
depart_m = 20;
arrival_h = 2;
arrival_m = 50;
}
void setDepartureHour(int dh)
{
depart_h = dh;
}
int getDepartureHour()
{
return depart_h;
}
void setDepartureMin(int dm)
{
depart_m = dm;
}
int getDepartureMin()
{
return depart_m;
}
void setArrivalHour(int ah)
{
arrival_h = ah;
}
int getArrivalHour()
{
return arrival_h;
}
void setArrivalMin(int am)
{
arrival_m = am;
}
int getArrivalMin()
{
return arrival_m;
}
};
Flight class and main() method
#include <stdio.h>
#include <iostream>
#include "Date.h"
#include "Time.h"
using namespace std;
class Flight
{
public:
int flightID;
int total_seats;
int reserved_seats;
bool isDirect;
Date d;
Time t;
Flight()
{
flightID=0;
total_seats=0;
reserved_seats=0;
isDirect = false;
}
void setFlightId(int id)
{
flightID = id;
}
int getFlightId()
{
return flightID;
}
void setTotalSeats(int t)
{
total_seats = t;
}
int getTotalSeats()
{
return total_seats;
}
void setReservedSeats(int r)
{
reserved_seats = r;
}
int getReservedSeats()
{
return reserved_seats;
}
void setIsFlightDirect(bool b)
{
isDirect = b;
}
bool getIsFlightDirect()
{
return isDirect;
}
void delayFlight(int min)
{
t.arrival_m = t.arrival_m + min;
if(t.arrival_m > 59)
{
t.arrival_h = t.arrival_h + 1;
if(t.arrival_h > 12)
{
t.arrival_h = t.arrival_h - 12;
}
t.arrival_m = t.arrival_m - 60;
}
std::cout << "Arrival time updated!" << std::endl;
}
void reserveSeat(int n)
{
reserved_seats = reserved_seats + n;
if(reserved_seats > total_seats)
{
std::cout << "Sorry! Seats are not available!" << std::endl;
reserved_seats = reserved_seats - n;
}
else
{
std::cout << "Seats reserved successfully!" << std::endl;
}
}
void display()
{
std::cout << "Flight Details" << std::endl;
std::cout << "Flight ID: " << getFlightId() << endl;
cout << "Departure date: " << d.getDepartureDate() << std::endl;
std::cout << "Departure time: " << t.getDepartureHour() << " hours and " << t.getDepartureMin() << " minutes." << std::endl;
cout << "Arrival date: " << d.getArrivalDate() << std::endl;
std::cout << "Arrival time: " << t.getArrivalHour() << " hours and " << t.getArrivalMin() << " minutes." << std::endl;
}
};
int main()
{
Flight f;
f.setFlightId(1);
f.setIsFlightDirect(true);
f.setTotalSeats(100);
f.setReservedSeats(90);
int m;
std::cout << "Enter the delay in flight in minutes: ";
std::cin >> m;
f.delayFlight(m);
int s;
std::cout << "Enter the number of seats to be reserved: ";
std::cin >> s;
f.reserveSeat(s);
f.display();
return 0;
}
Step by step
Solved in 2 steps with 1 images