Inheritance cooding

How to write this coding.

class named Vehicle members
 Brand
 Model
 Price
 Color
 A default constructor
 A constructor that accept different arguments.
 A method named display( ) that displays the values of member data with
new price.

Car inherits from Vehicle
 Engine capacity
 No. of passengers
 A default constructor
 A constructor that accept different arguments.
 A method named getData( ) to input the values of member data from
Vehicle and Car class.
 A method named getDiscount( ) that change the value of price.
 A method named setColor( ) that change the color of the car.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using std::cout;

int main() {
    cout << "class named Vehicle members
 Brand
 Model
 Price
 Color
 A default constructor
 A constructor that accept different arguments.
 A method named display( ) that displays the values of member data with 
new price.

Car inherits from Vehicle 
 Engine capacity
 No. of passengers
 A default constructor
 A constructor that accept different arguments.
 A method named getData( ) to input the values of member data from 
Vehicle and Car class.
 A method named getDiscount( ) that change the value of price.
 A method named setColor( ) that change the color of the car. ";
return 0;
}
Last edited on
you need two class one vechical
one Car .. then do some thing like this .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class CVehical
{
        private:
                int Brand ;
                int model ;
                float price ;
                int color ;
        public:
                CVechical();
                CVechical( int brand,  int mode , float price , int color ) ;
                void display() ;
                void get_data() ;
                ~CVechical() ;
};
class CCar : public CVechical
{
        private:
                int capacity ;
                int no_passnger ;
                CCar() : CVechical() { }
                void get_data() ;
                void getDiscount () ;
                void SetColor() ;

};


now take it forward to learn things .

cherrs .
xxx
Last edited on
Topic archived. No new replies allowed.