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".

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Implementation Notes: Please follow a consistent coding style (indentation, variable names, etc.) with comments.

  1. You are not allowed to use STL containers.

  2. You may (and should) implement any getter and setter methods when needed.

  3. Make use of constants and call by reference appropriately.

  4. Use cerr for printing error messages cout.

  5. Prin messages to the terminal. Do not create a .txt file to print into.

  6. 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 <iostream>
#include <cstdlib>


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 ***" << endl;
// Create agency with given name, cash and ticket price
Agency newAgency = Agency("NASA",20000,-40);
cout << newAgency;
// Set the ticket price which is set to 0 before
newAgency.setTicketPrice(10000);
// Print agency information
cout << newAgency;
// Execute the next mission
newAgency.executeNextMission();

cout << endl << "*** Astronaut creation ***" << endl;
// 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 ***" << endl;
// 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; i++){
passengerList[i]->buyTicket(newAgency.getTicketPrice());
}

cout << endl << "*** Moon mission creation ***" << endl;

// 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 ***" << endl;

// Create venus mission
Mission venusMission = Mission("VENUS-01",35000,80);

cout << "Name of the mission: " << venusMission.getName() << endl;
venusMission.setName("VS-01");

venusMission += astronautList[3];
venusMission += astronautList[4];
venusMission += passengerList[3];
venusMission += passengerList[4];

newAgency.addMission(venusMission);

cout << endl << "*** Mission creation finished ***" << endl;
// Show information of the agency
cout << newAgency;

cout << endl << "*** Lift off ***" << endl;
// Execute next mission
newAgency.executeNextMission();

cout << newAgency;

cout << endl << "*** Lift off ***" << endl;
// Execute another mission
newAgency.executeNextMission();

cout << newAgency << endl;

// Delete the allocated space
for(int i=0; i<5; i++){
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

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 operator< 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: 5000
Transcribed Image 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 operator< 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: 5000
4. You should compress your files into an archive file named "<your_student_number>.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
Transcribed Image Text:4. You should compress your files into an archive file named "<your_student_number>.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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY