Implementation Notes: Please follow a consistent coding style (indentation, variable names, etc.) with comments.
You are not allowed to use STL containers.
You may (and should) implement any getter and setter methods when needed.
Make use of constants and call by reference appropriately.
Use cerr for printing error messages cout.
Prin messages to the terminal. Do not create a .txt file to print into.
Your codes will be tested with Calico. Therefore your outputs should be exactly same with the given example output. To make sure about your output correctness, please checkout the supplied "output.txt" file. All available print messages are available in the "output.txt".
main.cpp file:
#include "Person.h"
#include "Mission.h"
#include "Agency.h"
#include
#include
using namespace std;
// Initialize the static member
int Mission::numMissions = 0;
int main(int argc, char const *argv[])
{
// Set the PRNG seed
srand(1773);
cout < "***="" agency="" creation="" ***"=""><>
// Create agency with given name, cash and ticket price
Agency newAgency = Agency("NASA",20000,-40);
cout <>
// Set the ticket price which is set to 0 before
newAgency.setTicketPrice(10000);
// Print agency information
cout <>
// Execute the next mission
newAgency.executeNextMission();
cout < endl="">< "***="" astronaut="" creation="" ***"=""><>
// Create astronauts
Astronaut* astronautList[5];
astronautList[0] = new Astronaut("Neil","Armstrong",3);
astronautList[1] = new Astronaut("Buzz","Aldrin",-4);
astronautList[2] = new Astronaut("Sally","Ride");
astronautList[3] = new Astronaut("Judith","Resnik",4);
astronautList[4] = new Astronaut("Yuri","Gagarin",5);
cout < endl="">< "***="" passenger="" creation="" ***"=""><>
// Create astronauts
Passenger* passengerList[5];
passengerList[0] = new Passenger("Dennis","Tito",12000);
passengerList[1] = new Passenger("Mark","Shuttleworth",10000);
passengerList[2] = new Passenger("Gregory","Olsen",15000);
passengerList[3] = new Passenger("Charles","Simonyi",24000);
passengerList[4] = new Passenger("Alperen","Kantarcı");
// Every passenger tries to buy a ticket
for(int i=0; i<5;>5;>
passengerList[i]->buyTicket(newAgency.getTicketPrice());
}
cout < endl="">< "***="" moon="" mission="" creation="" ***"=""><>
// Create moon mission
Mission moonMission = Mission("MN-01",5000,20);
moonMission += astronautList[0];
moonMission += astronautList[1];
moonMission += astronautList[2];
moonMission += passengerList[0];
moonMission += passengerList[1];
moonMission += passengerList[2];
newAgency.addMission(moonMission);
cout < endl="">< "***="" venus="" mission="" creation="" ***"=""><>
// Create venus mission
Mission venusMission = Mission("VENUS-01",35000,80);
cout < "name="" of="" the="" mission:="" "="">< venusmission.getname()=""><>
venusMission.setName("VS-01");
venusMission += astronautList[3];
venusMission += astronautList[4];
venusMission += passengerList[3];
venusMission += passengerList[4];
newAgency.addMission(venusMission);
cout < endl="">< "***="" mission="" creation="" finished="" ***"=""><>
// Show information of the agency
cout <>
cout < endl="">< "***="" lift="" off="" ***"=""><>
// Execute next mission
newAgency.executeNextMission();
cout <>
cout < endl="">< "***="" lift="" off="" ***"=""><>
// Execute another mission
newAgency.executeNextMission();
cout < newagency=""><>
// Delete the allocated space
for(int i=0; i<5;>5;>
delete astronautList[i];
delete passengerList[i];
}
return 0;
}
output.txt :
*** Agency creation ***
Ticket price can't be negative. It is set to 0.
Agency name: NASA, Total cash: 20000, Ticket Price: 0
Next Missions:
No missions available.
Completed Missions:
No missions completed before.
Agency name: NASA, Total cash: 20000, Ticket Price: 10000
Next Missions:
No missions available.
Completed Missions:
No missions completed before.
No available mission to execute!
*** Astronaut creation ***
Number of missions that astronaut completed can't be negative. It is set to 0.
*** Passenger creation ***
*** Moon mission creation ***
*** Venus mission creation ***
Given name does not satisfy the mission naming convention. Please set a new name!
Name of the mission: AA-00
Passenger Alex Baldwin does not have a valid ticket!
*** Mission creation finished ***
Agency name: NASA, Total cash: 20000, Ticket Price: 10000
Next Missions:
Mission number: 1 Mission name: MN-01 Cost: 5000
Mission number: 2 Mission name: VS-01 Cost: 35000
Completed Missions:
No missions completed before.
*** Lift off ***
MISSION MN-01 SUCCESSFUL!
Astronaut Neil Armstrong successfully completed 4 missions.
Astronaut Buzz Aldrin successfully completed 1 missions.
Astronaut Sally Ride successfully completed 1 missions.
Agency name: NASA, Total cash: 45000, Ticket Price: 10000
Next Missions:
Mission number: 2 Mission name: VS-01 Cost: 35000
Completed Missions:
Mission number: 1 Mission name: MN-01 Cost: 5000
*** Lift off ***
MISSION VS-01 FAILED!
Agency reschedules the mission.
Agency name: NASA, Total cash: 10000, Ticket Price: 10000
Next Missions:
Mission number: 2 Mission name: VS-01 Cost: 35000
Completed Missions:
Mission number: 1 Mission name: MN-01 Cost: 5000
Extracted text: Methods: Cket price cant beegattve. Tn ts set to v. Agency name: NASA, Total cash: 20000, Ticket Price: 0 Next Missions: No misstons available. Completed Missions: No missions completed before. Agency name: NASA, Total cash: 20000, Ticket Price: 10000 Next Missions: No misstons available. Completed Missions: No missions completed before. No available mission to execute! 1. Constructor(s): the constructor should optionally take the attributes. 2. addMission: this method takes a mission as an argument and adds the mission to the agency's nextMissions list/array. 3. executeNextMission: this method takes the next mission from the nextMissions list/array and ex- ecutes the mission. If the mission is successful, it should be added to completedMissions list/array and the profit of the mission should be added to the agency cash. Otherwise, the mission should be moved to the end of the nextMissions list/array. Failed mission profit also should be added to the *** Astronaut creation *** Number of missions that astronaut completed can't be negative. It is set to 0. agency cash. *** Passenger creation *** *** Moon mission creation *** 4. Overload operator<: by="" overloading="">< you="" should="" put="" information="" about="" the="" agency="" to="" the="" out="" stream.="" it="" should="" contain="" name,="" current="" cash,="" ticket="" price,="" information="" (name,="" cost)="" of="" the="" nextmissions="" and="" completedmissions.="" for="" every="" mission="" you="" should="" print="" mission="" number,="" mission="" name="" and="" mission="" cost.="" for="" more="" information="" you="" can="" check="" out="" the="" given="" output.="" ***="" venus="" mission="" creation="" ***="" given="" name="" does="" not="" satisfy="" the="" mission="" naming="" convention.="" please="" set="" a="" new="" name!="" name="" of="" the="" mission:="" aa-00="" passenger="" alperen="" kantarcı="" does="" not="" have="" a="" valid="" ticket!="" ***="" mission="" creation="" finished="" ***="" agency="" name:="" nasa,="" total="" cash:="" 20000,="" ticket="" price:="" 10000="" next="" missions:="" mission="" number:="" 1="" mission="" name:="" mn="" -01="" cost:="" 5000="" mission="" number:="" 2="" mission="" name:="" vs-01="" cost:="" 35000="" completed="" missions:="" no="" missions="" completed="" before.="" notice:="" an="" example="" main="" function="" will="" be="" supplied="" to="" you.="" you="" are="" expected="" to="" write="" your="" classes="" compatible="" with="" the="" given="" main="" function.="" please="" also="" consider="" that="" your="" implementations="" will="" be="" tested="" with="" different="" inputs.="" for="" the="" given="" "main.cpp"="" function,="" your="" code="" should="" give="" the="" following="" output.="" your="" output="" should="" be="" exactly="" same="" with="" the="" given="" "output.txt"="" file.="" be="" careful="" about="" newline="" and="" empty="" spaces="" in="" the="" "out-="" put.txt".="" please="" note="" that="" because="" of="" the="" mission="" failure="" probability="" if="" you="" change="" the="" random="" number="" generator="" seed="" you="" may="" get="" a="" different="" output.="" you="" can="" see="" the="" expected="" output="" for="" seed="" 1773="" as="" below.="" ***="" lift="" off="" ***="" mission="" mn-01="" successful!="" astronaut="" neil="" armstrong="" successfully="" completed="" 4="" missions.="" astronaut="" buzz="" aldrin="" successfully="" completed="" 1="" missions.="" astronaut="" sally="" ride="" successfully="" completed="" 1="" missions.="" agency="" name:="" nasa,="" total="" cash:="" 45000,="" ticket="" price:="" 10000="" next="" missions:="" mission="" number:="" 2="" mission="" name:="" vs-01="" cost:="" 35000="" completed="" missions:="" mission="" number:="" 1="" mission="" name:="" mn="" -01="" cost:="" 5000="" ***="" lift="" off="" ***="" mission="" vs-01="" failed!="" agency="" reschedules="" the="" mission.="" agency="" name:="" nasa,="" total="" cash:="" 10000,="" ticket="" price:="" 10000="" next="" missions:="" mission="" number:="" 2="" mission="" name:="" vs-01="" cost:="" 35000="" completed="" missions:="" mission="" number:="" 1="" mission="" name:="" mn-01="" cost:="">
.zip". Do not include any executable or project files in the archive file. You should only submit necessary files. Also, write your name and ID on the top of each document that you will upload. Methods: 1. Constructor(s): the constructor should optionally take the attributes. 5. An example "main.cpp" file will be supplied for testing your implementations. Please note that your code will be further tested with different main functions as well. 2. completeMission: when this method invoked, it will increment the numMissions attribute of the Astronaut by one. 1.4 Mission Private Attributes: Missions have name (eg. ST-21), missionNumber (eg. 2), cost (eg. 3500), faultProbability (eg. 20), completed (eg. true), passengers list/array and crew list/array. Missions also have a static numMissions variable which keeps total number of created missions. Mission name has a special naming convention. Each mission has an "XX-YY" name where X is an uppercase letter and Y is a digit. If the mission name does not satisfy this condition, an error message should be printed and the default name ("AA-00") should be set as mission name. You can use string::substr and string::find functions to parse the string. 1 Implementation Details You are expected to implement five classes; Person, Passenger, Astronaut, Mission, and Agency. You have to implement the given attributes and methods below. However, to achieve a list/array functionality you can add attributes or methods to the classes. faultProbability should be an integer between 0-100 which represents the failure probability of the mission. If 100 is given, then the mission fails at every launch. completed should be a boolean that indicates the mission success. All successful missions are con- sidered as completed, rescheduled and not executed missions are considered as not completed. 1.1 Person • passengers list/array should keep passengers that added to the mission. Private Attributes: crew list/array should keep crew members that assigned to the mission. Person has a name (eg. Neil) and a surname (eg. Armstrong). • numMission is initialized once and it is initialized to 0. You can see the initialization in the given "main.cpp". This static variable should be increased by 1 at each mission object creation. After increasing the variable result should be assigned to missionNumber variable. For example first mission should increase the static variable from 0 to 1 and assign the 1 to itself. Methods: 1. Constructor(s): the constructor should optionally take the attributes. 1.2 Passenger Methods: Passenger class is a subclass of the Person class. 1. Constructor(s): the constructor should optionally take the attributes. 2. operator+=: overload += operator for adding a Passenger or an Astronaut to the mission passen- ger or crew list/array respectively. Passengers can be added only if they have a ticket. If they don't have a ticket, error message should be shown. Astronauts are directly added to the crew list/array. You can see the usage of the overloaded operator in the example main.cpp file. Private Attributes: Passengers have cash (eg. 1250), and ticket (a boolean that shows whether a passenger has a ticket). 3. executeMission: this method invokes a random number generator (std::rand) and if the number is bigger than fault probability then mission will be successful. It will print whether mission is successful or not. If mission is successful it will invoke completeMission method of each astronaut in the crew list/array. Then it will print each astronaut name with number of completed missions. In order to see the behaviour of the method, please check out the provided output. Finally, it will set the completed attribute according to the result of the mission and return the result Methods: 1. Constructor(s): the constructor should optionally take the attributes. Note that cash can't be neg- ative. If it's given negative then cash should be set as zero and an error message should be shown. Error message will be the following: "Passenger cash can't be negative. It is set to 0." boolean. 2. buyTicket: when this method is invoked, it buys a ticket if the Passenger has enough cash to pay the ticket price. This method should take a ticket price (int) and return whether the person bought the 4. calculateProfit: this method gets a ticket price as an argument. It checks whether the mission is completed by checking the class attribute completed. If the mission is successful, then the function multiplies the ticket price with the number of passengers on board. Cost of the mission will be subtracted from the profit whether mission is successful or not. After that the method returns net profit which can be a positive or negative integer value. ticket or not as a boolean. 1.3 Astronaut Astronaut class is a subclass of the Personclass. 1.5 Agency Private Attributes: Private Attributes: Astronauts have numMissions (eg. 4) counter which shows number of successful flights that an astronaut • Agency has a name (eg. NASA), cash (eg. 25000), ticketPrice (eg. 1200), completedMissions list/array and nextMissions list/array. completed. 2 "/>
Extracted text: 4. You should compress your files into an archive file named ".zip". Do not include any executable or project files in the archive file. You should only submit necessary files. Also, write your name and ID on the top of each document that you will upload. Methods: 1. Constructor(s): the constructor should optionally take the attributes. 5. An example "main.cpp" file will be supplied for testing your implementations. Please note that your code will be further tested with different main functions as well. 2. completeMission: when this method invoked, it will increment the numMissions attribute of the Astronaut by one. 1.4 Mission Private Attributes: Missions have name (eg. ST-21), missionNumber (eg. 2), cost (eg. 3500), faultProbability (eg. 20), completed (eg. true), passengers list/array and crew list/array. Missions also have a static numMissions variable which keeps total number of created missions. Mission name has a special naming convention. Each mission has an "XX-YY" name where X is an uppercase letter and Y is a digit. If the mission name does not satisfy this condition, an error message should be printed and the default name ("AA-00") should be set as mission name. You can use string::substr and string::find functions to parse the string. 1 Implementation Details You are expected to implement five classes; Person, Passenger, Astronaut, Mission, and Agency. You have to implement the given attributes and methods below. However, to achieve a list/array functionality you can add attributes or methods to the classes. faultProbability should be an integer between 0-100 which represents the failure probability of the mission. If 100 is given, then the mission fails at every launch. completed should be a boolean that indicates the mission success. All successful missions are con- sidered as completed, rescheduled and not executed missions are considered as not completed. 1.1 Person • passengers list/array should keep passengers that added to the mission. Private Attributes: crew list/array should keep crew members that assigned to the mission. Person has a name (eg. Neil) and a surname (eg. Armstrong). • numMission is initialized once and it is initialized to 0. You can see the initialization in the given "main.cpp". This static variable should be increased by 1 at each mission object creation. After increasing the variable result should be assigned to missionNumber variable. For example first mission should increase the static variable from 0 to 1 and assign the 1 to itself. Methods: 1. Constructor(s): the constructor should optionally take the attributes. 1.2 Passenger Methods: Passenger class is a subclass of the Person class. 1. Constructor(s): the constructor should optionally take the attributes. 2. operator+=: overload += operator for adding a Passenger or an Astronaut to the mission passen- ger or crew list/array respectively. Passengers can be added only if they have a ticket. If they don't have a ticket, error message should be shown. Astronauts are directly added to the crew list/array. You can see the usage of the overloaded operator in the example main.cpp file. Private Attributes: Passengers have cash (eg. 1250), and ticket (a boolean that shows whether a passenger has a ticket). 3. executeMission: this method invokes a random number generator (std::rand) and if the number is bigger than fault probability then mission will be successful. It will print whether mission is successful or not. If mission is successful it will invoke completeMission method of each astronaut in the crew list/array. Then it will print each astronaut name with number of completed missions. In order to see the behaviour of the method, please check out the provided output. Finally, it will set the completed attribute according to the result of the mission and return the result Methods: 1. Constructor(s): the constructor should optionally take the attributes. Note that cash can't be neg- ative. If it's given negative then cash should be set as zero and an error message should be shown. Error message will be the following: "Passenger cash can't be negative. It is set to 0." boolean. 2. buyTicket: when this method is invoked, it buys a ticket if the Passenger has enough cash to pay the ticket price. This method should take a ticket price (int) and return whether the person bought the 4. calculateProfit: this method gets a ticket price as an argument. It checks whether the mission is completed by checking the class attribute completed. If the mission is successful, then the function multiplies the ticket price with the number of passengers on board. Cost of the mission will be subtracted from the profit whether mission is successful or not. After that the method returns net profit which can be a positive or negative integer value. ticket or not as a boolean. 1.3 Astronaut Astronaut class is a subclass of the Personclass. 1.5 Agency Private Attributes: Private Attributes: Astronauts have numMissions (eg. 4) counter which shows number of successful flights that an astronaut • Agency has a name (eg. NASA), cash (eg. 25000), ticketPrice (eg. 1200), completedMissions list/array and nextMissions list/array. completed. 2