UNIT 5 INTRODUCTION TO C 51 OVERVIEW OF C C is an object oriented programming

Unit 5 introduction to c 51 overview of c c is an

This preview shows page 110 - 114 out of 125 pages.

UNIT - 5 INTRODUCTION TO C++ 5.1 OVERVIEW OF C++ C++ is an object – oriented programming language C++ was developed by bjarne stroustrup at AT & T bell laboratories in murray hill, new jersey, usa The idea of C++ comes from the c increment operator ++, thereby suggesting that C++ is an incremented version of C Most of what we already know about capplies to C++ also Therefore, almost all c programs are also C++ program The three most important facilities that C++ adds on o c are classes, function overloading and operator overloading 5.2 APPLICATIONS OF C++ C++ is a versatile language for handling very large programs. It is suitable for virtually any programming taks including development of editors, compilers, databases, communication systems and any complex real – life application system Since C++ allows us to create hierarchy related objects, we can build special object- oriented libraries which can be used later by many programmers While C++ is able to map the real world problem property, the c part of C++ gives the language the ability to get close to the machine – level details When a new features need to be implemented, it is very easy to add to the existing structure of an object. A simple C++ program Example: Printing a string #include<iostream.h> // include header file main() { count<<"C++ is better C"; // C++ statement }
Image of page 110
5.2 Fundamentals of Computing an Programming Program Features The C++ program is a collection of functions. The example contains only are function, main() Every C++ program must have a main() Comments C++ introduces a new comment symbol // (double slash) A comment may start anywhere in the line C Comment Symbols C++ Comment /* CProgram */ //C++ Program Output Operator Example: cout <<"C++ is better C."; This statement introduces two new C++ features, cout and << The identifier cout is a predefined object that represent the standard output steam in c++ Here, the standard output stream represents the screen The operator << is called the insertion or put to operator. The object cout has a simple interface if string represents a string variable Cout<<String; << → bitwise left shift operator this concept is known as operator over loading C C++ printf Count<< The iostream.h file # include < iostream .h> Some old versions of C++ use a header file called stream.h The header file iostream.h should be included at the beginning of all program that use input/output statements
Image of page 111
Introduction to C++ 5.3 Return Statement Every main() in c++ should end with a return (0) statement; Otherwise a warning or an error might occur Turbo c++ gives a warning and then compiles and executes the program Average of two numbers #include<iostream.h> main() { float number1, number2,sum, average; Cout<<"Enter two number:"; Cin>>number1; Cin>> number2; Sum = number 1+ number2; average = sum/2; Cout<<"sum="<<sum<<"\n"; Cout<<"Average = "<<average<<"\n"; } Output Enter two number : 6.5 7.5 Sum = 14 Average = 7 Input Operator The statement Cin>>number1; The identifier Cin is a predefined object in c++ that corresponds to the standard input stream Here, this stream represents the keyboard The operator >> is known as extraction or get from operator
Image of page 112
5.4
Image of page 113
Image of page 114

You've reached the end of your free preview.

Want to read all 125 pages?

  • Fall '19

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture