Question
C++ code please asap

QUESTIONS Write the test main function as described next. This function is NOT a member function of either of the two classes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Flight
{
private :
string name;
       int id;
       int speed;
   public :  
   Flight()
   {
      this->name="";
           this->id=0;
           this->speed=0;
   }
   Flight(string name,
       int id,
       int speed)
       {
           this->name=name;
           this->id=id;
           this->speed=speed;
       }
       string getName()
       {
           return name;
       }
       int getId()
       {
           return id;
       }
       int getSpeed()
       {
           return speed;
       }
      
friend istream &operator>> (istream &in, Flight &d)
{
  
   cout<<"Enter Flight name :";
   getline(in,d.name);
  
   cout<<"Enter Id :";
   in>>d.id;
   cout<<"Enter Speed (in knots):";
   in>>d.speed;
   cin.ignore();
return in;
}

};


void writeToFile(Flight flights[],int size);
int main()
{
const int size=10;
Flight flights[size];
for(int i=0;i<size;i++)
{
   cout<<"Flight#"<<(i+1)<<":"<<endl;
   cin>>flights[i];
   }
  
   writeToFile(flights,size);


   return 0;
}
void writeToFile(Flight flights[],int size)
{
   ofstream dataOut;
   dataOut.open("flights.bin");
   for(int i=0;i<size;i++)
   {
       dataOut<<setw(20)<<left<<flights[i].getName()<<setw(10)<<left<<flights[i].getId()<<setw(10)<<left<<flights[i].getSpeed()<<endl;
   }
   dataOut.close();
}

============================================

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\FlightClassReadOperatorOverload.exe Flight#1: Enter Flight name :Airline Enter Id

=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
C++ code please asap QUESTIONS Write the test main function as described next. This function is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are to write a basic fitness application, in C++, that allows the user of the...

    You are to write a basic fitness application, in C++, that allows the user of the application to manually edit “diet” and “exercise” plans. For this application you will need to create three classes: DietPlan, ExercisePlan, and FitnessAppWrapper. Diet Plan Attributes: The class DietPlan is used to represent a daily diet plan. Your class must include three data members to represent your goal calories (an integer), plan name (a std::string), and date for which the plan is intended (a std::string)....

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Please answer the following in C++. Add a function to both the Sale and Salesperson classes...

    Please answer the following in C++. Add a function to both the Sale and Salesperson classes that returns the private salesperson ID number. Write a main()function that contains an array of five Salesperson objects and store appropriate data in it. Then, continue to prompt the user for Sale data until the user enters an appropriate sentinel value. For each Sale transaction entered, determine whether the salesperson's ID number is valid. Either display an error message, or use the friend display()function...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to...

    C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to Random Access Binary File. New program should be modified to display a menu for the user to do the following: 1. Replace Employee and Department classes with Employee and Department Structures. 2. Inside each structure, replace all string variables with array of characters. 3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 4....

  • C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to...

    C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to Random Access Binary File. New program should be modified to display a menu for the user to do the following: 1. Replace Employee and Department classes with Employee and Department Structures. 2. Inside each structure, replace all string variables with array of characters. 3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 4....

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT