Assignment Create an Aircraft class that has several properties that are common
ID: 3602319 • Letter: A
Question
Assignment Create an Aircraft class that has several properties that are common to all aircraft (Ex: number of engines, seat capacity). You define the name of the Class and the actual fields. The fields MUST BE PRIVATE!!! You must define a constructor that allows you to provide at least some of the field values used for an aircraft. You must define a printCharacteristics) method. Create three subclasses for specialized types of aircraft. An example might be a Fighter, Acrobat, and Freight. You do not have to use these three choices. You define the names of the classes. Each specialized craft should have additional properties that are common to just that type of specialized craft. These fields MUST BE PRIVATE. For each derived class, you must define a constructor that allows you to provide at least some of the field values used for these subclass aircraft. You must define any getter/setter methods you need Make a SINGLE C++ vector of Aircraft pointers. You will populate this list by reading commands from an input file. This vector will hold pointers to any type of Aircraft including your three derived classes. The commands in the file will cause you to create your Aircraft objects or print them using the printCharacteristics ) method. This method must be overridden in each subclass. The output should print a well formatted description of all the specific and inherited information for each craft. (Make sure you up on virtual functions and virtual destructors).Explanation / Answer
#include "stdlib.h"
#include "stdafx.h"
#include <iostream>
using namespace std;
const int rows=13;
const int coloums=6;
const int firstclass_lastrow=2;
const int secondclass_lasstrow=7;
char **updateSeats(char **seats, int row , int coloum);
void printSeatsAvailable(char **seats);
char **createSeats();
void getUserPreference(char **seats);
void gotoMainMenu(char **seats2);
bool checkSeat(char **seats, int row_number , int colum_number);
bool seatAvailable(char **seats, int start , int end);
void welcomeMessage();
bool validateUserpreference(int row, int colum, char classtype, char smokPref);
char **updateSeats(char **seats, int row , int coloum)
{
seats[row-1][coloum-1]='X';
cout <<" "; cout <<" ";
return seats;
}
void printSeatsAvailable(char **seats)
{
for (int i=0; i<rows; i++)
{
cout <<" ";
for (int j=0; j<coloums; j++)
{
cout << seats[i][j]<<" ";
}
}
}
char **createSeats()
{
char **seats=new char*[rows];
for (int i=0; i<rows; i++)
{
seats[i] = new char[10];
for (int j=0; j<coloums; j++)
seats[i][j]='*';
}
return seats;
}
bool validateUserpreference(int row, int colum, char classtype, char smokPref)
{
if(classtype=='F')
{
if((row -1)<firstclass_lastrow && (colum-1) <coloums)
{
return true;
}
else
{
cout <<" Invalid user input";
cout << " First class belongs first and second row ";
return false;
}
}
else if(classtype=='E')
{
'E',smoking_pref )
if(smokPref=='S')
{
if(secondclass_lasstrow<(row -1)&& (row -1)<rows && (colum-1) <coloums)
{
return true;
}
else
{
cout <<" Invalid user input";
cout << " This row is not belong to economy smoking class ";
return false;
}
}
else if(smokPref=='N')
{
if(firstclass_lastrow<row && row <secondclass_lasstrow && colum-1 <coloums)
{
return true;
}
else
{
cout <<" Invalid user input";
cout << " This row is not belong to economy non smoking class ";
return false;
}
}
}else
{
return false;
}
}
void getUserPreference(char **seats)
{
char **seats2;
char class_type, smoking_pref;
int colum, row;
bool val;//hold validated value for the seat
cout << " Please select your class ";
cout << " For first class enter 'F' ";
cout << " For economy class enter 'E' ";
cout << " To exit from the programe enter 'O' ";
cout << " Enter your preference :";
cin >> class_type;
class_type=toupper(class_type);
if(class_type=='F')
{
cout << " Enter the preference seat ";
cout << " Row :";
cin >> row;
cout << " Coloumn :";
cin >> colum;
val =validateUserpreference(row, colum, 'F','N' );
if(val==true){
smoking_pref, colum, row);
if(checkSeat(seats, row , colum)){
seats2=updateSeats(seats, row, colum);
printSeatsAvailable(seats2);
getUserPreference(seats2);
}else
{
cout << " Already occupied this seat! ";
cout << " Try Again !!";
getUserPreference(seats);
}
}else{
getUserPreference(seats);
}
cin.get();
}
else if (class_type=='E')
{
cout << " For smoking row enter 'S' ";
cout << " For non-smoking row enter 'N' ";
cout << " ";
cin >> smoking_pref;
smoking_pref=toupper(smoking_pref);
cout << " Enter the preference seat ";
cout << " Row :";
cin >> row;
cout << " Coloumn :";
cin >> colum;
val =validateUserpreference(row, colum, 'E',smoking_pref );
if(val==true){
smoking_pref, colum, row);
if(checkSeat(seats, row , colum)){
seats2=updateSeats(seats, row, colum);
printSeatsAvailable(seats2);
getUserPreference(seats2);
}else
{
cout << " Already occupied this seat! ";
cout << " Try Again !!";
//system("cls");
getUserPreference(seats);
}
}else{
getUserPreference(seats);
}
}
else if(class_type=='O')
{
welcomeMessage();
}else{
cout <<" Invalid character!! ... try again!";
getUserPreference(seats);
}
}
void gotoMainMenu(char **seats)
{
char input;
cout << " **************************************************** ";
cout << " #################welcome to main menu############### ";
cout << " enter 1 for buy a seat ";
cout << " ";
cout << " ##################################################### ";
cout << " ***************************************************** ";
cout << " Enter your preference :";
cin >> input;
if(input=='1')
{
system("cls");
getUserPreference(seats);
}
else
{ system("cls");
gotoMainMenu(seats);
}
}
bool checkSeat(char **seats, int row_number , int colum_number)
{
if (seats[row_number-1][colum_number-1]=='*')
{
return true;
}
else
{
return false;
}
}
bool seatAvailable(char **seats, int start , int end)
{
for(int i=start; i<end; i++)
{
for (int j=0; j<7; j++){
if (seats[i][j]=='*')
{
return true;
}
else
{
return false;
}
}
}
}
void welcomeMessage()
{
char ans;
do{
cout <<" ";
cout <<" ########### Welcome To Jet Airways ##############"<<" " ;
cout <<" *********** ********** "<< " ";
cout <<" ******* Airplane Seating Assingment ****** "<< " ";
cout <<" * * "<< " ";
cout <<" * * "<< " ";
cout <<" * * "<< " ";
cout <<" ";
cout <<" ";
cout<<" ~*~*~*~*~*~*~*~*~*~*~*~ About Us ~*~*~*~*~*~*~*~*~*~ "<<endl<<endl;
cout<<" WORK WITH PASSION "<<endl;
cout<<" < E-mail : Jetliner Airways@ rocketmail.com > "<<endl;
cout<<" < Website: www.jetliner.com > "<<endl;
cout <<" ";
cout <<" ";
cout <<" Do you want to continue? (y/n) :";
cin >> ans;
ans=toupper(ans);//changing input into uppercase
}while(ans!='Y' && ans!='N');
if(ans =='Y')
{
system("cls");
char **seats=createSeats();// initially all seats are free
gotoMainMenu(seats);
}else
{
exit(1);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
welcomeMessage();
cin.get();
return 0;
}
MAKE_SLIDER
(
cs_slider_ailerons,
BMP_CS_SMALL_AILERONS,
NULL,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
95, 6, AILERON_DEFLECTION, NULL, 100,
MODULE_VAR_NONE, NULL, 0
)
PELEMENT_HEADER cs_sliders_list1[] =
{
&cs_slider_ailerons.header,
NULL
}; \ END OF FIRST SLIDER MACRO
MAKE_SLIDER(
cs_slider_elevator,
BMP_CS_SMALL_ELEVATOR,
&cs_sliders_list1,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
98, 46,
MODULE_VAR_NONE, NULL, 0,
ELEVATOR_DEFLECTION, NULL, -70
)
PELEMENT_HEADER cs_sliders_list2[] =
{
&cs_slider_elevator.header,
NULL
}; \ END OF SECOND SLIDER MACRO
MAKE_SLIDER
(
cs_slider_rudder,
BMP_CS_SMALL_RUDDER,
&cs_sliders_list2,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
94, 83,
RUDDER_DEFLECTION, NULL, 80,
MODULE_VAR_NONE, NULL, 0
)
PELEMENT_HEADER cs_sliders_list3[] =
{
&cs_slider_rudder.header,
NULL
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.