0
#include <iostream>
using namespace std;
#include <string>

class Engine {
      int power;
      public:
             Engine() {power=0;};
             Engine (int pIn) { power = pIn;};
             void show ();
             float getPower () {return power;};
             };
void Engine::show()
{
     cout << " This is an engine have a power of " << power << " KWH " << endl;
     return;
     }
class Car : public virtual Engine {
      int speed;
      char mark [20];
      float price;
      public :
          
             Car();
             Car (int ,int ,char[],float);
             void show();
             float getSpeed () {return speed;};
             char[] getMark() {return mark;};
             float getPrice() {return price;);
             };
Car :: Car():Engine () {
    speed =0 ;
    strcpy (mark, "" );
    price = 0 ;
}
Car :: Car ( int pwIn, int sIn, char mIn[], float prIn) : Engine (pwIn){
    speed =sIn;
    strcpy (mark , mIn);
    price = prIn;
}
void Car :: show () 
{
     cout << " This is a " << mark << " having a speed of " << speed << " km/h,its power is"
     << getPower()<< "KWh and price is $ "  << price << endl;
     return ;
     }
     
class PublicTransport : public virtual Engine{
      float ticket ;
      public :
             PublicTransport();
             PublicTransport (int, float ) ;
             void (show);
             float getTicket() {return ticket;} ;
             };
PublicTransport :: PublicTransport () : Engine ()
{
                ticket =0;
                }
PublicTransport :: PublicTransport ( int pwIn , float tIn ) : Engine (pwIn){
                ticket = tIn;
                }
                // gioi thieu
void PublicTransport :: show (){
     cout << " This is a public tranport havin a ticket of $ " << ticket << " and its power is "
     << getPower()<< "Kwh" << endl;
     return ;
     }
class Bus : public Car, public PublicTransport {
      int label;
      public : 
             Bus();
             Bus ( int, int, char [],float ,float,int);
             void show();
             };
      Bus:: Bus () : Engine () ,Car(), Transport(){
            label = 0 ;
            }
            Bus :: Bus ( int pwIn,int sIn, char mIn [], float prIn, float tIn, int lIn);
            Engine (pwIn), Car (sIn, mIn, prIn ),PublicTransport ( tIn){
                   label = lIn;
                   }
            void Bus::show(){
                 cout << " This is a bus on the line " << label << " ,its speed is " << getSpeed()
                 << "km/h, power is " << Car::getPower()
                 << " KWh,mark is " << getMark ()
                 << " ,price is $ " << getPrice()
                 << " and ticket is " << getTicket()<< endl;
                 return ;
                 }
                 
                 void main ()
                 {
                      clarscr();
                      Bus myBus ( 250 ,100 , " Mercedes" ,3000, 1.5, 27 );
                      myBus.Car :: Engine :: show () ;
                      myBus.PublicTransport :: Engine :: show ();
                      myBus.PublicTransport :: show();
                      myBus.show ();
                      return ;
                      }

this is a mistake
23 F:\C++\Bus.cpp expected unqualified-id before '{' token

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by iamthwee
0

Did you even compile and test each function/class as you wrote the program. Cleaned up your indentation...

#include <iostream>
using namespace std;
#include <string>

class Engine
{
  int power;
public:
  Engine()
  {
    power = 0;
  };
  Engine ( int pIn )
  {
    power = pIn;
  };
  void show ();
  float getPower ()
  {
    return power;
  };
};
void Engine::show()
{
  cout << " This is an engine have a power of " << power << " KWH " << endl;
  return;
}
class Car : public virtual Engine
{
  int speed;
  char mark [20];
  float price;
public :

  Car();
  Car ( int , int , char[], float );
  void show();
  float getSpeed ()
  {
    return speed;
  };
  char[] getMark()
  {
    return mark;
  };
  float getPrice()
  {
    return price;
    ); //did you notice this?
  };
  Car :: Car() : Engine ()
  {
    speed = 0 ;
    strcpy ( mark, "" );
    price = 0 ;
  }
  Car :: Car ( int pwIn, int sIn, char mIn[], float prIn ) : Engine ( pwIn )
  {
    speed = sIn;
    strcpy ( mark , mIn );
    price = prIn;
  }
  void Car :: show ()
  {
    cout << " This is a " << mark << " having a speed of " << speed << " km/h,its power is"
    << getPower() << "KWh and price is $ "  << price << endl;
    return ;
  }

