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

a) Write a definition for a class named Aircraft with fields for manufacturer, y

ID: 3677586 • Letter: A

Question

a) Write a definition for a class named Aircraft with fields for manufacturer, year, cost, length, passengerCapacity, and freightCapacity. Use the most appropriate types for these fields. All fields should be accessible in the class and its derived classes.

b) Give prototypes for a default constructor, a copy constructor, and an initializing constructor that takes six parameters and initializes all fields, an assignment operator, and a destructor. All are intended to be available outside the class. Make clear where these prototypes go in the class definition given in part (a).

c)Write a definition for a class named Jet that inherits from Aircraft using public inheritance and adds fields for jet engine type (a string) and exhaust gas speed. It should also have an initializing constructor that takes eight parameters. All fields should be inaccessible from outside the class, but the constructor should be accessible.

d)Write code for the initializing constructor for the Jet class that was declared in part (c). Make use of a constructor for the base Aircraft class as well as a constructor for the manufacturer name (this string variable can b

e)Show how to declare a variable (in say main.cpp) named myJetNow of the type Jet with a manufacturer of Lockheed McDonnell, a year of 2010, a cost of 200000, a length of 24 meters, a passenger capacity of 16, a freight capacity of 40000, a jet engine type of Rolls Royce, and an exhaust gas speed of1288.4.

Explanation / Answer

Constructors
   When ever we are creating an object some piece of code will execute internally to perform initialization,that piece of code is nothing but “constructor“.Hence the main objective of constructor is to perform initialization.

Default constructor

If we are not writing any constructor then the compiler always generate constructor
If we are writing at least one constructor then the compiler won’t generate any default constructor

Prototype of default constructor:
It is always no-arg constructor
It contains only one line i.e super().It is a call to super class constructor and it should be no-arg call.
The access modifier of the default constructor is same as class modifier(either public (or) default)

Example
public class Test{
//default constructor generated by compiler
public Test(){

}
}

Copy Constructor

The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: Initialize one object from another of the same type. Copy an object to pass it as an argument to a function

Constructor Initilization:

Constructors have no names and cannot be called directly. They are invoked when initialization takes place, and they are selected according to the rules of initialization. The constructors without explicit specifier are converting constructors. The constructors with a constexpr specifier make their type a LiteralType. Constructors that may be called without any argument are default constructors. Constructors that take another object of the same type as the argument are copy constructors and move constructors.

class X {
int a, b, i, j;
public:
const int& r;
X(int i)
: r(a) //
, b{i} //
, i(i) //
, j(this->i)
{ }
};

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