You are on page 1of 4

C++

Chapter 1: Introduction of OOPs and Revision of basics

-----------------------------------------------------------------------Chapter Contents History of Programming approaches Invention of programming languages Points about C++ Differences between C and C++ Input Output Instructions About Header File iostream h First !ample Program

-----------------------------------------------------------------------History of programming approaches At each critical point in the evolution of programming" a new approach was created to help the programmer handle increasingly comple# programs $he first programs were created by toggling switches on the front panel of the computer $his approach is suitable for only the smallest programs %e#t" assembly language was invented" which allowed longer programs to be written $he ne#t advance happened in the &'()s when the first high level language *FO+$+A%, was invented -y using high level programming language" a programmer was able to write programs that were several thousand lines long However the method of programming was .anything/ goes approach It yields unreadable and unmanageable code %e#t invention is structured programming languages in the &'0)s C is a structured programming language as it contains control structures" code bloc1s and absence of goto *or at least minimal use, $o allow more comple# programs to be written" a new approach of programming is needed !o the ob2ect oriented programming was invented OOP ta1es the best of the ideas embodied in structured programming and combines them with powerful new concepts that allow you to organi3e your program more effectively Inventions of programming languages In &'4)s" Assembly language was invented which is a machine level language5 also it comes under low level language In &'()s" FO+$+A% was invented It is first high level programming language that is machine independent language

In &'00" -CP6 was invented by 7artin +ichards -CP6 stands for -asic Combined Programming 6anguage In &'0'" - language was developed by 8en $hompson He is also 1now as developer of 9%I: operating system In &';<" C language was developed by Dennis +itchie at A$ =$/s -ell 6ab" %ew >ersy 9!A In &';'" C++ language was developed by -2arne !troustrup Initially C++ was pronounced as C with classes ome Points about C++ C++ was developed by -2arne stroustrup in the year &';' at A$ and $/s -ell 6abs" %ew >ersey 9!A C++ is an enhancement in C" so it consists of all the features that C provides Initially C++ was 1nown as .C with classes/ In the year &'?@" it is named as C++ C++ is also a middle level language 2ust li1e C !ifferences bet"een C and C++ 1# Ahen a function ta1es no parameter" its prototype has the word void inside parenthesis int fun$void#% However" in C++ the void is optional int fun$#% If this convention would use in C" it mean that nothing is said about the parameters &# In a C++ program" all functions must be prototyped In C" prototypes are recommended but technically optional '# About 1eyword returnB In C++" if a function is declared as returning a value" that is return type other than void" any return statement within that function must contain a value In C" a non void function is not reCuired to actually return a value If it doesn/t" a garbage value is returned (# CommentsB In C" comments in the program can be specified by DEF ED In C++" due to bac1ward compatibility" DEF ED is still used for multiple line comments Ae can also ma1e a single line as comment by prefi# that line by DD )# Declaration of local variables In C local variables can be declared only at the start of a bloc1 prior to any action statements In C++ local variables can be declared anywhere in the bloc1 *# +eference variable

In C++" reference variable are implicit pointers that acts as another variable name for some e#isting variable $here is no concept of reference variable in C +# $op Down and -ottom up approach C programmer follows top down approach for programming It is a program design techniCue that starts with the highest level of an idea and wor1s its way down to the lowest level of detail C++ programmer adopts bottom up approach for programming In a bottomGup approach the individual base elements of the system are first specified in great detail $hese elements are then lin1ed together to form larger subsystems" which then in turn are lin1ed" sometimes in many levels" until a complete topGlevel system is formed ,# Procedure oriented Programming and Ob2ect Oriented Programming Procedure oriented Programming 7ain program is divided into small parts depending on the functions $he Different part of the program connects with each other by parameter passing 7ost of the functions use global data Ob2ect Oriented Programming 7ain program is divided into small ob2ects depending on the problem Data = functions of each individual ob2ect act li1e a single unit Hach ob2ect controls its own data Data hiding is possible in OOP which prevent illegal access of function from outside of it $his is one of the best advantages of OOP Input-Output Instruction In C" standard input device is 1eyboard and scanf*, is use to receive data from 1eyboard Also" standard output device is monitor and printf*, is use to send dataDmessage to monitor In C++" printf*, can be replaced by .cout/B coutIIJHello !CAJ5 $his statement introduces two new C++ features" cout and II cout is a predefined ob2ect $he operator II is called the insertion or put to operator It is used to display message on the screen ./amples: printf*KHello !CAJ,5 coutIIKHello !CAJ5 printf*Ksum of Ld and Ld is LdJ" a" b" c,5 coutIIKsum of JIIaIIK and KIIbIIK is KIIc5 printf*KLdJ"a+b,5 coutIIa+b5 In C++" scanf*, can be replaced by .cin/B cinMM#5

cinMMyMM35 $he identifier cin is a predefined ob2ect in C++ $he operator MM is 1nown as e#traction or get from operator It is used to ta1e input from 1eyboard ./amples: scanf*KLdJ" =a,5 cinMMa5 scanf*KLdLdJ" =a" =b,5 cinMMaMMb5 scanf*KLdLfJ" =a" =c,5 cinMMaMMc5 0bout header file iostream1h Ae need to include header file iostream h" as it contains declarations for the identifier cout and the operator II Also it contains declarations for the identifier cin and operator MM ample Program NincludeIiostream hM void main*, O int #" s5 coutIIJHnter a numberJ5 cinMM#5 sP#E#5 coutIIJ!Cuare of KII#IIJ is KIIs5 Q