class PublicTransport : public virtual Engine
  {
    float ticket ;
  public :
    PublicTransport();
    PublicTransport ( int, float ) ;
    void ( show );
    float getTicket()
    {
      return ticket;
    } ;
  };
  PublicTransport :: PublicTransport () : Engine ()
  {
    ticket = 0;
  }
  PublicTransport :: PublicTransport ( int pwIn , float tIn ) : Engine ( pwIn )
  {
    ticket = tIn;
  }
  // gioi thieu
  void PublicTransport :: show ()
  {
    cout << " This is a public tranport havin a ticket of $ " << ticket << " and its power is "
    << getPower() << "Kwh" << endl;
    return ;
  }
class Bus : public Car, public PublicTransport
  {
    int label;
  public :
    Bus();
    Bus ( int, int, char [], float , float, int );
    void show();
  };
  Bus:: Bus () : Engine () , Car(), Transport()
  {
    label = 0 ;
  }
  Bus :: Bus ( int pwIn, int sIn, char mIn [], float prIn, float tIn, int lIn );
  Engine ( pwIn ), Car ( sIn, mIn, prIn ), PublicTransport ( tIn )
  {
    label = lIn;
  }
  void Bus::show()
  {
    cout << " This is a bus on the line " << label << " ,its speed is " << getSpeed()
    << "km/h, power is " << Car::getPower()
    << " KWh,mark is " << getMark ()
    << " ,price is $ " << getPrice()
    << " and ticket is " << getTicket() << endl;
    return ;
  }

  void main ()
  {
    clarscr();
    Bus myBus ( 250 , 100 , " Mercedes" , 3000, 1.5, 27 );
    myBus.Car :: Engine :: show () ;
    myBus.PublicTransport :: Engine :: show ();
    myBus.PublicTransport :: show();
    myBus.show ();
    return ;
  }

My compile log:

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\internet\My Documents\test.cpp" -o "C:\Documents and Settings\internet\My Documents\test.exe"   -Wall  -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
C:\Documents and Settings\internet\My Documents\test.cpp:42: error: expected unqualified-id before '[' token

C:\Documents and Settings\internet\My Documents\test.cpp:51: error: `Car::Car()' and `Car::Car()' cannot be overloaded
C:\Documents and Settings\internet\My Documents\test.cpp:57: error: `Car::Car(int, int, char*, float)' and `Car::Car(int, int, char*, float)' cannot be overloaded
C:\Documents and Settings\internet\My Documents\test.cpp:64: error: `void Car::show()' and `void Car::show()' cannot be overloaded

C:\Documents and Settings\internet\My Documents\test.cpp:76: error: variable or field `show' declared void
C:\Documents and Settings\internet\My Documents\test.cpp:82: error: cannot declare member function `Car::PublicTransport::PublicTransport' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:86: error: cannot declare member function `Car::PublicTransport::PublicTransport' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:92: error: cannot declare member function `Car::PublicTransport::show' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:98: error: invalid use of undefined type `class Car'
C:\Documents and Settings\internet\My Documents\test.cpp:29: error: forward declaration of `class Car'
C:\Documents and Settings\internet\My Documents\test.cpp:105: error: cannot declare member function `Car::Bus::Bus' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:109: error: cannot declare member function `Car::Bus::Bus' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:110: error: expected `;' before '(' token
C:\Documents and Settings\internet\My Documents\test.cpp:114: error: expected `;' before "void"
C:\Documents and Settings\internet\My Documents\test.cpp:115: error: cannot declare member function `Car::Bus::show' within `Car'
C:\Documents and Settings\internet\My Documents\test.cpp:133: error: expected `}' at end of input
C:\Documents and Settings\internet\My Documents\test.cpp: In member function `float Car::getPrice()':
C:\Documents and Settings\internet\My Documents\test.cpp:49: error: expected primary-expression before ')' token
C:\Documents and Settings\internet\My Documents\test.cpp:49: error: expected `;' before ')' token

C:\Documents and Settings\internet\My Documents\test.cpp: In member function `void Car::main()':
C:\Documents and Settings\internet\My Documents\test.cpp:126: error: `clarscr' undeclared (first use this function)
C:\Documents and Settings\internet\My Documents\test.cpp:126: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Documents and Settings\internet\My Documents\test.cpp:130: error: `((Car::PublicTransport*)(&myBus))->Car::PublicTransport::show' cannot be used as a function
C:\Documents and Settings\internet\My Documents\test.cpp: At global scope:

C:\Documents and Settings\internet\My Documents\test.cpp:133: error: expected unqualified-id at end of input
C:\Documents and Settings\internet\My Documents\test.cpp:133: error: expected `,' or `;' at end of input

Execution terminated

Come on?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.