Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help making a helicopter simulator program in C++. The instructions are:

ID: 3671267 • Letter: I

Question

I need help making a helicopter simulator program in C++. The instructions are:

Keywords: Overload, method, constructor/destructor, class, struct, pointer, dynamic memory allocation, string manipulation, vector, read/write file

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)

This is what I have so far. But it's not working completely

#include<string>
#include<iostream>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;
class Helicopter {

public:
Helicopter();
~Helicopter();
void API();
//structure declared
struct flying_data
{
string pilot_name = "";
vector<int>helicopter;
int i = 4;
helicopter.push_back(i); // it says helicopter does not name a type. I don't know if there are other things wrong with the code.
int visibility = 0.0;
double tank_level = 0.0;
}myHelicopter;
//method protoypes declaration
private:
void weather_input(flying_data*);
void fly_helicopter(flying_data*);
};

//constructor
Helicopter::Helicopter()
{
API();
}
//empty constructor
Helicopter::~Helicopter()
{
}
//calling simulation methods
void Helicopter::API()
{
weather_input(&myHelicopter);
fly_helicopter(&myHelicopter);
}
void Helicopter::weather_input(flying_data* myHelicopter)
{
//reading file
std::ifstream readfile("visibility.txt");//reding numbers from text file
std::string eachline;
while (std::getline(readfile, eachline))
{
std::istringstream iss(eachline);
int n;
while (iss >> n)//reading visibility value from file
{
myHelicopter->visibility = n;
}
}
//if visibility greater than 60
if(myHelicopter->visibility > 60) {
//reading tank level from pilot
cout<<" How many fuel bars are there in helicopter: ";
double fuel;
cin>>fuel;
myHelicopter->tank_level = fuel;
//if low fuel
if(fuel == 1){ //that is 10%
cout<<" Low fuel.. so it is not safe to fly.";
}
else{ //if fuel is enough to fly
cout<<" conditions are good to fly.";
}
}
//if low visibility that is less than 60
else{
cout<<" Conditions are not good to fly helicopter.";
}

}

//simulating helicopter
void Helicopter::fly_helicopter(flying_data* myHelicopter)
{
//outputting to file
string fileName = myHelicopter->pilot_name +".txt";
ofstream out_data(fileName);
//until tank level greater than 0.1
while (myHelicopter->tank_level > 0.1) {
out_data << " New tank level: " << myHelicopter->tank_level;
//decreasing 3% every time
myHelicopter->tank_level = myHelicopter->tank_level - 0.3;
}
}
int main() {
//creating helicopter object
Helicopter helicopter;
helicopter.API();
return 0;
}

Explanation / Answer

The error is comming becasue of the order of placement of the statement helicopter.push_back(i);

Please use the below given corrected code instead :

//structure declared
struct flying_data
{
string pilot_name = "";
vector<int> helicopter;
int i = 4;
int visibility = 0.0;
double tank_level = 0.0;
helicopter.push_back(i); // it says helicopter does not name a type. I don't know if there are other things wrong with the code.
}myHelicopter;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote