Full Version: Object Oriented Programming (oop) Tutorial
Dream.In.Code > Programming Tutorials > C++ Tutorials
born2c0de
This Tutorial teaches you Object Oriented Programming from scratch. It is supposed to teach Inheritance as well but it is incomplete as of now. But the tutorial teaches you so many other things before you need to know Inheritance that by the time you finish reading it, the other half will be complete.

-Sanchit
born2c0de
I decided to make this Tutorial Complete in itself. Hence I shall name it OOP Tutorial in C++ PART 1.
PART 2 will contain Inheritance and a few advanced concepts of OOP.
Here's the PART-1 Version of the Tutorial.
Vextor
I know it's been some time since you posted this tutorial but I wanted to put my two cents in. This is really great and keep up the good work. It's given me everything I need to get myself back on track with where I had left off in C++ a while back. With this and a few other tutorials i've alaready learned a ton. Thanks!
born2c0de
I know it's been a long time since you posted before me [i just had to put in the pun wink2.gif ]
Sorry for late reply...looks like I should keep an eye on the Tutorials Section too.
Thanks for your appreciation...I makes me write more and more.
Currently I'm writing a tutorial on Recursion...It's going to be real exhaustive and informative.
I hope I'll be able to finish that soon because as I'm writing it, I feel its the best one so far.

Thanks.
Jessehk
I was under the impression that class methods should not be declared inline unless it was a template class.

Though I could be wrong...

Other than that, great tutorial. smile.gif
born2c0de
QUOTE(Jessehk @ 18 Jan, 2006 - 02:32 AM)
I was under the impression that class methods should not be declared inline unless it was a template class.

Though I could be wrong...

Other than that, great tutorial. smile.gif

no...just a matter of convention and choice...some people stick to that convention...
shikha
while using float values ...... we write 0.2f,6f........etc;
wat does ut signify?????
born2c0de
the 'f' suffix is just a printf Conversion-type character.
Any number that's suffixed with an 'f' just shows that its expected type is a floating point.

Here are the other Conversion-type characters.

QUOTE

Type Char Expected Input Format of output

d Integer signed decimal integer
i Integer signed decimal integer
o Integer unsigned octal integer
u Integer unsigned decimal integer
x Integer unsigned hexadecimal int (with a, b, c, d, e, f)
X Integer unsigned hexadecimal int (with A, B, C, D, E, F)
f Floating point signed value of the form [-]dddd.dddd.

e Floating point signed value of the form [-]d.dddd or e
[+/-]ddd
g Floating point signed value in either e or f form, based on given value and precision. Trailing zeros and the decimal point are printed if necessary.
E Floating point Same as e; with E for exponent.
G Floating point Same as g; with E for exponent if e format used

Characters
c Character Single character
s String pointer Prints characters until a null-terminator is pressed or precision is reached
% None Prints the % character

Pointers
n Pointer to int Stores (in the location pointed to by the input argument) a count of the chars written so far.
p Pointer Prints the input argument as a pointer; format depends on which memory model was used. It will be either XXXX:YYYY or YYYY (offset only).

Source : Borland Help
shikha
thankuuuuu................................ biggrin.gif
ankesh_ec
QUOTE(born2c0de @ 21 Dec, 2004 - 03:02 AM) *

This Tutorial teaches you Object Oriented Programming from scratch. It is supposed to teach Inheritance as well but it is incomplete as of now. But the tutorial teaches you so many other things before you need to know Inheritance that by the time you finish reading it, the other half will be complete.

-Sanchit

this is nice tutorial
completesunny
QUOTE(born2c0de @ 21 Dec, 2004 - 03:02 AM) *

This Tutorial teaches you Object Oriented Programming from scratch. It is supposed to teach Inheritance as well but it is incomplete as of now. But the tutorial teaches you so many other things before you need to know Inheritance that by the time you finish reading it, the other half will be complete.

-Sanchit



where can i get the PART 2 of this .....????can u send as soon as possible
virendra
where is the second part still waiting for it
virendra rolleyes.gif
born2c0de
Thanks for appreciating my tutorial guys.

And more than that, thanks for reminding me that I have to write the second part of this tutorial. I'm really sorry I totally forgot that I had this pending.


I'll start working on it.

And just in case if somone is already familiar with Inheritance in C++, be sure to check out my Polymorphism Tutorial in the C++ Tutorials Section.

I've even included how the compiler implements polymorphism internally.

Will be back soon with Part-2.

Sorry to keep you guys waiting.

And once again, thanks for reminding me about the second part.
janotte
Very cool tutorial, thank you.

I am a little confused by the "void main()".

Shouldn't it be "int main()" for C++?

Not a big issue but good to get people off on the right foot. But not to take away from your great work in putting this together. Thank you again.

Reference
The C++ Standard requires that main() returns type int. A program which uses any other return type for main() is technically not Standard C++, although many compilers do not enforce this strictly.
http://en.wikipedia.org/wiki/C_plus_plus#Minimal_program
born2c0de
Yes, I completely agree with you.
Unfortunately at the time of writing this tutorial, I did not realize this. And by the time I did, I was too lazy to change all voids to ints.

Glad to hear that you enjoyed the tutorial.
smile.gif
Xing
Didn't read the whole tutorial just scanned it fast. One thing which immidietly struck me was about the size of integer.

sizeof integer or any other built-in type is implementation defined in C and C++. Standard has only specified their minimum sizes

CODE

Base type    Minimum size (bits)    Minimum value (signed)    Maximum value (signed)    Maximum value (unsigned)
char            8                     -127                    127                       255
short           16                    -32,767                 32,767                    65,535
int             16                    -32,767                 32,767                    65,535
long            32                    -2,147,483,647          2,147,483,647             4,294,967,295

Oblivion
Thanks, this looks good. smile.gif
lapastica
great tutorial..thx
zorro68
I'm trying to know how works OOP and i think this tutorial is very good. But i can see you have some math mistakes in this tutorial, we see:

When you multiply two complex number, you say:
imag=(a.real * b.imag) - (a.imag * b.real);
and is:
imag=(a.real * b.imag) + (a.imag * b.real);

And when you divide complex numbers, you say:
float div = (....) + ( ....)
and is:
float div = (....) - ( ....)

So the output change:
...
Real=-5.47
Imaginary=7.92
...

and is:
...
Real=-9.24
Imaginary=11.88
...

You must change this in some functions when multiply and divide complex number.

I'm waiting for the next tutorial...

PD: Sorry for my bad english.
born2c0de
Thanks for correcting the errors
smile.gif
Zammy
Very nice tutorial. I hope we see a second part soon because its kinda short. Some of the stuff in the code are not throughly explained.

CODE
   complex(float r=0.0f,float i=0.0f)
           {
                real = r;
              imag = i;
           }


What does the ".0f" do in declaring the function?

CODE
friend ostream& operator <<(ostream& s,complex c);
Not explained. Waiting for 2nd chapter?

Question: How important is Overloading Operators ? It looks too much fuzz for readability.

Despite the above KUDOS! I was pretty much suffering under the text book I was reading about OO. I am taking "Fundamental Data Structures" course that threw me in deep water from first 2-3 lectures. Now I have a homework for Sunday I am not sure if I be able to do.
PrettyHateMachine
QUOTE(born2c0de @ 21 Dec, 2004 - 03:02 AM) *

This Tutorial teaches you Object Oriented Programming from scratch. It is supposed to teach Inheritance as well but it is incomplete as of now. But the tutorial teaches you so many other things before you need to know Inheritance that by the time you finish reading it, the other half will be complete.

-Sanchit

Well done! This is great for me because im already familiar with java and was a little hazy on the syntactical differences between the two languages. Thanks pirate.gif
priyanth kumar
QUOTE(virendra @ 12 Sep, 2006 - 09:16 PM) *

where is the second part still waiting for it
virendra rolleyes.gif

circuspeanuts
laugh.gif

ironically enough, the one part I need really bad right now isn't in here xD

This tutorial has helped me lots, as well as some of your (and others) tutorials. I've come to better understand pointers, strings, implementing functions, and the arrow operator (->).

The only thing I'm missing at the moment is the inheritance portion so I may complete my final project. You wouldn't happen to have finished or know someone who may have an inheritance tutorial finished, would you (I only ask because I know you've probably been busy and haven't been able to finish Part II of the oop tutorial for inheritance and such..)?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.