Darshan Institute of Engineering & Technology for Diploma Studies

Size: px
Start display at page:

Download "Darshan Institute of Engineering & Technology for Diploma Studies"

Transcription

1 1. Explain Call by Value vs. Call by Reference Or Write a program to interchange (swap) value of two variables. Call By Value In call by value pass value, when we call the function. And copy this value in another variable at function definition. In call by value the original value in calling function will never change after execution of function. For example: #include<iostream.h> void swap(int a, int b) int temp; temp=a; a=b; b=temp; int a,b; cout<<"enter two numbers:"; cin>>a>>b; swap(a, b); cout<< a= <<a<< b= <<b; Call By Reference In call by reference pass reference when call function. The formal arguments in the called function become aliases to the actual argument in the calling function. In call by reference the original value in calling function will change after execution of function. For example: #include<iostream.h> void swap(int &a, int &b) int temp; temp=a; a=b; b=temp; int a,b; cout<<"enter two numbers:"; cin>>a>>b; swap(a, b); cout<< a= <<a<< b= <<b; 2. Explain return by reference A function can also return reference. 1 Dept: CE Programming In C++ ( ) Nitin Rola

2 int & max(int &x, int &y) if(x > y) return x; else return y; Now max function will return reference of x or y. 3. What is inline function? Explain with example. The functions can be made inline by adding prefix inline to the function definition. An inline function is a function that is expanded in line when it is invoked. The complier replaces the function call with the corresponding function code. Inline function saves time of calling function, saving registers, pushing arguments onto the stack and returning from function. We should be careful while using inline function. If function has 1 or 2 lines of code and simple expressions then only it should be used. Inline expansion may not work in following situations, 1) If a loop, a switch or a goto exists in function body. 2) For function is not returning any value, if a return statement exists. 3) If function contains static variables. 4) If function is recursive. #include<iostream.h> inline int cube(int n) return n*n*n; int c; c = cube(10); cout<<c; Function call is replaced with expression so c = cube(10); becomes c=10*10*10; at compile time. Disadvantage: It makes the program to take up more memory because the statements that define the inline function are reproduced at each point where the function is called. 4. Default Arguments C++ allows us to call a function without specifying all its arguments. In such cases, the function assigns a default value to the parameter which does not have a matching argument in the function call. Default values are specified when the function is declared. We must add default arguments from right to left. We cannot provide a default value to a particular argument in the middle of an argument list. 2 Dept: CE Programming In C++ ( ) Nitin Rola

3 Default arguments are useful in situations where some arguments always have the same value. E.g. passing marks. Legal and illegal default arguments void f(int a, int b, int c=0); // legal void f(int a, int b=0, int c=0); // legal void f(int a=0, int b, int c=0); // illegal void f(int a=0, int b, int c); // illegal void f(int a=0, int b=0, int c=0); // legal #include <iostream.h> void f(int a=0, int b=0) cout << "a= " << a << ", b= " << b; cout << '\n'; f(); f(10); f(10, 99); Output: a=0,b=0 a=10,b=0 a=10, b=99 5. Explain function overloading with example. Function overloading is compile time polymorphism. Function overloading is the practice of declaring the same function with different signatures. The same function name will be used with different number of parameters and parameters of different type. Overloading of functions with different return types is not allowed. Compiler identifies which function should be called out of many using the type and number of arguments. A function is overloaded when same name is given to different functions. However, the two functions with the same name must differ in at least one of the following, a) The number of parameters b) The data type of parameters c) The order of appearance #include <iostream.h> void Add(int num1, int num2)\\ Function 1: Receives 2 integer parameters cout<<num1 + num2 <<endl; void Add(float num1, float num2)\\function 2: Receives 2 float parameters. cout<<num1 + num2 <<endl; 3 Dept: CE Programming In C++ ( ) Nitin Rola

4 void Add(int num1, int num2, int num3)\\function 3: Receives 3 int parameters cout<<num1 + num2 + num3 <<endl; float a=10.5,b=20.5; Add(10,20); \\ Calls function 1 Add(a,b); \\ Calls function 2 Add(1,2,3); \\ Calls function 3 6. Explain Const argument Function should not modify const argument. Compiler will generate error when condition is violated. int length(const string &s); int trial(const int a=10); 7. Class v/s Structure Class Structure 1. By default members of class are private. 1. By default members of structure are public. 2. class student int rollno; void getdata(); ; 8. Explain Class with example 2. struct student int rollno; void getdata(); ; A class is a template that specifies the attributes and behavior of things or objects. A class is a blueprint or prototype from which objects are created. A class is the implementation of an abstract data type (ADT). It defines attributes and methods which implement the data structure and operations of the ADT, respectively. The General Form of a Class class classname Datatype variable1; Datatype variable2; //... Datatype variablen; Public: Returntype methodname1(parameter-list) // body of method Returntype methodname2(parameter-list) // body of methodanguage Returntype methodnamen(parameter-list) // body of method 4 Dept: CE Programming In C++ ( ) Nitin Rola

5 A class is declared by use of the class keyword. The data, or variables, defined within a class are called instance variables. The code is contained within methods. Collectively, the methods and variables defined within a class are called members of the class. Variables defined within a class are called instance variables because each instance of the class (that is, each object of the class) contains its own copy of these variables. Thus, the data for one object is separate and unique from the data for another. Example class Box double width; double height; double depth; void volume() cout<<"volume is "; cout<<(width * height * depth)<<endl; 9. Creating Objects We can create by using class name. Syntax: class_name Object_name; Box b Here b is a object of class Box and Box is datatype of object b; 10. Introducing Methods General form of a method: type name(parameter-list) // body of method Here, type specifies the type of data returned by the method. This can be any valid type, including class types that you create. If the method does not return a value, its return type must be void. The name of the method is specified by name. This can be any legal identifier other than those already used by other items within the current scope. The parameter-list is a sequence of type and identifier pairs separated by commas. Parameters are essentially variables that receive the value of the arguments passed to the method when it is called. If the method has no parameters, then the parameter list will be empty. Return value Methods that have a return type other than void return a value to the calling routine using the following form of the return statement: return value; Here, value is the value returned. Example class Box double width; double height; double depth; double volume() 5 Dept: CE Programming In C++ ( ) Nitin Rola

6 return width * height * depth; 11. Explain Memory allocation for objects The memory space for objects is allocated when they are declared and not when the class is specified. This is partly true. The member function are created and placed in the memory space only once when they are defined as a part of a class specification. All the objects belonging to that class use the same member functions; no separate space is allotted when objects are created. Only space for member variables is allocated separately for each object Common for all objects Member funcion1 Memory created when functions Member funcion2 defined Object1 Object2 Object3 Member variable1 Member variable1 Member variable1 Member variable2 Member variable2 Member variable2 Memory created when objects defined 12. What is friend function? Explain with example. A friend function is a function which is declared using friend keyword. It is not a member of the class but it has access to the private and protected members of the class. It is not in the scope of the class to which it has been declared as friend. It cannot access the member names directly. It can be declared either in public or private part of the class. It is not a member of the class so it cannot be called using the object. Usually, it has the objects as arguments. It is normal external function which is given special access privileges. Syntax: class ABC ; friend void xyz(void); // declaration 6 Dept: CE Programming In C++ ( ) Nitin Rola

7 void xyz(void) //definition Set of statements; xyz() //call #include<iostream.h> #include<conio.h> class numbers int num1, num2; void setdata(int a, int b); friend int add(numbers N); ; void numbers :: setdata(int a, int b) num1=a; num2=b; int add(numbers N) return (N.num1+N.num2); numbers N1; N1.setdata(10,20); cout<< Sum = <<add(n1); add is a friend function of the class numbers so it can access all members of the class (private, public and protected). Member functions of one class can be made friend function of another class, like class X int f(); class Y friend int X :: f(); The function f is a member of class X and a friend of class Y. We can declare all the member functions of one class as the friend functions of another class. In such cases, the class is called a friend class, like class X is the friend class of class Z class Z 7 Dept: CE Programming In C++ ( ) Nitin Rola

8 friend class X;. 13. Explain various type of Access modifier (specifier) in C++. OR Explain various scope of class. C++ has three access modifiers namely private, protected and public. Private: Private members of the class can be accessed within the class and from member functions of the class. They cannot be accessed outside the class or from other programs, not even from inherited class. Encapsulation is possible due to the private access modifier. If one tries to access the private members outside the class then it results in a compile time error. Protected: This access modifier plays a key role in inheritance. Protected members of the class can be accessed within the class and from derived class but cannot be accessed from any other class or program. It works like public for derived class and private for other programs Public: Public members of the class are accessible by any program from anywhere. There are no restrictions for accessing public members of a class. Class members that allow manipulating or accessing the class data are made public. class ABC int A; int GetA() return A; // private variable by default // private method by default private: int B; int GetB() return B; protected: int C; int GetC() return C; int D; int GetD() return D; // private variable // private method // protected variable // protected method // public variable // public method ; class XYZ : public ABC //A, B, GetA(),GetB() cannot be accessed from here because they are private //C, GetC() can be accessed from here because they are protected ; //D, GetD() can be accessed from here and anywhere because they are public 8 Dept: CE Programming In C++ ( ) Nitin Rola

9 ABC a; a.d = 5; cout << a.getd(); a.a = 2; cout << a.getb(); a.c = 2; // can be accessed because D is public // can be accessed because GetD() is public // cannot be accessed because A is private // cannot be accessed because GetB() is private // cannot be accessed because C is protected 14. Explain Static data members and static member functions with example. Static data members Data members of the class which are shared by all objects are known as static data members. Only one copy of a static variable is maintained by the class and it is common for all objects. Static members are declared inside the class and defined outside the class. It is initialized to zero when the first object of its class is created. No other initialization is permitted. It is visible only within the class but its lifetime is the entire program. Static members are generally used to maintain values common to the entire class. #include<iostream.h> #include<conio.h> class item int number; static int count; void getdata(int a) number = a; count++; void getcount() cout<< Count : <<count; ; int item :: count; item a,b,c; a.getdata(100); b.getdata(200); c.getdata(300); a.getcount(); b.getcount(); c.getcount(); \\ static variable declaration \\ static variable definition Object a Object b Object a, b and c have separate storage area for variable number but they share common storage area for count variable Static member functions Static member functions are associated with a class, not with any object. Object c 9 Dept: CE Programming In C++ ( ) Nitin Rola count 300

10 They can be invoked using class name, not object. They can access only static members of the class. They cannot be virtual. They cannot be declared as constant or volatile. A static member function can be called, even when a class is not instantiated. There cannot be static and non-static version of the same function. A static member function does not have this pointer. Syntax: classname:: functionname #include<iostream.h> #include<conio.h> class item int number; static int count; void getdata(int a) number = a; count++; static void getcount() cout<< Count : <<count; ; int item :: count; item a,b,c; a.getdata(100); b.getdata(200); c.getdata(300); item::getcount(); 15. Explain nesting of member functions. A member function can be called by using its name inside another function of the same class is known as a nesting of member function For example: class sample int a; pulibc : void getdata() cout<< Enter the value of a ; cin>>a; void putdata() getdata() //nesting of member function cout<< the value of a= <<a; 10 Dept: CE Programming In C++ ( ) Nitin Rola

11 ; sample s; s.putdata(); When we call putdata() function, the control will jump to the definition of putdata function and from this definition control will jump to the definition of getdata() function when detect call statement of getdata(). 16. Differentiate public member function and private member function by proper example. We cannot call private member function using object, where as we can public member function. A private member function can only be called by another member function of same class. To call private member function, we have to use nesting of member function. For example: #include <iostream.h> #include <conio.h> class sample int a; void read() //private member function cout<<"enter the value of a"; cin>>a; void disp() //public member function read(); //call private member function cout<<"the value of a="<<a; ; sample S; S.disp(); //call public member function /* OUTPUT Enter the value of a10 The value of a=10 */ 17. Write a program to demonstrate the array of object. we can also create array of object like as array of any type of variable. #include <iostream.h> class sample int roll_no; char name[20]; void read() 11 Dept: CE Programming In C++ ( ) Nitin Rola

12 cout<<"enter the Roll number="; cin>>roll_no; cout<<"enter the Name="; cin>>name; void disp() cout<<"\nroll_no="<<roll_no<<"\tname="<<name; ; void main() sample S[5]; int i; for(i=0;i<5;i++) S[i].read(); for(i=0;i<5;i++) S[i].disp(); 18. Making an outside function inline Define member function outside the class to separate the detail of implementation from the class. We can make outside function inline by following method. class trial int number; void getdata(int a); ; inline void trial:: getdata(int a) number=a; 19 Explain array within a class We can also declare and use array within class like as outside class. #include <iostream.h> #include <conio.h> class trial int a[5]; void getdata() for(int i=0;i<5;i++) cin>>a[i]; void putdata() for(int i=0;i<5;i++) cout<<a[i]; ; 12 Dept: CE Programming In C++ ( ) Nitin Rola

13 void main() trial t; clrscr(); t.getdata(); t.putdata(); 20 Explain passing objects as an argument and return object We can pass object as an argument like any other data type and also we can return it. We can pass by two methods: 1. A copy of the entire object is passed to the function. 2. Only the address of the object is transferred to the function. We can return object by return keyword and set return type of function is class_name. #include <iostream.h> #include <conio.h> class trial int a; void getdata() a=10; void putdata() cout<<"\nvalue of a="<<a; trial square(trial tt) trial ttt; a=tt.a*tt.a; ttt.a=tt.a*tt.a*tt.a; return ttt; ; void main() trial t1,t2,t3; clrscr(); t1.getdata(); t3=t2.square(t1); t1.putdata(); t2.putdata(); t3.putdata(); Output Value of a=10 Value of a=100 Value of a= Dept: CE Programming In C++ ( ) Nitin Rola

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). UNITII Classes Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). It s a User Defined Data-type. The Data declared in a Class are called Data- Members

More information

Downloaded from

Downloaded from Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather

More information

cout<< \n Enter values for a and b... ; cin>>a>>b;

cout<< \n Enter values for a and b... ; cin>>a>>b; CHAPTER 8 CONSTRUCTORS AND DESTRUCTORS 8.1 Introduction When an instance of a class comes into scope, a special function called the constructor gets executed. The constructor function initializes the class

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3 Class A class is a template that specifies the attributes and behavior of things or objects. A class is a blueprint or prototype from which objects are created. A class is the implementation of an abstract

More information

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer: Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing

Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing Classes and Objects Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing Classes i)theentiresetofdataandcodeofanobjectcanbemadeauserdefineddatatypewiththehelpofaclass.

More information

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently.

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently. OBJECTS An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently. Objects that work in associations with each others. Objects that frequently

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

Chapter-13 USER DEFINED FUNCTIONS

Chapter-13 USER DEFINED FUNCTIONS Chapter-13 USER DEFINED FUNCTIONS Definition: User-defined function is a function defined by the user to solve his/her problem. Such a function can be called (or invoked) from anywhere and any number of

More information

CSE202-Lec#4. CSE202 C++ Programming

CSE202-Lec#4. CSE202 C++ Programming CSE202-Lec#4 Functions and input/output streams @LPU CSE202 C++ Programming Outline Creating User Defined Functions Functions With Default Arguments Inline Functions @LPU CSE202 C++ Programming What is

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

Bangalore South Campus

Bangalore South Campus INTERNAL ASSESSMENT TEST 1(Solutions) Date :01/03/2017 Max Marks: 40 Subject& Code: Object Oriented Concepts (15CS45) Sem:VII ISE Name of the faculty: Miss Pragyaa Time: 90 minutes Note: Answer to all

More information

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI 621213 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Sub code: CS2203 SEM: III Sub Name: Object Oriented Programming Year: II UNIT-I PART-A 1. What is

More information

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

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013 Q.2 a. Discuss the fundamental features of the object oriented programming. The fundamentals features of the OOPs are the following: (i) Encapsulation: It is a mechanism that associates the code and data

More information

What Is a Function? Illustration of Program Flow

What Is a Function? Illustration of Program Flow What Is a Function? A function is, a subprogram that can act on data and return a value Each function has its own name, and when that name is encountered, the execution of the program branches to the body

More information

Solution: A pointer is a variable that holds the address of another object (data item) rather than a value.

Solution: A pointer is a variable that holds the address of another object (data item) rather than a value. 1. What is a pointer? A pointer is a variable that holds the address of another object (data item) rather than a value. 2. What is base address? The address of the nth element can be represented as (a+n-1)

More information

Developed By Strawberry

Developed By Strawberry Experiment No. 3 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study below concepts of classes and objects 1. Array of Objects 2. Objects as a function argument 3. Static Members P1: Define a

More information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP THROUGH C++(R16) int *x; float *f; char *c; What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,

More information

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

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

UNIT III (PART-II) & UNIT IV(PART-I)

UNIT III (PART-II) & UNIT IV(PART-I) UNIT III (PART-II) & UNIT IV(PART-I) Function: it is defined as self contained block of code to perform a task. Functions can be categorized to system-defined functions and user-defined functions. System

More information

Functions. Introduction :

Functions. Introduction : Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In

More information

POINTERS INTRODUCTION: A pointer is a variable that holds (or whose value is) the memory address of another variable and provides an indirect way of accessing data in memory. The main memory (RAM) of computer

More information

OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES

OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES Polymorphism: It allows a single name/operator to be associated with different operations depending on the type of data passed to it. An operation may exhibit different behaviors in different instances.

More information

C++ 8. Constructors and Destructors

C++ 8. Constructors and Destructors 8. Constructors and Destructors C++ 1. When an instance of a class comes into scope, the function that executed is. a) Destructors b) Constructors c) Inline d) Friend 2. When a class object goes out of

More information

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation. Lab 4 Functions Introduction: A function : is a collection of statements that are grouped together to perform an operation. The following is its format: type name ( parameter1, parameter2,...) { statements

More information

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

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction

More information

DELHI PUBLIC SCHOOL TAPI

DELHI PUBLIC SCHOOL TAPI Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

Module Operator Overloading and Type Conversion. Table of Contents

Module Operator Overloading and Type Conversion. Table of Contents 1 Module - 33 Operator Overloading and Type Conversion Table of Contents 1. Introduction 2. Operator Overloading 3. this pointer 4. Overloading Unary Operators 5. Overloading Binary Operators 6. Overloading

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

DE122/DC106 Object Oriented Programming with C++ DEC 2014

DE122/DC106 Object Oriented Programming with C++ DEC 2014 Q.2 a. Distinguish between Procedure-oriented programming and Object- Oriented Programming. Procedure-oriented Programming basically consists of writing a list of instructions for the computer to follow

More information

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

MEMORY ADDRESS _ REPRESENTATION OF BYTES AND ITS ADDRESSES

MEMORY ADDRESS _ REPRESENTATION OF BYTES AND ITS ADDRESSES [1] ~~~~~~~~~~~~~~~~~ POINTER A pointers is a variable that holds a memory address, usually the location of another variable in memory. IMPORTANT FEATURES OF POINTERS (1) provide the means through which

More information

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

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Padasalai.Net s Model Question Paper

Padasalai.Net s Model Question Paper Padasalai.Net s Model Question Paper STD: XII VOLUME - 2 MARKS: 150 SUB: COMPUTER SCIENCE TIME: 3 HRS PART I Choose the correct answer: 75 X 1 = 75 1. Which of the following is an object oriented programming

More information

Sample Paper Class XI Subject Computer Sience UNIT TEST II

Sample Paper Class XI Subject Computer Sience UNIT TEST II Sample Paper Class XI Subject Computer Sience UNIT TEST II (General OOP concept, Getting Started With C++, Data Handling and Programming Paradigm) TIME: 1.30 Hrs Max Marks: 40 ALL QUESTIONS ARE COMPULSURY.

More information

IBS Technical Interview Questions

IBS Technical Interview Questions IBS Technical Interview Questions IBS Technical interview Questions mainly from C,C++ and DBMS. In Technical interview, be prepared about your favorite subject. Suppose they asked, Which is your favorite

More information

Implementing Abstract Data Types (ADT) using Classes

Implementing Abstract Data Types (ADT) using Classes Implementing Abstract Data Types (ADT) using Classes Class Definition class classname { public: //public member functions private: //private data members and member functions }; // Note the semicolon!

More information

END TERM EXAMINATION

END TERM EXAMINATION END TERM EXAMINATION THIRD SEMESTER [BCA] DECEMBER 2007 Paper Code: BCA 209 Subject: Object Oriented Programming Time: 3 hours Maximum Marks: 75 Note: Attempt all questions. Internal choice is indicated.

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of ECE INTERNAL ASSESSMENT TEST 2 Date : 03/10/2017 Marks: 40 Subject & Code : Object Oriented Programming

More information

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

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

COMPUTER SCIENCE (083)

COMPUTER SCIENCE (083) Roll No. Code : 112012-083 Please check that this question paper contains 7 questions and 8 printed pages. CLASS-XI COMPUTER SCIENCE (083) Time Allowed : 3 Hrs. Maximum Marks : 70 General Instructions

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3 Programming in C main Level 2 Level 2 Level 2 Level 3 Level 3 1 Programmer-Defined Functions Modularize with building blocks of programs Divide and Conquer Construct a program from smaller pieces or components

More information

UNIT POLYMORPHISM

UNIT POLYMORPHISM UNIT 3 ---- POLYMORPHISM CONTENTS 3.1. ADT Conversions 3.2. Overloading 3.3. Overloading Operators 3.4. Unary Operator Overloading 3.5. Binary Operator Overloading 3.6. Function Selection 3.7. Pointer

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7

Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7 Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7 CS202 7-1 Relationship of Objects Friends, Nesting Static Members Template Functions and Classes Reusing Code Template Specializations

More information

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016 Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with

More information

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

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT Scheme and Solution -T2 Date : 30/3/2015 Max Marks : 50 Subject & Code : Object Oriented Programming with C++(13MCA22 ) Name of faculty : R.Jayanthi Time : 11.30 am -1.00 Pm Answer

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE UNIT I 1. State the characteristics of procedure oriented programming. Emphasis is on algorithm. Large

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

Object Oriented Programming

Object Oriented Programming F.Y. B.Sc.(IT) : Sem. II Object Oriented Programming Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1(a) Explain encapsulation? [5] (A) The wrapping

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

Introduction Of Classes ( OOPS )

Introduction Of Classes ( OOPS ) Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

DE70/DC56/DE122/DC106 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2015

DE70/DC56/DE122/DC106 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2015 Q.2 a. Define Object-oriented programming. List and explain various features of Object-oriented programming paradigm. (8) 1. Inheritance: Inheritance as the name suggests is the concept of inheriting or

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

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

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

DE70/DC56 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014

DE70/DC56 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014 Q.2a. Discuss the fundamental features of the object oriented programming. Answer The fundamentals features of the OOPs are the following: Encapsulation: It is a mechanism that associates the code and

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

CLASSES AND OBJECT CHAPTER 04 CLASS XII

CLASSES AND OBJECT CHAPTER 04 CLASS XII CLASSES AND OBJECT CHAPTER 04 CLASS XII Class Why Class? Class is the way to represent Real-World entity that have both the Characteristics and Behaviors of an entity. Implementation of Class class class_name

More information

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf("%f\n", *j);

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf(%f\n, *j); You try /* EXAMPLE 3 */ #include int main(void) { char ch = 'c'; char *chptr = &ch; int i = 20; int *intptr = &i; float f = 1.20000; float *fptr = &f; char *ptr = "I am a string"; /* EXAMPLE

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

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

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented

More information

QUESTIONS AND ANSWERS. 1) To access a global variable when there is a local variable with same name:

QUESTIONS AND ANSWERS. 1) To access a global variable when there is a local variable with same name: Q1. List the usage of :: operator in C++. [AYUSH BANIK -1741012] QUESTIONS AND ANSWERS 1) To access a global variable when there is a local variable with same name: int x; // Global x int main() int x

More information

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University (5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming

More information

UNIT 1 OVERVIEW LECTURE NOTES

UNIT 1 OVERVIEW LECTURE NOTES UNIT 1 OVERVIEW LECTURE NOTES OBJECT-ORIENTED PROGRAMMING IN C++ Object Oriented Programming is a method of visualizing and programming the problem in a global way. Object oriented programming is a technique

More information

PROGRAMMING IN C++ COURSE CONTENT

PROGRAMMING IN C++ COURSE CONTENT PROGRAMMING IN C++ 1 COURSE CONTENT UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 2 1.1 Procedure oriented Programming 1.2 Object oriented programming paradigm 1.3 Basic concepts of Object Oriented

More information

An Introduction to C++

An Introduction to C++ An Introduction to C++ The workers and professionals of the world will soon be divided into two distinct groups: those who will control computers and those who will be controlled by the computers. It would

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Parameter Passing in Function Calls Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

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

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

More information

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

More information

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Chapter 10 Introduction to Classes

Chapter 10 Introduction to Classes C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this

More information

ADTs & Classes. An introduction

ADTs & Classes. An introduction ADTs & Classes An introduction Quick review of OOP Object: combination of: data structures (describe object attributes) functions (describe object behaviors) Class: C++ mechanism used to represent an object

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Storage Classes Scope Rules Functions with Empty Parameter Lists Inline Functions References and Reference Parameters Default Arguments Unary Scope Resolution Operator Function

More information

Binding and Variables

Binding and Variables Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

More information

OBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2

OBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2 UNIT-2 Syllabus for Unit-2 Introduction, Need of operator overloading, overloading the assignment, binary and unary operators, overloading using friends, rules for operator overloading, type conversions

More information