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.

Slides:



Advertisements
Similar presentations
Introduction to Programming in C++ John Galletly.
Advertisements

Three types of computer languages
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 3: Input/Output
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ fundamentals.
Unformatted and Formatted I/O Operations. 2 Unformatted Input/output is the most basic form of input/output. Unformatted I/O transfers the internal binary.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
You gotta be cool. Stream Stream Output Stream Input Unformatted I/O with read, gcount and write Stream Manipulators Stream Format States Stream Error.
Introduction to C++ Systems Programming. Systems Programming: Introduction to C++ 2 Systems Programming: 2 Introduction to C++  Syntax differences between.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Basics Outline 21.1Introduction 21.2Streams Iostream Library.
1 Today’s Objectives  Announcements Turn in Homework 4 Quiz 4 will be on Wednesday, July 19 – It will have questions about inheritance, polymorphism,
Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
UNIT VI Streams & Files in C++: Stream classes, stream errors, disk file I/O with streams, File pointers, Error handling in file I/O. File I/O with members.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
Learners Support Publications Introduction to C++
Streams One of the themes of this course is that everything can be reduced to simple (and similiar) concepts. Streams are one example. Keyboard and Screen.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
CS212: Object Oriented Analysis and Design
Chapter 15 - C++ As A "Better C"
Bill Tucker Austin Community College COSC 1315
PROGRAMMING WITH C ++.
Topic 2 Input/Output.
Introduction to C++ (Extensions to C)
Introduction to C++ Systems Programming.
CPS120: Introduction to Computer Science
Computing Fundamentals
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Introduction to C++.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Chapter 2 part #3 C++ Input / Output
Introduction to C++ Programming
Programming Funamental slides
1.13 The Key Software Trend: Object Technology
Procedural Programming
Programming Funamental slides
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Chapter 3: Input/Output
Managing console i/o operations
Chapter 3 Input output.
Principles of object – oriented programming UNIT-1 Chapter-1.
Programs written in C and C++ can run on many different computers
Chapter 15 - C++ As A "Better C"
Review of C++ Language Basics
Capitolo 1 – Introduction C++ Programming
Chapter 2 part #3 C++ Input / Output
C++ Programming Basics
CPP Programming Language
Input/Output Streams, Part 1
Presentation transcript:

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

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.

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.

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

Procedure Oriented programming language Vs Object Oriented programming language

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.

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

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

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).

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.

Differences between ‘C’ and ‘C++’

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

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.

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.

Header files and libraries in C++

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.

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..

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.

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.

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()

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

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.

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

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.

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

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(); }

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.

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

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.

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 hex: It converts the base to oct: It converts the base to 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’).

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