#include "iostream"
class vehicle {
protected:
int wheels;
float weight;
public:
void initialize(int in_wheels, float in_weight);
int get_wheels(void) {return wheels;}
float get_weight(void) {return weight;}
float wheel_loading(void) {return weight/wheels;}
};
class car : public vehicle {
int passenger_load;
public:
void initialize(int in_wheels, float in_weight, int people = 4);
int passengers(void) {return passenger_load;}
};
class truck : public vehicle {
int passenger_load;
float payload;
public:
void init_truck(int how_many = 2, float max_load = 24000.0);
float efficiency(void);
int passengers(void) {return passenger_load;}
};
main()
{
vehicle unicycle;
unicycle.initialize(1, 12.5);
cout << "The unicycle has " <<
unicycle.get_wheels() << " wheel.\n";
cout << "The unicycle's wheel loading is " <<
unicycle.wheel_loading() << " pounds on the single tire.\n";
cout << "The unicycle weighs " <<
unicycle.get_weight() << " pounds.\n\n";
car sedan;
sedan.initialize(4, 3500.0, 5);
cout << "The sedan carries " << sedan.passengers() <<
" passengers.\n";
cout << "The sedan weighs " << sedan.get_weight() << " pounds.\n";
cout << "The sedan's wheel loading is " <<
sedan.wheel_loading() << " pounds per tire.\n\n";
truck semi;
semi.initialize(18, 12500.0);
semi.init_truck(1, 33675.0);
cout << "The semi weighs " << semi.get_weight() << " pounds.\n";
cout << "The semi's efficiency is " <<
100.0 * semi.efficiency() << " percent.\n";
}
// initialize to any data desired
void
vehicle::initialize(int in_wheels, float in_weight)
{
wheels = in_wheels;
weight = in_weight;
}
void
car::initialize(int in_wheels, float in_weight, int people)
{
passenger_load = people;
wheels = in_wheels;
weight = in_weight;
}
void
truck::init_truck(int how_many, float max_load)
{
passenger_load = how_many;
payload = max_load;
}
float
truck::efficiency(void)
{
return payload / (payload + weight);
}
// Result of execution
//
// The unicycle has 1 wheel.
// The unicycle's wheel loading is 12.5 pounds on the single tire.
// The unicycle weighs 12.5 pounds.
//
// The sedan carries 5 passengers.
// The sedan weighs 3500 pounds.
// The sedan's wheel loading is 875 pounds per tire.
//
// The semi weighs 12500 pounds.
// The semi's efficiency is 72.929072 percent.
Subscribe dengan Rohaza Dollah dot com untuk mendapat tipstips/produk/idea terkini tentang pernigaaan internet.
Subscribe melalui Email
Subscribe melalui Email
ATAU
Categories
- Affiliate Program (1)
- Ainul Mardhiah (1)
- Articles (1)
- Audio Book (1)
- birthday (1)
- Business (5)
- Cerekarama Online (1)
- Computer Ethic (1)
- Diariku (13)
- dns (1)
- domain (1)
- final countdown (1)
- Health (1)
- Isu Semasa (2)
- Java (2)
- Jokes (2)
- Make Money Online (3)
- Million Challenge (1)
- Motivation (3)
- Pengaturcaraan C++ (10)
- penyakit rohani (1)
- Petua Hebat Blogging (5)
- Politik (1)
- Russell Brunson (1)
- server (1)
- web hosting (1)
- Worth Reading (1)
April 22, 2008
Aturcara C++ - Pewarisan / Inheritance
Labels: Pengaturcaraan C++
Subscribe to:
Post Comments (Atom)
Work at Home, Stay at Home
Download PERCUMA
Dapatkan secara percuma beberapa material yang boleh dimuat turun secara PERCUMA.
Pengiklanan Berkesan
Online Success Plan
.....dan banyak lagi akan ditambah dari masa ke semasa.
Pengiklanan Berkesan
Online Success Plan
.....dan banyak lagi akan ditambah dari masa ke semasa.
0 comments:
Post a Comment