«Voiture» не называет тип и ожидаемое первичное выражение перед «for» - PullRequest
0 голосов
/ 08 марта 2019

Я пытаюсь создать программу о транспортном средстве, но компилятор выдавал ошибку в функции main () «voiture не называет тип» и «avion не называет тип». Я думаю, что проблема связана с двумя последними двумя циклами в функции main (), но я не знаю, как ее исправить.

#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
#include<math.h>
#include<vector>



enum TYPE_AVION  { REACTION , HELICES};
class Vehicule{enter code here
        protected:
            string marque;
            unsigned int date_achat;
            double prix_achat;
            double prix_courant;

    public :
        Vehicule(string marque,unsigned int date_achat ,double prix_achat)
                :marque(marque),date_achat(date_achat),prix_achat(prix_achat)
                {}

        void affiche(ostream& sortie) const {
              sortie << marque << "date d'achat :" << date_achat << ", prix d'achat : "
              << prix_achat << ", prix actuel : " << prix_courant << endl;
        }

        double calculePrix(){
                return prix_achat - 0.01*prix_achat*(2015-date_achat);

        }


};

class Voiture : public Vehicule{
    private:
          double cylindree;
          int nb_porte;
          double puissance;
          double km;

    public :

          Voiture(string marque,unsigned int date_achat,double prix_achat,double cylindree,int nb_porte,double puissance,double km)
                        :Vehicule(marque,date_achat,prix_achat),cylindree(cylindree),nb_porte(nb_porte),puissance(puissance),km(km)
                        {}

          void affiche(ostream& sortie) const {
                  sortie << "----Voiture----" << endl;
                  sortie <<  sortie << marque << "date d'achat :" << date_achat << ", prix d'achat : "
                  << prix_achat << ", prix actuel : " << prix_courant << endl;
                  sortie << cylindree << "litres, " << nb_porte << " portes," << puissance
                  << " CV," << km << " km" << endl;
          }

          double calculePrix(){
              double prix =  prix_achat - 0.02*prix_achat*(2015-date_achat) - 0.05*prix_achat*(km/10000);

              if ( marque == "Renault" || marque == "Fiat"){
                            double d = 0.1*prix_achat;
                            prix -= d;
              }

              if ( marque == "Porsche" || marque == "Ferrari"){
                            double z = 0.2*prix_achat;
                            prix += z;
                    }
              return prix ;
              }



};


class Avion :public Vehicule{

    private:
          TYPE_AVION type;
          unsigned int nb_heure_vol;



    public :


          Avion(string marque1,unsigned int date_achat1,double prix_achat1,TYPE_AVION type,unsigned int nb_heure_vol)
                    :Vehicule(marque1,date_achat1,prix_achat),type(type),nb_heure_vol(nb_heure_vol)
                    {}

          void affiche(ostream& sortie) const {
                    sortie << "----Avion a" << type << "----" << endl;
                    sortie <<  sortie << marque << "date d'achat :" << date_achat << ", prix d'achat : "
                    << prix_achat << ", prix actuel : " << prix_courant << endl;
                    sortie << nb_heure_vol << " heures de vol." << endl;
                    }

          double calculePrix(){

                    double prix1 = 0.0;
                    if ( type == REACTION){
                            prix1 = prix_achat - 0.1*(nb_heure_vol/1000);
                    }

                    if ( type == HELICES){
                              prix1 = prix_achat -0.1*(nb_heure_vol/1000);
                    }

                    return prix1;
          }
};











int main(){

vector<Voiture> garage;
vector<Avion> hangar;

garage.push_back(Voiture("Peugeot", 1998, 147325.79, 2.5, 5, 180.0,
12000));
garage.push_back(Voiture("Porsche", 1985, 250000.00, 6.5, 2, 280.0,
81320));
garage.push_back(Voiture("Fiat", 2001, 7327.30, 1.6, 3, 65.0,
3000));
hangar.push_back(Avion("Cessna", 1972, 1230673.90, HELICES,
250));
hangar.push_back(Avion("Nain Connu", 1992, 4321098.00, REACTION,
1300));



for (auto  voiture : garage) {
    voiture.calculePrix();
    voiture.affiche(cout);
    }

for (auto  avion : hangar) {
    avion.calculePrix();
    avion.affiche(cout);
    }

return 0;
}

Я посмотрел древний аналогичный пост, но он не решил мою проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...