2016-04-11 24 views
0

私はこのデフォルトの関数の引数

#include <iostream> 
#include <string> 
using namespace std; 
class Vehicle { 
protected: 
    int Number; 
    int Year; 
    string Make; 
    string BodyStyle; 
    string Model; 
    string Color; 
    int Cost; 
public: 
    Vehicle() {} 
    Vehicle(int num, int year1, string make1, int bStyle1, 
      int model1, int color1, int cost1) 
    { 
     Number = num; 
     Year = year1; 
     Make = make1; 
     BodyStyle = bStyle1; 
     Model = model1; 
     Color = color1; 
     Cost = cost1; 
    } 
    void display() { 
     cout << "---This is Vehicle Class.---" << endl; 
     cout << "Number: " << Number << endl; 
     cout << "Year: " << Year << endl; 
     cout << "Make: " << Make << endl; 
     cout << "BodyStyle: " << BodyStyle << endl; 
     cout << "Model: " << Model << endl; 
     cout << "Color: " << Color << endl; 
     cout << "Cost: " << Cost << endl; 
    } 
}; 

Vehicleクラスのようなプログラムは、三つのクラス

  1. トラック車両
  2. オートバイの車両
  3. トレーラによって実装されている場合。

Vehicleクラスを実装するファーストクラスです。

class TruckVehicle : Vehicle { 
protected: 
    int Passengers; 
    int Mileage; 
    int GrossWeight; 
    string PoweredBy; 
    int TempGross; 
public: 
    TruckVehicle(int number, int year, string make, string model, 
       string bStyle, string color, int cost, 
       int passengers, int mileage, int gWeight, 
       string pBy, int tGross) 
    { 
     Number = number; 
     Year = year; 
     Make = make; 
     BodyStyle = bStyle; 
     Model = model; 
     Color = color; 
     Cost = cost; 
     Passengers = passengers; 
     Mileage = mileage; 
     GrossWeight = gWeight; 
     PoweredBy = pBy; 
     TempGross = tGross; 
    } 
    void display() { 
     cout << "---This is TruckVehicle class.---" << endl; 
     cout << "Number: " << Number << endl; 
     cout << "Year: " << Year << endl; 
     cout << "Make: " << Make << endl; 
     cout << "BodyStyle: " << BodyStyle << endl; 
     cout << "Model: " << Model << endl; 
     cout << "Color: " << Color << endl; 
     cout << "Cost: " << Cost << endl; 
     cout << "Passenger: " << Passengers << endl; 
     cout << "Mileage: " << Mileage << endl; 
     cout << "GrossWeight: " << GrossWeight << endl; 
     cout << "PoweredBy: " << PoweredBy << endl; 
     cout << "TempGross: " << TempGross << endl; 
    } 
}; 

Vehicleクラスを実装する第2のクラス。

class MotorcycleVehicle : Vehicle { 
protected: 
    int Passengers; 
    int Mileage; 
public: 
    MotorcycleVehicle(int number, int year, string make, string model, 
         string bStyle, string color, int cost, 
         int passenger, int mileage) 
    { 
     Number = number; 
     Year = year; 
     Make = make; 
     BodyStyle = bStyle; 
     Model = model; 
     Color = color; 
     Cost = cost; 
     Passengers = passenger; 
     Mileage = mileage; 
    } 
    void display() { 
     cout << "---This is Motor Cycle Class.---" << endl; 
     cout << "Number: " << Number << endl; 
     cout << "Year: " << Year << endl; 
     cout << "Make: " << Make << endl; 
     cout << "BodyStyle: " << BodyStyle << endl; 
     cout << "Model: " << Model << endl; 
     cout << "Color: " << Color << endl; 
     cout << "Cost: " << Cost << endl; 
    } 
}; 

Vehicleクラスを実装する第3クラス。

class TrailerVehicle : protected Vehicle { 
protected: 
    int GrossWeight; 
public: 
    TrailerVehicle() { 
     GrossWeight = 0; 
    } 
    TrailerVehicle(int number, int year, string make, string model, 
        string bStyle, string color, int cost, int gWeight) 
    { 
     Number = number; 
     Year = year; 
     Make = make; 
     BodyStyle = bStyle; 
     Model = model; 
     Color = color; 
     Cost = cost; 
     GrossWeight = gWeight; 
    } 
    void display() { 
     cout << "---This is Trailer Vehicle Class.---" << endl; 
     cout << "Number: " << Number << endl; 
     cout << "Year: " << Year << endl; 
     cout << "Make: " << Make << endl; 
     cout << "BodyStyle: " << BodyStyle << endl; 
     cout << "Model: " << Model << endl; 
     cout << "Color: " << Color << endl; 
     cout << "Cost: " << Cost << endl; 
     cout << "GrossWeight: " << GrossWeight << endl; 
    } 
}; 

トレーラ車クラスはTravelTrailerVehicleで実装されています。

class TravelTrailerVehicle : TrailerVehicle { 
protected: 
    int Passengers; 
    int Mileage; 
    string PoweredBy; 
    int BodyNumber; 
    int Length; 
public: 
    TravelTrailerVehicle(int number,int year,string make, string model, 
         string bStyle,string color,int cost, 
         int gWeight,int passengers,int mileage) 
    { 
     GrossWeight = gWeight; 
     Passengers= passengers; 
     Mileage= mileage; 
     Year = year; 
     Make = make; 
     Model = model; 
     BodyStyle = bStyle; 
     Color = color; 
     Number = number; 
     Cost = cost; 
    } 
    void display() { 
     cout << "----This is Travel Trailer Class.----" << endl; 
     cout << "Number: " << Number << endl; 
     cout << "Year: " << Year << endl; 
     cout << "Make: " << Make << endl; 
     cout << "Model:" << Model << endl; 
     cout << "BodyStyle: " << BodyStyle << endl; 
     cout << "Color: " << Color << endl; 
     cout << "Cost:" << Cost << endl; 
     cout << "GrossWeigth: " << GrossWeight << endl; 
     cout << "Passengers: " << Passengers << endl; 
     cout << "Mileage: " << Mileage << endl; 
    } 
}; 

メインメソッド。

int main() { 
    TruckVehicle Truck1(111111, 2014,"Toyota", "Tacoma","4x4","Black",25000, 2, 15000, 333333,"Gas", 222222); 
    MotorcycleVehicle Motorcycle1(2222222,2015,"Honda", "Gold Wing","Coupe","Red",5000, 1, 3250); 
    TravelTrailerVehicle Trailer1(123456789, 2015, "Toyota", "Camry","Coupe","Red", 20000, 666666, 5, 9855); 
    Truck1.display(); 
    Motorcycle1.display(); 
    Trailer1.display(); 
    system("pause"); 
    return 0; 
} 

誰かが私に、「すべてのコンストラクタのために必要なコードを最小限にするために、デフォルトの関数パラメータとメンバーリストを使用する」が何を意味するかのヒントを与えることができます。

+0

まず、どのコンストラクタパラメータをpデフォルト値を浮動させるか?次に、C++で既定の関数パラメータを記述するルールに従います。 –

+3

あなたの質問にこのコードの壁が必要とは思われません。あなたは、あなたが求めている特定の質問に関連するコードを表示したままにしておくべきです。 – juanchopanza

答えて

関連する問題