Help! Programs illustrating Inheritance in C++..

Status
Not open for further replies.

Quiz_Master

* Teh Flirt King *
Hello. I am currently studying OOP in C++. I am not getting hang of this Inheritance concept.:sad: I want to write simple programs (like addition, multiplication, dividation etc) using all 5 types(Single, Multiple, Multilevel, Hierarchical and Hybrid) of Inhertitance.

Can you give me simple example programs (basic like adding, substracting etc.) for understanding the concept so I can write some more complex programs.

Please .. please Help this helpless soul.;)

Thanks in advance.
(Note: It will be really great if I can get example programs 4 all kind of inheritance.)
 

QwertyManiac

Commander in Chief
Quiz_Master said:
multiplication, dividation etc
lol.

While small examples like addition, subtraction, etc can be used to illustrate the implementation of Inheritance, its not actually used for silly tasks like these.

Think on a larger scale like re-using an existing or abandoned project.

Suppose it has a class-based structure within. Now adding lines here and there would make it very shabby and tedious to move around. But you could instead create a new class and inherit all old existing classes with minimal editing. This would make your currently-in-writing code look more cleaner and also let you use the old program code's function and data without writing them all up again. This could be one use of Inheritance.

Why do you need codes, the diagrams you might have for the various types of inheritance should get you going?
 
OP
Quiz_Master

Quiz_Master

* Teh Flirt King *
Ahmmm... I know yaar... you are a genious... but kyaa karain.. I am not. :(

Read 1st line buddy... I am learning.. so wont it be easier if I start from basic programs??
Anyone else for help. :(
 

Faun

Wahahaha~!
Staff member
take a base class named employee

derive two child classes hourly employee and fixed employee

its the simplest inheritance example as employee will be a generic class and later are specialized one.

Employee will have common attribute(variables) of bot derived classes such as SSN no, name , address,contact no.

derived classes will extend these attribs and in addition to Hourly employee class will have a variable(attribute) called hours and operation(method) to calculateSalary() based on hours worked.

Fixed employee will not hav hours variable instead it will have a rank variable and a mehof named caclulateSalary() based on rank.

If u really want to learn c++ easier way use this book:
*www.dreamtechpress.com/display.asp...or=Tony Gaddis, Judy Walters, Godfrey Muganda

do read about deadly diamond of inheritance, it is usually asked in Viva
 
Last edited:

Sykora

I see right through you.
so wont it be easier if I start from basic programs??

If "basic" means "useless" as I think it does, the answer is no. Even otherwise, the answer is still no. To understand what Inheritance is, you have know _why_ you use it.

I want to write simple programs (like addition, multiplication, dividation etc) using all 5 types(Single, Multiple, Multilevel, Hierarchical and Hybrid) of Inhertitance.

rofl. You're trying to design a watch with a sledgehammer. Inheritance isn't used for stuff like that. I went and googled "Inheritance in C++" and got a couple of good links on the first page. Take a look at them, and tell us if you have any specific questions.

Ahmmm... I know yaar... you are a genious... but kyaa karain.. I am not.

Inheritance isn't all that hard, but you _are_ going to have to work for it.
 
Status
Not open for further replies.
Top Bottom