Implement a helicopter simulator: 1) create a class helicopter containing the pu
ID: 3671220 • Letter: I
Question
Implement a helicopter simulator: 1) create a class helicopter containing the public method API; API calls the private methods: weather_input, fly_helicopter; (2 points) 2) The local pointer variable *myHelicopter defined as “struct flying_data” declared in the method API; myHelicopter requires struct dynamic allocation to match what user informs about how many helicopters are flying: 2 or 3; This struct contains: pilot_name, rockets, visibility; declare rockets as a type of variable “vector” of integer containing 4 rockets, 1 is loaded or 0 is empty/discharged. (3 points) 3) Method weather_input: read from a file what is the current visibility – if below 60% abort for safety reasons; also ask how many bars of fuel the helicopter has: 10 bars meaning 100%, 5 bars is 50% and so on; if fuel has only 10% of fuel it is not safe to fly.(2 points) 4) Use pointers to pass myHelicopter among the functions that are called from API. From fly_helicopter: print into a file on every loop iteration the fuel level; the name of the file for the output should be the pilot name; every loop decreases 3% from current tank level; (3 points)
Explanation / Answer
#include <iostream>
#include <stdlib.h>
struct flying_data
{
string pilot_name;
/*declare rockets as a type of variable “vector” of integer containing 4 rockets,
1 is loaded or 0 is empty/discharged.*/
vector<int>rockets(4,0);
int visibility;
};
class helicopter
{
public:
flying_data *myHelicopter ;
helicopter(int num)
{
myHelicopter= malloc(num*sizeof(flying_data));
}
void weather_input(int num)
{
ifstream infile("fly_data.txt");
if(!infile)
{
cout<<"cannot open the Input file ";
}
else
{
for(int i=0;i<num;i++)
{
infile>>myHelicopter.visibility;
if(myHelicopter.visibility<60)
{
cout<<endl<<"Helicopter "+(i+1) <<" is aborted";
}
int fuel;
cout<<endl<<"how many bars of fuel?";
cin>>fuel;
if(fuel==1)
cout<<endl<<"Helicopter "+(i+1) <<"not safe to fly";
}
}
}
void fly_helicopter();
};
int main()
{
cout<<endl<<"How many helicopters? ";
int num;
cin>>num;
helicopter H(num);
H.weather_input(num);
H.fly_helicopter();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.