Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit -1 Objectives: Exposure to basics of object oriented mode, C++ programming and I/O in C++ INTRODUCTION: Differences Between C and C++, The Object.

Similar presentations


Presentation on theme: "Unit -1 Objectives: Exposure to basics of object oriented mode, C++ programming and I/O in C++ INTRODUCTION: Differences Between C and C++, The Object."— Presentation transcript:

1 Unit -1 Objectives: Exposure to basics of object oriented mode, C++ programming and I/O in C++ INTRODUCTION: Differences Between C and C++, The Object Oriented Technology, Disadvantage of Conventional Programming, Concepts of Object Oriented Programming, Advantages of OOP, Structure of a C++ Program, Header Files and Libraries. INPUT AND OUTPUT IN C++: Introduction, Streams In C++ and Stream Classes, Pre-Defined Streams, Stream Classes, Formatted and Unformatted Data,Unformatted Console I/O Operations, Member Functions of Istream Class, Formatted Console I/O Operations, Bit Fields, Flags without Bit Field, Manipulators, User Defined Manipulators

2 Evolution of OOP’s Earlier languages such as COBOL (COmmon Business Oriented Language), FORTRAN (FORmula of TRANslation) etc. are Procedure oriented languages. Structure oriented programming languages are C, PASCAL and BASIC The procedure (function) oriented programming languages follow top down approach. The big problem is divided into small sub problems and solved those problems, and makes calls to sub problems where they required. The main disadvantage is providing security for the code.

3 Code re-usability is not possible in Procedure Oriented programming languages. To overcome these difficulties, Object oriented programming is came into existence. It is completely depends on Objects, and it is Bottom-up approach for solving the Big problems. C++ is developed by Bjarne Stroustrup.

4 Principle of Object Oriented Programming Language: In Object Oriented programming there is no functions and sub-functions, it is completely depends on Objects. 1.ABSTRACTION 2.ENCAPSULATION 3.INHERITANCE 4.POLYMORPHISM 5.DYNAMIC BINDING 6.MESSAGE PASSING 7.CLASSES AND OBJECTS

5 Procedure Oriented programming language Vs Object Oriented programming language

6 Applications of OOP’s a) Real time systems. b) Simulation and modeling. c) Object oriented database. d) Hypertext, Hypermedia. e) AI (Artificial Intelligence). f) CAM/CAD systems. g) Decision support and office automation systems.

7 Dis-advantages of conventional programming languages: 1. Monolithic programming 2. Procedural Programming 3. Structured Programming 4. Object Oriented programming

8 Evolution of CPP In the early 1980’s, Bjarne Stroustrup working for Bell Labs developed the C++ language. The C++ language is a linking of C. Like the C language, C++ is compact and can be used for system programming. C++ has object-oriented programming (OOP) capabilities. C++ is called a hybrid language because it can be used both as a procedural language like C and as an object-oriented language

9 In 1990’s, the ANSI/ISO committee began working on a standard version of the C++ language. By June 1998,the committee had approved the Final Draft International Standard for C++. It was released in the form of a document. It extended the language to include exceptions, templates, and the Standard Template Library ( STL).

10 Applications of C++ 1. C++ is a versatile language for handling large program. 2. C++ programs are easily maintainable and expandable. 3. Expected that C++ will replace with C as general purpose language in near future. 4. It is used to developing editors, compilers, databases, communication systems and complex real time applications.

11 Differences between ‘C’ and ‘C++’

12 Comment statements in C++ C++ supports two types of comment lines. They are 1. Multi line comments. 2. Single line comments. 1.Multi line comments: These comment statements are also recognized by C language. It is also supported by C++. The following representation shows multi line comment lines. /* this is a C++ program for Adding two integer numbers and two Floating point numbers */ 2. Single line comments: These comment statements are supported by only C++. The following representation shows single line comments. // this is C++ program for // Adding two integer numbers and two // floating point numbers

13 Structure of C++ program The structure of C++ program contains four sections. 1. Include files or linking section. 2. Class declaration or definition section. 3. Member function definition section. 4. Main function section.

14 1. Include files or linking section: This section contains header files for requiring C++ program. The #include “iostream.h” header file is required for input/output streams, cin/cout. 2. Class definition or declaration section: class is an object code. So you have to write the code of an object i.e. data members are member functions in this section. 3. Main function section: The object for the above class is created in “main()” function section. By using that object name with dot (. ) operator you have to access the public member functions in class. 4. Normal function definition: This section is useful to write the definitions of user defined functions.

15 Header files and libraries in C++

16 Streams in C++: Stream is series of bytes or flow of data. Generally the stream is divided into two types 1. Input stream: The source stream that provides data as input to the program is called as input stream. 2. Output stream: The source stream that receives data from the program is called as output stream.

17 1. Output Stream: The standard output stream in C++ is ‘cout’. It is an output function in C++. The operator used with output stream is called put to operator or insertion operator (<<). The examples of output stream are as follows: cout<<a; cout<<”this is a C++ program:”; cout<<”\n the sum of two number is :”<<c; 2. Input Stream: The standard input stream in C++ is ‘cin’. It is an input function in C++ for reading input. The operator used with input stream is called get to operator or extraction operator ( >> ). The examples of input stream are as follows: cin>>a; cin>>a>>b>>c; C++ does not contain any format sepcifiers. i.e. %d, %f, %c, %ld etc..

18

19 1.istream class: It is derived from ios class, it inherits all the properties of ios. It contains different functions namely get(), getline(), read(), ignore(), gcount(), peek(), pushback()..etc. 2. ostream class: It is also derived from ios class, it inherits all the properties of ios. It contains different functions namely ‘put()’, ‘write()’. 3. streambuf: This ‘streambuf’ deals with files and memory.

20 4. iostream class: It is derived from both ‘istream’ class and ‘ostream’ class, It handles both input and output operations. 5. istream_withassign: The assignment operator is used with ‘istream’ is called as ‘istream_withassign’ class. 6. iostream_withassign: The assignment operator is used with ‘iostream’ class is called as ‘iostream_withassign’ class. 7. ostream_withassign: The assignment operator is used with ‘istream’ class is called as ‘ostream_withassign’ class.

21 Unformatted I/O operations: 1. Different ‘istream’ class operations are: 1. get(): This function is used to get a single character from input device. Syntax: cin.get(char ch); or ch=cin.get()

22 Program by using ‘get()’ function. #include"iostream.h" #include"conio.h" void main() { char ch; clrscr(); cout<<"\n enter a character:"; cin.get(ch); //or it is equivalent to ch=cin.get() cout<<"\n The given character is :"<<ch; getch(); } Output: enter a character:s The given character is :s

23 2. getline(): This function is used to get whole line until new line occurs or it reads specified number of maximum characters from input device. It selects the given characters and placed it into buffer. Syntax: cin.getline(string,n); n-is specified number of characters.

24 Program by using ‘getline()’ function: Ex:1 #include"iostream.h" #include"conio.h" void main() { char str[100]; clrscr(); cout<<"\n enter a string:"; cin.getline(str,7); cout<<"\n The given string is:"<<str; getch(); } Output: enter a string:This is c++ program The given string is:This i

25

26 3. read(): This function is used to read specified number of characters from input device. It is same as ‘getline()’ function. But this function does not terminate the reading string with ‘\0’ (NULL character). Syntax: cin.read(str,n); n-is number of characters.

27 2. Different ‘ostream’ class operations are: 1.put(): This functions is used to print single character on output screen. Syntax: cout.put(char); #include"iostream.h" #include"conio.h" void main() { char ch; clrscr(); cout<<"\n enter a character:"; cin.get(ch); cout.put(ch); getch(); } Output: enter a character:s s

28 2. write(): This functions is used to write specified number of characters on output screen. Syntax: cout.write(str,n); str-given string, n-is number of characters to be written in output. #include"iostream.h" #include"conio.h" #include"string.h" void main() { char str[]="ABCDEF"; clrscr(); for(int i=0;i<=strlen(str);i++) { cout.write(str,i); cout<<endl; } for(i-=2;i>=0;i--) { cout.write(str,i); cout<<endl; } getch(); }

29 Formatted console I/O operations: The formatted console I/O operations are used display the output in various styles, and get the input in various formats. They are classified three types 1. Member functions of ‘ios’ stream class and flags. 2. Manipulators. 3. User-defined manipulators.

30

31

32

33

34

35 5. unsetf(): This function is used to clear flags which is set by ‘setf()’ function. After applying ‘unsetf()’ function the output will be displayed in normal format. Example: cout.width(6); cout.fill(‘*’); cout.setf(ios::left,ios::adjustfield); cout.unsetf(ios::left); //unset the flag. cout<<67; o/p: ****67

36 Manipulators The manipulators are special functions that are used to modify the working of stream. These manipulators are easily embedded into i/o statements. Generally there are two types of manipulators, they are 1. Non-parameterized manipulators. 2. Parameterized manipulators.

37 1.Non-parameterized manipulators: These manipulators do not contain parameters; they are directly used with I/O functions. The following are some list of non-parameterized manipulators: 1. dec: It converts the base to 10. 2. hex: It converts the base to 16. 3. oct: It converts the base to 8. 4. ws: It extracts white spaces from the input stream, characters in the stream will be extracted until a non- white space. 5. endl: It output a new line character, it is same as ‘\n’. 6. ends: It outputs a null character (‘\0’).

38 Examples: cout<<oct<<55; o/p: 67 cout<<hex<<59; o/p: 3b cout<<endl;o/p: new line. cout<<ends; o/p: NULL

39

40

41


Download ppt "Unit -1 Objectives: Exposure to basics of object oriented mode, C++ programming and I/O in C++ INTRODUCTION: Differences Between C and C++, The Object."

Similar presentations


Ads by Google