An Object Oriented Programming with C

Similar documents
KLiC C++ Programming. (KLiC Certificate in C++ Programming)

Syllabus of C++ Software for Hands-on Learning: This course offers the following modules: Module 1: Getting Started with C++ Programming

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Object Oriented Programming

Object Oriented Programming with c++ Question Bank

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Computer Science (330)

SRE VIDYASAAGAR HIGHER SECONDARY SCHOOL. TWO MARKS

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Introduction to Programming Using Java (98-388)

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

CHOICE BASED CREDIT SYSTEM (With effect from )


Absolute C++ Walter Savitch

Time : 3 hours. Full Marks : 75. Own words as far as practicable. The questions are of equal value. Answer any five questions.

Short Notes of CS201

Tentative Teaching Plan Department of Software Engineering Name of Teacher Dr. Naeem Ahmed Mahoto Course Name Computer Programming

CS201 - Introduction to Programming Glossary By

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

C++ (Non for C Programmer) (BT307) 40 Hours

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

B.Sc II Year Computer Science (Optional)

CERTIFICATE IN WEB PROGRAMMING

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

Object Oriented Programming. Solved MCQs - Part 2

Sample Copy. Not for Distribution.

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Get Unique study materials from

CS201 Latest Solved MCQs

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Interview Questions of C++

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

VALLIAMMAI ENGINEERING COLLEGE

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

C++ Important Questions with Answers

SAURASHTRA UNIVERSITY

XII CS(EM) Minimum Question List N.KANNAN M.Sc., B.Ed COMPUTER SCIENCE IMPORTANT QUESTION (TWO MARKS) CHAPTER 1 TO 5 ( STAR OFFICE WRITER)

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

AN OVERVIEW OF C++ 1

For Teacher's Use Only Q No Total Q No Q No

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Chapter 2 Basic Elements of C++

CS3157: Advanced Programming. Outline

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

S Y B Voc Software Development Syllabus

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

Problem Solving with C++

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

6.096 Introduction to C++ January (IAP) 2009

END TERM EXAMINATION

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE1303. B.Tech. Year - II

M.C.A DEGREE EXAMINATION,NOVEMBER/DECEMBER 2010 Second Semester MC 9222-OBJECT ORIENTED PROGRAMMING (Regulation 2009)

Unit 1 : Principles of object oriented programming

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

XII- COMPUTER SCIENCE VOL-II MODEL TEST I


STRUCTURING OF PROGRAM

Computer Programming C++ (wg) CCOs

UNIT-2 Introduction to C++

Contents. 2 Introduction to C++ Programming,

Object Oriented Programming with Java. Unit-1

Multiple Choice Questions. Chapter 5

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Java Quick Syntax Reference. Second Edition. Mikael Olsson

Syllabus for Computer Applications

PART - I 75 x 1 = The building blocks of C++ program are (a) functions (b) classes (c) statements (d) operations

Murach s Beginning Java with Eclipse

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

The Design Process. General Development Issues. C/C++ and OO Rules of Thumb. Home

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Chapter 15 - C++ As A "Better C"

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Sample Copy. Not For Distribution.

C++ Quick Guide. Advertisements

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Introduction to C++ Systems Programming

Come and join us at WebLyceum

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

SRI SARASWATHI MATRIC HR SEC SCHOOL PANAPAKKAM +2 IMPORTANT 2 MARK AND 5 MARK QUESTIONS COMPUTER SCIENCE VOLUME I 2 MARKS

Proposed Syllabus for F.Y.B.Sc. (Information Technology) (w.e.f. June-2015)

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Midterm Review. PIC 10B Spring 2018

Instantiation of Template class

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

Padasalai.Net s Model Question Paper

CS304 Object Oriented Programming Final Term

COP 3330 Final Exam Review

Transcription:

An Object Oriented Programming with C By Tanmay Kasbe Dr. Ravi Singh Pippal IDEA PUBLISHING WWW.ideapublishing.in i

Publishing-in-support-of, IDEA PUBLISHING Block- 9b, Transit Flats, Hudco Place Extension Near Andrews Ganj, New Delhi Zipcode : 110049 Website: www.ideapublishing.in Copyright, Author All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form by any means, electronic, mechanical, magnetic, optical, chemical, manual, photocopying, recording or otherwise, without the prior written consent of its writer. ISBN: 978-81-932706-4-6 Price: 599.00 D The opinions/ contents expressed in this book are solely of the author and do not represent the opinions/ standings/ thoughts of idea publishing. Printed in India ii

About the Author X Tanmay Kasbe is currently working as an asst. professor in computer department. He is pursuing PhD in computer science application and holds an MCA degree from RGPV University, Bhopal. He has a long experience of teaching postgraduate, graduate and engineering students. He has 7+ year of experience as a freelancer in software development in.net technologies. He is also the author of "DBMS Concepts- A Practical approach". Dr. Ravi Singh Pippal is presently working as a Professor (Computer Science) in RKDF University, Bhopal, India. He has obtained Ph.D. from ABV-Indian Institute of Information Technology and Management, Gwalior. His primary research areas of interest include Cryptology (Cryptography, Cryptanalysis), Steganography, Key Management, Image Encryption and many more. iii

About the book X This book provides a comprehensive and practical overview of the object oriented programming with C++, It has been thoughtfully structured to introduce the readers to all the important concept of C++ though a single book. This book with its numerous programming examples with explanation will be an ideal text for undergraduate and postgraduate student of computer science and application (MCA and BCA). Besides, for any programmer who wishes to know the fundamental C++, this would be a useful book. iv

Table of Contents CHAPTER 1 :: Software Programming Language 1-18 1.1 Introductions1 1.2 Levels of Programming Language 4 Low Level Programming Language4 Machine Language5 Assembly Language6 High Level Programming Language 7 1.3 Hierarchy of Programming Language 9 1.4 Translator Program9 Assembler 11 Compiler 12 Interpreter14 1.5 Differences between compiler & Interpreter15 1.6 Introductions of Linker & Loader16 Key Points to Remember18 CHAPTER 2 :: Object Oriented Programming Language 19-36 2.1 Introduction 19 2.2 Procedure Oriented Programming 20 2.3 Comparison of OOPs & POP 22 2.4 Structure Programming 23 2.5 Object Oriented Programming Concepts 24 Objects 24 Class26 v

Polymorphism 27 Inheritance 28 Data Abstraction 29 Data Encapsulation 31 Message Passing 33 2.6 Advantages of OOPs 34 Key Points to Remember 36 CHAPTER 3 :: Basic Features of C++ 37-76 3.1 Introductions of C++ 37 3.2 Differences between C++ & C 38 3.3 Tokens in C++ 39 Keywords 40 Variables/Identifiers 41 Constants/Literals 46 Integer-Constants 46 Character-constants 47 Floating-constants 48 Strings-constants 49 Punctuators 49 Operators 51 Arithmetic Operators 51 Relational Operators 52 Logical Operators 54 Bit-wise Operators 55 Assignment Operator 55 Misc Operators 56 3.4 Data Types in C++ 57 vi

Built-In data types 58 Int 58 Float 61 Char 62 Double User define data types 61 Structure 63 Union 66 Class 67 Enumerations 3.5 Expression & Statements 67 Integral expressions 68 Float expressions 68 Relational or Boolean expressions 69 Logical expressions 69 Bitwise expressions 69 Pointer expressions 70 3.6 Data Type Conversion 70 3.7 Manipulator functions 72 Endl 73 hex, dec, oct setbase 73 setw setprecision 74 ends flush Key Points to Remember 75 vii

CHAPTER 4 :: C++ Programs & Standards 77-98 4.1 Introductions 77 4.2 Guidelines for Programs 77 4.3 Structure of C ++ Programs 83 4.4 Header file in C++ Programs 85 Iostream.h Cout<< functions Cin>> functions Conio.h Math.h Other header files 4.5 First program in C 90 4.6 Compilation & Execution 91 4.7 Formatting Output 93 Key Points to Remember 97 CHAPTER 5 :: Functions 99-140 5.1 Introductions 99 5.2 Why Functions? 104 5.3 Function Example 105 Function prototyping OR Function declarations 107 Declaring type of functions 108 Defining a function 108 Actual argument & formal argument 109 Return Statement 111 5.4 Calling a function by using call by value 112 5.5 Calling a function by using call by Reference 115 viii

5.6 Comparisons of call by value & call by reference 117 5.7 Multi-function 118 5.8 Programming example 120 5.9 Recursion 125 5.10 Recursion programs example 125 Key Points to Remember 138 CHAPTER 6 :: Classes & Objects 141-176 6.1 Introductions 141 6.2 Difference between class & structures 142 6.3 Structure of class 142 Syntax of class Variable Declaration Class Function Definition Access specifiers Public 144 Private 145 Protected 146 Defining the object of a class 148 Accessing member function using object 148 6.4 Defining function outside the class 153 6.5 Inline Functions 157 6.6 Friend Functions 161 6.7 Programming Examples 166 6.8 Multiple classes 170 6.9 Static Class members 172 Static Data members 173 Static Member functions 174 ix

Key Points to Remember 176 CHAPTER 7:: Control Statements 177-238 7.1 Introductions 177 7.2 Decision making/conditional Statements 178 Simple if statement 178 If...else statement 180 Nested if...else statement 187 7.3 Selection statement (Switch) 191 7.4 Loop Statements 204 While Loop 205 Do..While Loop 213 For loop 215 7.5 Comparision of for, while, do..while loop 230 7.6 Jumping statements 232 Break 232 Continue 233 Key Points to Remember 236 CHAPTER 8 : : Constructors & Destructors 239-266 8.1 Introductions 239 8.2 What is constructors 240 8.3 Constructors types 243 Default Constructors 243 Parameterized constructors 246 Copy constructors 250 Dynamic constructors 253 8.4 Multiple constructor in class 255 8.5 Programming examples 258 x

8.6 Destructors 262 Key Points to Remember 266 CHAPTER 9 : : Array, String Handling and Pointers 267-320 9.1 Introductions 267 9.2 Array 267 One Dimensional Array 268 Two Dimensional Array 282 M Dimensional Array 294 9.3 String Handling 300 9.4 Pointer Introduction 306 What is pointer? 308 9.5 This pointer 312 9.6 Dynamic Memory Allocation 314 Key Points to Remember 320 CHAPTER 10 : : Compile Time Polymorphism 321-356 10.1 Introductions 321 10.2 Function Overloading 321 10.3 Default Arguments 328 10.4 Operator Overloading 332 10.5 Overloading Unary Operator 333 Overloading using Friend Function 339 10.6 Overloading Binary Operator 342 Overloading using Friend Function 343 Key Points to Remember 354 CHAPTER 11 : : Inheritance 357-420 11.1 Introductions 357 xi

11.2 Syntax for defining derived classes 358 Access Specifiers 359 11.3 Single Inheritance 363 11.4 Multiple Inheritance 372 11.5 Multilevel Inheritance 380 11.6 Hierarchical Inheritance 386 11.7 Hybrid Inheritance 392 11.8 Constructors in Derived Class 400 11.9 Protected Access Specifiers 407 11.10 Virtual Base Class 413 Key Points to Remember 418 CHAPTER 12 : : Run Time Polymorphism 421-436 12.1 Introduction 421 12.2 Virtual Function 421 12.3 Difference between function overloading & overriding 429 12.4 Pure Virtual Function 430 12.5 Early Binding & Late Binding 434 CHAPTER 13 : : Exception Handling & 437-462 13.1 Introduction 437 13.2 Exception Handling 440 Try Block 440 Catching Errors 441 Throwing an Error 442 Multiple Catch Statement 446 Catch All Exception 449 13.3 Templates 452 Function Template 453 xii

Class Template 458 Key Points to Remember 461 CHAPTER 14 : : File Handling 463-482 14.1 Introduction 463 14.2 File Stream 465 14.3 Opening & Closing a File 466 Opening a file in C++ 467 Using Constructor 468 Using Open () function 468 Closing a file in C++ 470 Binary File Program 475 Appendix:(A): 75 Objective Question with answers key Appendix:(B): Complete Programs according to Universities Syllabus 483-504 513-516 xiii

Introduction to software programming language Chapter 1 INTRODUCTION TO SOFTWARE PROGRAMMING LANGUAGE 1.1 Introduction A software programming language is a special language programmers use to create software programs or other sets of instructions for computers to execute. These commands can be interpreted into a code understood by a machine. Programs are created through programming languages to control the behavior and output of a machine. As we all know computer cannot understand anything, for everything we must provide a set of instruction which is executed by programming language & then provide us an output. All the instruction which we have writes using any high level programming language is called source code. Most of the programming languages use translator programs to translate instructions into computer specific language. Although there are over 2,000 computer languages, relatively few are widely used. If we are talking on current scenario then JAVA &.NET are the most 1

Introduction to software programming language popular languages which are used by most of the small and large MNC for software development. A programming language is typically divided into three elements: Syntax Semantic Logic Developments Syntax: Like human languages, each programming language has its own grammar and syntax. In computer programming language it is very important to follow complete syntax otherwise it will not execute. A translator program responsibility is to check whether our program follow all the syntax of the language or not. If any mistake found by translator program then translator program will give errors and we must remove all the error then only our program will execute successfully. Syntax deals solely with the form and structure of symbols in a language without any consideration given to their meaning. Each programming languages has its own syntax. If we take some of the C programming language syntax likes ; (Semicolon) used or represent termination of line. (Double Equals) means when we have compared two values 2

Introduction to software programming language X ++ means we have increase the value of X by 1 Semantics: Semantics describes the behavior that a computer follows when executing a program in the language. We might disclose this behavior by describing the relationship between the input and output of a program or by a step-by-step explanation of how a program will execute on a real or an abstract machine. Semantics follow directly from syntax. Semantics deal with the meaning assigned to the symbols, characters and words. Syntax is what the computer understands; semantics is what the human understands. Examples: The sentence "Baby milk drinks" does not have a syntactic meaning, but through semantics most people would interpret it as meaning Baby drinks milk as our prior knowledge tells us that a baby drinks milk, and therefore we can find a meaning from the key words. The Arabic symbol '3' (for example) contains no meaning in and of itself. They are just pixels. You & I assign meaning to it. We assign the numeric value 'three'. Indeed the whole literate world seems to agree with us in this numeric assignment. And obviously, it works for us. But only because we agree on this convention. 3

Catch Your Complete Book From Idea Store www.ideapublishing.in