southcity.thelps.edu.insouthcity.thelps.edu.in/uploadedfiles/updatedirectory/cs notes...  · web...

32
SUMMARY NOTES ::COMPUTER SCIENCE:: XII OBJECT-ORIENTED PROGRAMMING (OOP) An object-oriented programming (OOP) is a programming language model which is organized around "objects" rather than "actions" and data rather than logic. The whole idea behind anobject oriented model is to make programming closer to they real world thereby making it a very natural way of programming. The core of pure object- oriented programming is to combine into a single unit both data and functions or methods that operate on that data. Simula was the first object-oriented programming language. Java, Python, C+ +, Visual Basic, .NET and Ruby are the most popular OOP languages today. The basic concepts related to OOP are as follows: 1. Objects 2. Classes 3. Encapsulation 4. Abstraction 5. Data Hiding 6. Polymorphism 7. Inheritance Object Oriented Programming follows bottom up approach in program design and emphasizes on safety and security of data.. Object Oriented programming has following advantages: Simplicity: The objects in case of OOP are close to the real world objects, so the complexity of the program is reduced making the program structure very clear and simple. Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods. Extensibility and Maintainability: It is quite easy to add new features and extend the program in case of object oriented programming. It can be simply done by introducing a few new objects and modifying some existing ones. The original base class need not be modified at all. Re-usability: Objects can be reused in different programs. The class definitions can be reused in various applications. Inheritance makes it possible to define subclasses of data objects that share some or all of the main class characteristics. Security: Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption. FEATURES OF OBJECT ORIENTED PROGRAMMING: An object is the basic key concept of Object Oriented Programming. As mentioned before it can be anything around us - a person, place, any activity or any other identifiable entity. Every object is characterised by: Identity: This is the name that identifies an object. For example a Student is the name given to anybody who is pursuing a course. Or an i- phone is a mobile phone that has been launched by Apple Inc. Properties: These are the features or attributes of the object. For example

Upload: lamdien

Post on 03-Mar-2019

214 views

Category:

Documents


0 download

TRANSCRIPT

SUMMARY NOTES ::COMPUTER SCIENCE:: XII

OBJECT-ORIENTED PROGRAMMING (OOP)An object-oriented programming (OOP) is a programming language model which is organized around"objects" rather than "actions" and data rather than logic.The whole idea behind anobject oriented model is to make programming closer to they real world thereby making it a very natural way of programming. The core of pure object-oriented programming is to combine into a single unit bothdata and functions or methods that operate on that data.Simula was the first object-oriented programming language. Java, Python, C++, Visual Basic, .NET andRuby are the most popular OOP languages today.The basic concepts related to OOP are as follows:1. Objects2. Classes3. Encapsulation4. Abstraction5. Data Hiding6. Polymorphism7. InheritanceObject Oriented Programming follows bottom up approach in program design and emphasizes on safety and security of data..Object Oriented programming has following advantages:Simplicity: The objects in case of OOP are close to the real world objects, so the complexity of the program is reduced making the program structure very clear and simple.Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.Extensibility and Maintainability: It is quite easy to add new features and extend the program in case of object oriented programming. It can be simply done by introducing a few new objects and modifying

some existing ones. The original base class need not be modified at all.Re-usability: Objects can be reused in different programs. The class definitions can be reused in various applications. Inheritance makes it possible to define subclasses of data objects that share some or all of the main class characteristics.Security: Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption.FEATURES OF OBJECT ORIENTED PROGRAMMING:An object is the basic key concept of Object Oriented Programming. As mentioned before it can be anything around us - a person, place, any activity or any other identifiable entity. Every object is characterised by:Identity: This is the name that identifies an object. For example a Student is the name given to anybody who is pursuing a course. Or an i-phone is a mobile phone that has been launched by Apple Inc.Properties: These are the features or attributes of the object. For example a student will have his name age, class, date of birth etc. as his attributes or properties. A mobile phone has model, color, price as its properties.Behaviour: The behaviour of an object signifies what all functions an object can perform. For example a student can pass or fail the examination. A mobile phone can click and store photographs (behave like a camera).A class is group of objects with same attributes and common behaviours. It is basically a blueprint to create objects. An object is a basic key concept of OOP but classes provide an ability to generalize similar type of objects. Both data and functions operating on the data are bundled as a unit in a class for the same category of objects.A real instance of a class is called an object and creating the new object is called instantiationInheritance:

Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class.Derived class is also known as a child class or sub class. Inheritance helps in reusability of code , thus reducing the overall size of the programData Abstraction:It refers to the act of representing essential features without including the background details .Example : For driving , only accelerator, clutch and brake controls need to be learnt rather than working of engine and other details.Data Encapsulation:It means wrapping up data and associated functions into one single unit called class.A class groups its members into three sections :public, private and protected, where private and protected members remain hidden from outside world and thereby helps in implementing data hiding.Modularity :The act of partitioning a complex program into simpler fragments called modules is called as modularity.It reduces the complexity to some degree and It creates a number of well defined boundaries within the program .Polymorphism:Poly means many and morphs mean form, so polymorphism means one name multiple forms.It is the ability for a message or data to be processed in more than one form.C++ implements Polymorhism through Function Overloading , Operator overloading and Virtual functions .

Static and Dynamic Binding:Binding is the process of linking the function call to the function definition. The body of the function is executed when the function call is made. Binding can be of two types:Static Binding: In this type of binding, the linking of function call to the function definition is done during compilation of the program.Dynamic Binding: In this type of binding, linking of a function call to the function definition is done at run time. That means the code of the function that is to be linked with function call is unknown until it is executed.

Dynamic binding of functions makes the programs more flexible. You will learn more on dynamic binding in the next chapter.Access specifiers in Classes:Access specifiers are used to identify access rights for the data and member functions of the class.There are three main types of access specifiers in C++ programming language:privateClass members declared as private can be used only by member functions and friends (classes or functions) of the class.protectedClass members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class. Class members declared as protected can be used by member functionspublicClass members declared as public can be used by any function.Importance of Access SpecifiersAccess control helps prevent you from using objects in ways they were not intended to be used. Thus it helps in implementing data hiding and data abstraction.INLINE FUNCTIONSInline functions definition starts with keyword inlineThe compiler replaces the function call statement with the function code itself(expansion) and then compiles the entire code.They run little faster than normal functions as function calling overheads are saved.A function can be declared inline by placing the keyword inline before it.Exampleinline void Square (int a){ cout<<a*a;}void main(){.Square(4); { cout <<4*4;}Square(8) ; { cout <<8*8; }}CONSTRUCTORS :A member function with the same as its class is called Constructor and it is used to initialize the object of that class with a legal initial value.

Example :class Student{int rollno;float marks;public:student( ) //Constructor{rollno=0;marks=0.0;}//other public members};1. Default Constructor:A constructor that accepts no parameter is called the Default Constructor. If you don't declare a constructor or a destructor, the compiler makes one for you. The default constructor and destructor take no arguments and do nothing.2. Parameterized Constructors:A constructor that accepts parameters for its invocation is known as parameterized Constructors also called as Regular Constructors.DESTRUCTORS:A destructor is also a member function whose name is the same as the class name but is preceded by tilde(“~”).It is automatically by the compiler when an object is destroyed.Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed.A destructor is called for a class object when that object passes out of scope or is explicitly deleted.Example :class TEST{ int Regno,Max,Min,Score;Public:TEST( ) // Default Constructor{ }TEST (int Pregno,int Pscore) // Parameterized Constructor{Regno = Pregno ;Max=100;Max=100;Min=40;Score=Pscore;}~ TEST ( ) // Destructor{ Cout<<”TEST Over”<<endl;}};The following points apply to constructors and destructors:

Constructors and destructors do not have return type, not even void nor can they return values.References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.Constructors cannot be declared with the keyword virtual.Constructors and destructors cannot be declared static, const, or volatile.Unions cannot contain class objects that have constructors or destructors.The compiler automatically calls constructors when defining class objects and calls destructors when class objects go out of scope.Derived classes do not inherit constructors or destructors from their base classes, but they do call the constructor and destructor of base classes.The default destructor calls the destructors of the base class and members of the derived class.The destructors of base classes and members are called in the reverse order of the completion of their constructor:The destructor for a class object is called before destructors for members and bases are called.Copy ConstructorA copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object.A copy constructor is a constructor of the form classname(classname &).The compiler will use the copy constructors whenever you initialize an instance using values of another instance of the same type.Copying of objects is achieved by the use of a copy constructor and a assignment operator.Example :class Sample{ int i, j;}public:Sample(int a, int b) // constructor{ i=a;j=b;}Sample (Sample & s) //copy constructor{ j=s.j ; i=s.j;Cout <<”\n Copy constructor working \n”;}void print (void){cout <<i<< j<< ”\n”;}:};The following cases may result in a call to a copy constructor:

*When an object is passed by value to a function:If a function with the following prototype :void cpyfunc(Sample ); // Sample is a classthen for the following function callcpyfunc(obj1); // obj1 is an object of Sample type*When a function returns an object :When an object is returned by a function the copy constructor is invokedSample cpyfunc(); // Sample is a class and it is return type of cpyfunc()If func cpyfunc() is called by the following statementobj2 = cpyfunc();INHERITANCEInheritance is the process by which new classes called derived classes are created from existing classes called base classes.The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on.Features or Advantages of Inheritance:Reusability of CodeSaves Time and EffortFaster development, easier maintenance and easy to extendCapable of expressing the inheritance relationship and its transitive nature whichensures closeness with real world problems .Access Control and Inheritance:A derived class can access all the non-private members of its base class. Thus base-class members that should not be accessible to the member functions of derived classes should be declared private in the base class.A derived class inherits all base class methods with the following exceptions:Constructors, destructors and copy constructors of the base class.Overloaded operators of the base class.The friend functions of the base class.TYPES OF INHERITANCE1. Single class Inheritance:Single inheritance is the one where you have a single base class and a single derived class.

2.Multilevel Inheritance:In Multi level inheritance, a subclass inherits from a class that itself inherits from another class. It represent transitive nature of classes.

3. Multiple Inheritance:In Multiple inheritances, a derived class inherits from multiple base classes. It has properties of both the base classes.

4. Hierarchical Inheritance:In hierarchical Inheritance, it's like an inverted tree. So multiple classes inherit from a single base class.

5. Hybrid Inheritance:It combines two or more forms of inheritance .In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions.Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.Ambiguity problem can be solved by using virtual base classes

B(derived class)

A(base class)

C (derived class)

B (derived class/ base class to c)

A(base class)

C

BA

B C

A

B C

A

DATA FILE HANDLING IN C++File• A file is a stream of bytes stored on some secondary storage devices.• Text file: A text file stores information in readable and printable form. Each line of text is terminated with an EOL (End of Line) character.• Binary file: A binary file contains information in the non-readable form i.e. in the same format in which it is held in memory.File Stream• Stream: A stream is a general term used to name flow of data. Different streams are used to represent different kinds of data flow.• There are three file I/O classes used for file read / write operations.o ifstream - can be used for read operations.o ofstream - can be used for write operations.o fstream - can be used for both read & write operations.File modes:• ios::out It open file in output mode (i.e write mode) and place the file pointer in beginning, if file already exist it will overwrite the file.• ios::in It open file in input mode(read mode) and permit reading from the file.• ios::app It open the file in write mode, and place file pointer at the end of file i.e to add new contents and retains previous contents. If file does not exist it will create a new file.• ios::ate It open the file in write or read mode, and place file pointer at the end of file i.e input/ output operations can performed anywhere in the file.• ios::trunc It truncates the existing file (empties the file).• ios::nocreate If file does not exist this file mode ensures that no file is created and open() fails.• ios::noreplace If file does not exist, a new file gets created but if the file already exists, the open() fails.• ios::binary Opens a file in binary mode.Text File functions:Char I/O :

get() – read a single character from text file and store in a buffer.e.g file.get(ch);put() - writing a single character in textfile e.g. file.put(ch);getline() - read a line of text from text file store in a buffer.e.g file.getline(s,80);We can also use file>>ch for reading and file<<ch writing in text file. But >> operator does not accept white spaces.Binary file functions:read()- read a block of binary data or reads a fixed number of bytes from the specifiedstream and store in a buffer.Syntax : Stream_object.read((char *)& Object, sizeof(Object));e.g file.read((char *)&s, sizeof(s));write() – write a block of binary data or writes fixed number of bytes from a specific memory location to the specified stream.Syntax : Stream_object.write((char *)& Object, sizeof(Object));e.g file.write((char *)&s, sizeof(s));Binary file functions:read()- read a block of binary data or reads a fixed number of bytes from the specified stream and store in a buffer.Syntax : Stream_object.read((char *)& Object, sizeof(Object));e.g file.read((char *)&s, sizeof(s));write() – write a block of binary data or writes fixed number of bytes from a specific memory location to the specified stream.Syntax : Stream_object.write((char *)& Object, sizeof(Object));e.g file.write((char *)&s, sizeof(s));seekg(): It places the file pointer to the specified position in a stream before input operation.Fileobject.Seekg(int,ios::beg);//sets get pointer int bytes from beginning of fileEg. Fileobject.seekg(20,ios::beg);// 20 bytes fom beginingFileobject.Seekg(int.ios::cur);// sets get pointer int bytes from current position of fileFileobject.Seekg(int,ios::end);// sets get pointer int bytes from end of file seekp(): It places the file pointer to the specified position in a stream before output operation. tellg(): This function returns the current position of the file pointer in a stream.

Fileobject.tellg() // returns the byte location in integerint p=fileobject.tellg(); tellp(): This function returns the current position of the file pointer in a stream.

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++MemoryMap :- Program Code : It holds the compiled code of the program.- Global Variables : They remain in the memory as long as program continues.- Stack : It is used for holding return addresses at function calls, arguments passed to the functions, local variables for functions. It also stores the current state of the CPU.- Heap : It is a region of free memory from which chunks of memory are allocated vi a DMA functions.StaticMemory Allocation : The amount of memory to be allocated is known in advance and it allocated during compilation, it is referred to as Static Memory Allocation.e.g. int a; // This will allocate 2 bytes for a during compilation.Dynamic Memory Allocation : The amount of memory to be allocated is not known beforehand rather it is required to allocated as and when required during runtime, it is referred to as dynamic memory allocation.C++ offers two operator for DMA – new and delete.e.g int *x =new int; float* y= new float; // dynamic allocationdelete x; delete y; //dynamic deallocationCreating Dynamic Array :Syntax : pointer-variable = new data-type [size];e.g. int * array = new int[10];Two dimensional array :int *arr, r, c;r = 5; c = 5;arr = new int [r * c];Now to read the element of array, you can use the following loops :For (int i = 0; i < r; i++){

cout << “\n Enter element in row “ << i + 1 << “ : “;For (int j=0; j < c; j++)cin >> arr [ i * c + j];}Free Store : It is a pool of unallocated heap memory given to a program that is used by the program for dynamic memory allocation during execution.Pointer arithmetic:Two arithmetic operations, addition and subtraction, may be performed on pointers.Base address : A pointer holds the address of the very first byte of the memory location where it is pointing to. The address of the first byte is known as BASE ADDRESS.

Q.How is *p different from **p ?Ans : *p means, it is a pointer pointing to a memory location storing a value in it. But **p means, it is a pointer pointing to another pointer which in turn points to a memory location storing a value in it.Q. How is &p different from *p ?Ans : &p gives us the address of variable p and *p. dereferences p and gives us the value stored in memory location pointed to by p.Q. How does the functioning of a function differ when(i) an object is passed by value ? (ii) an object is passed by reference ?Ans : (i) When an object is passed by value, the called function creates its own copy of theobject by just copying the contents of the passed object. It invokes the object’s copy constructor to create its copy of the object. However, the called function destroys its copy of the object by calling the destructor function ofthe object upon its termination.(i) When an object is passed by reference, the called function does not create its own copy of the passed object. Rather it refers to the original object using its reference or alias name. Therefore, neither constructor nor destructor function of the object is invoked in such a case.DATA STRUCTURESIn Computer Science, a data structure is a particular way of storing and organizing data in a computer sothat it can be used efficiently. Different kinds of data structures are suited to different kinds of

applications, and some are highly specialized to specific tasks. The data structure can be classified into following two types:Simple Data Structure: These data structures are normally built from primitive data types like integers,floats, characters. For example arrays and structure.Compound Data Structure: simple data structures can be combined in various ways to form morecomplex structure called compound structures. Linked Lists, Stack, Queues and Trees are examples ofcompound data structure.StackIn computer science, a stack is a last in, first out (LIFO) data structure. A stack can is characterized byonly two fundamental operations: push and pop. The push operation adds an item to the top of the stack.The pop operation removes an item from the top of the stackApplication of stacks in infix expression to postfix expression conversionInfix expression operand1 operator operand2 for example a+bPostfix expression operand1 operand2 operator for example ab+Prefix expression operator operand1 operand2 for example +abLinked listIn Computer Science, a linked list (or more clearly, "singly-linked list") is a data structure that consists ofa sequence of nodes each of which contains data and a pointer which points (i.e., a link) to the next nodein the sequence.QUEUEQueue is a linear data structure which follows First In First Out (FIFO) rule in which a new item is addedat the rear end and deletion of item is from the front end of the queue. In a FIFO data structure, the firstelement added to the queue will be the first one to be removed.

Boolean algebraRelation: In database, a relation means a 'table' (form of rows and columns).

Domain: A domain is the original sets of atomic values used to model data.Tuple: A row in a table.Attribute: A column in a table.Primary Key: A column or set of columns that uniquely identifies a row within a table is called primary key.Candidate Key: Candidate keys are set of fields (columns with unique values) in the relation that are eligible to act as a primary key.Alternate Key: Out of the candidate keys, after selecting a key as primary key, the remaining keys are called alternate key.DDL: Data Definition Language (DDL) or Data Description Language (DDL).DML: Data Manipulation Language (DML).String datatypes: CHAR, VARCHAR, VARCHAR2Numeric datatype: NUMBER, NUMERIC, INT, FLOAT, DECIMALDate: DATESelection: Selection in relational algebra returns those tuples (records) in a relation that fulfil a condition(Produce table containing subset of rows).Projection: Projection in relational algebra returns those columns in a relation that given in the attribute list (Produce table containing subset of columns).Union: The union operator is used to combine two or more tables. In the union operation, duplicate records will be automatically removed from the resultant table.Cartesian product: SQL joins are used to relate information in different tables. Cartesian product returns a number of rows equal to number of rows in the first table multiply by number of rows in the second table. At the same time, number of columns equal to number of columns in the first table added by number of columns in the second table.Operation in relational algebra:1. Selection2. Projection3. Union4. Cartesian ProductSelection in relational algebra returns those tuples(records) in a relation that fulfill a condition(Produce table containing subset of rows).σ condition (relation)

σ(rn>10)(student)Projection in relational algebra returns those columns in a relation that given in the attribute list (Produce table containing subset of columns).Syntax:attribute list(relation)Example:Adno,Name (S)unionThe union operator is used to combine two or more tables. Each table within the UNION should have the same number of columns, similar data types and also the columns must be in the same order. In the union operation, duplicate records will be automatically removed from the resultant table.Select * from a union select * from b;Cartesian product is a binary operation and is denoted by (x) Cartesian product returns a number of rows equal to number of rows in the first table multiply by number of rows in the second table. At the same time, number of columns equal to number of columns in the first table added by number of columns in the second table.Select * from a,b;Equi JoinEqui Joins are used to give information in different tables. It is a special type of join in which we use only equality operator.For exampleSELECT * FROM product, customer WHERE product.product_no = customer. procuct_no;(or)SELECT * FROM product p, customer c WHERE p.product_no=c.procuct_no;SQL Non-equi joinsThe non-equi join is a type of join in which, we use only relational operators except equal operator. These include >, <, >=, >= and !=.For exampleSELECT * FROM product,customer WHERE product.product_no!=customer.procuct_no;Arithmetic operator takes two operands and performs a mathematical calculation on them. However, they can be used only in SELECT command. The arithmetic operators used in SQL are:+ Addition- Subtraction* Multiplication/ Division

Relational operators are used to implement comparison between two operands. These operators can be used only in 'where clause'. Relational operators are -< less than> greater than< = less than or equal to> = greater than or equal to= equal to! = not equal toLIKE OPERATOR is used to search a value similar to specific pattern in a column using wildcard operator.There are two wildcard operators - percentage sign (%) and underscore ( _ ). The percentage sign represents zero, one, or multiple characters, while the underscore represents a single number or character.Display names, whose name's second letter is 'o'.SELECT name FROM student WHERE name LIKE "_ o%";IN: The IN operator allows us to specify multiple values in a WHERE clauseSELECT * FROM STUDENT WHERE SECTION IN(‘A’,’C’);BETWEEN: The BETWEEN operator is used to test whether or not a value (stated before the keyword BETWEEN) is "between" the two values stated after the keyword BETWEEN.SELECT * FROM student WHERE fees BETWEEN 2500 AND 3500;ORDER BY: This command is used to arrange values in ascending or descending order.

SELECT * FROM student ORDER BY fees ASC;SQL COMMANDS:CREATE TABLE: Used to create structure of the table.ALTER TABLE: Used to implement structure modification.DROP TABLE: To remove full structure.INSERT INTO: To add row values.SELECT: To display row or column information.DISTINCT: To select different information.Aggregate functions are used to implement calculation based upon a particular column. These functionsalways return a single value.MAX(): To select maximum value of a particular column.

MIN(): To select minimum value of a particular column.SUM(): To find total value of a particular column.AVG(): To find average value of a particular column.COUNT(): Number of records in the table.The SQL GROUP BY is a clause that enables SQL aggregate functions for grouping of information. (ie. GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups.). This clause is used whenever aggregate functions by group are required.Display number of students in each class.SELECT count (*), class FROM student GROUP BY class;2. Display sum of fees for each class.SELECT class, sum (fees) FROM student GROUP BY class;'HAVING' clauseAs mentioned earlier, the 'where' clause is used only to place condition on the selected columns, whereas the 'HAVING' clause is used to place condition on groups created by 'group by' clause, because here the 'WHERE' clause is not useable.Display sum of fees which is more than 5000 for each classSELECT class, sum (fees) FROM student GROUP BY class HAVING sum (fees)>5000;

BOOLEAN LOGICBoolean Algebra: is an algebra that deals with binary variables and logic operationsVariable: A variable is a symbol, usually an alphabet used to represent a logical quantity. It can have a 0 or 1 valueBoolean Function: consists of binary variable, constants 0 & 1, logic operation symbols, parenthesis and equal to operator.Complement: A complement is the inverse of a variable and is indicated by a' or bar over the variable.A binary variable is one that can assume one of the two values 0 and 1.Literal: A Literal is a variable or the complement of a variableTruth table: it provides the basic method of describing a Boolean function.Boolean Algebra is made up of

Elements - which are variables or constants with value 1 or 0.

Operators - which are And, Or and Not.

Axioms and Theorems.A boolean variable is a symbol used to represent a logical quantity. It will take value from the domain {0, 1},and boolean constant is single digit binary value (bit) viz. 0 or 1.There are three fundamental operators- AND, OR and NOT.Just like algebra, Boolean algebra also have axioms and theorems, which describe how logical quantities behave. We know that axiom is a statement which is considered to be true, and theorems are to be proved.First axiom is Closure Property, it states that Boolean operations (+ or .) on Boolean variables or constants will always result into a Boolean value.Basic postulates of Boolean Algebra:Boolean algebra consists of fundamental laws that are based on theorem of Boolean algebra. These fundamental laws are known as basic postulates of Boolean algebra. These postulates states basic relations in boolean algebra, that follow:I If X != 0 then x=1 and If X!=1 then x=0II OR relations(logical addition)III AND relations (logical multiplication)IV Complement Rules 0 1, 1 0Principal of DualityThis principal states that we can derive a Boolean relation from another Boolean relation by performing simple steps. The steps are:-1. Change each AND(.) with an OR(+) sign2. Change each OR(+) with an AND(.) sign3. Replace each 0 with 1 and each 1 with 0e.g0+0=0 then dual is 1.1=11+0=1 then dual is 0.1=0Basic theorem of Boolean algebraBasic postulates of Boolean algebra are used to define basic theorems of Boolean algebra that provides all the tools necessary for manipulating Boolean expression.1. Properties of 0 and 1(a) 0+X=X(b) 1+X=1(c) 0.X=0(d) 1.X=X2. Indempotence Law(a) X+X=X(b) X.X=X3. Involution Law

(X) = X4. Complementarity Law(a) X + X=1(b) X. X=05. Commutative Law(a) X+Y=Y+X(b) X.Y=Y.X6. Associative Law(a) X+(Y+Z)=(X+Y)+Z(b) X(YZ)=(XY)Z7. Distributive Law(a) X(Y+Z)=XY_XZ(b) X=YZ=(X+Y)(X+Z)8. Absorption Law(a) X+XY= X(b) X(X+Y)=XSome other rules of Boolean algebraX+XY=X+YDemorgan’s TheoremA mathematician named DeMorgan developed a pair of important rules regarding group complementationin Boolean algebra.Demorgan’s First Theoremi) (A+B)' = A'.B'ii)A.B)' = A'+B'Minterm :Minterm is a Product of all the literals within the logic System.Maxterm:A maxterm is a sum of all the literals (with or without the bar) within the logic system. Boolean Expression composed entirely either of Minterms or Maxterms is referred to as Canonical Expression.Canonical Form:Canonical expression can be represented is derived from(i) Sum-of-Products(SOP) form(ii) Product-of-sums(POS) formMinimization of Boolean expressions:-After obtaining SOP and POS expressions, the next step is to simplify the Boolean expression.There are two methods of simplification of Boolean expressions.1. Algebraic Method2. Karnaugh Map

Look for octet first and roll the map.(octet removes three variables)

Second look foe quad and roll the map, also look all for corners.(quad removes two variables)

Third look for pairs.( pair removes one variable)

Remove redundant /duplicate groups. Last write single.

Gate is an electronic system that performs a logical operation on a set of input signal(s). They are the building blocks of IC.

An SOP expression when implemented as circuit - takes the output of one or more AND gates and OR's them together to create the final output.

An POS expression when implemented as circuit - takes the output of one or more OR gates and AND's them together to create the final output.

Universal gates are the ones which can be used for implementing any gate like AND, OR and NOT, or any combination of these basic gates; NAND and NOR gates are universal gates.

Implementation of a SOP expression using NAND gates only1) All 1st level AND gates can be replaced by one NAND gate each.2) The output of all 1st level NAND gate is fed into another NAND gate.This will realize the SOP expression3) If there is any single literal in expression, feed its complement directly to 2nd level NAND gate.Similarly POS using NOR gate can be implemented by replacing NAND by NOR gate.Implementation of POS / SOP expression using NAND / NOR gates only.1) All literals in the first level gate will be fed in their complemented form.2) Add an extra NAND / NOR gate after 2nd level gate to get the resultant output.

COMMUNICATION & NETWORK CONCEPTS

Data channel: - The information / data carry from one end to another in the network by channel.

Baud & bits per second (bps) :- It’s used to measurement for the information carry of a communication channel.Measurement Units :- bit1 Byte= 8 bits1 KBPS ( Kilo Byte Per Second)= 1024 Bytes1 Kbps (kilobits Per Second) = 1024 bits1 Mbps ( Mega bits Per Second )=1024 KbpsBandwidth :- It is amount of information transmitted or receives per unit time.Telnet-It is an older internet utility that lets us log on to remote computer system. It also facilitates for terminalemulation purpose. Terminal emulation means using a pc like a mainframe computer through networking.Wireless/Mobile ComputingWireless communication is simply data communication without the use of landlines. Mobile computing means that the computing device is not continuously connected to the base or central network.1. GSM(Global System for Mobile communication): it is leading digital cellular system. In covered areas, cell phone users can buy one phone that will work any where the standard is supported. It uses narrowband TDMA, which allows eight simultaneous calls on the same radio frequency.2. CDMA(Code Division Multiple Access): it is a digital cellular technology that uses spreadspectrumtechniques. CDMA does not assign a specific frequency to each user. Instead ,every channel uses the full available spectrum.3. WLL(Wireless in Local Loop) : WLL is a system that connects subscribers to the public switched telephone network using radio signals as a substitute for other connecting media.4. Email(Electronic Mail): Email is sending and receiving messages by computer.5. Chat: Online textual talk in real time , is called Chatting.6. Video Conferencing: a two way videophone conversation among multiple participants is called video conferencing.7. SMS(Short Message Service): SMS is the transmission of short text messages to and from a mobile pone, fax machine and or IP address.8. 3G and EDGE: 3G is a specification for the third generation of mobile communication of mobile

communication technology. 3G promises increased bandwidth, up to 384 Kbps when a device is stationary.EDGE(Enhanced Data rates for Global Evolution ) is a radio based high speed mobile data standard.Network Security Concepts:Viruses: Viruses are programs which replicate and attach to other programs in order to corrupt the executable codes. Virus enters the computer system through an external source and become destructive.Worms: Worms are also self- replicating programs that do not create multiple copies of itself on one computer but propagate through the computer network. Worms log on to computer systems using the username and passwords and exploit the system.Trojan horse: - Though it is a useful program, however, a cracker can use it to intrude the computer system in order to exploit the resources. Such a program can also enter into the computer through an email or free programs downloaded through the Internet.Spams: Unwanted e-mail (usually of a commercial nature sent out in bulk)Cookies: Cookies are the text messages sent by a web server to the web browser primarily for identifyingthe user.Firewall: A firewall is used to control the traffic between computer networks. It intercepts the packets between the computer networks and allows only authorized packets to pass.Cyber Law: Cyber law refers to all the legal and regulatory aspects of Internet and the World Wide Web.Cyber Crimes: Cyber crime involves the usage of the computer system and the computer network for criminal activity.Hacking: Hacking is an unauthorized access to computer in order to exploit the resources.Web Services:WWW: The World Wide Web or W3 or simply the Web is a collection of linked documents or pages, stored on millions of computers and distributed across the Internet.HTML (Hyper Text Markup Language):- HTML is a computer language that describes the structure and behavior of a web page. This language is used to create web pages.

XML (eXtensible Markup Language):- Extensible Markup Language (XML) is a meta language that helps to describe the markup language.HTTP (Hyper Text Transfer Protocol):- A protocol to transfer hypertext requests and information between web servers and web browsers.Domain Names: A domain name is a unique name that identifies a particular website and represents thename of the server where the web pages reside.URL:- The Uniform Resource Locator is a means to locate resources such as web pages on the Internet.URL is also a method to address the web pages on the Internet. There are two types of URL, namely, absolute URL and relative URL.Website: A collection of related web pages stored on a web server is known as a website.Web browser: A software application that enables to browse, search and collect information from the Web is known as Web browser.Web Servers: The web pages on the Internet are stored on the computers that are connected to the Internet. These computers are known as web servers.Web Hosting: - Web Hosting or website hosting is the service to host, store and maintain the websites onthe World Wide Web.Web Scripting: - The process of creating and embedding scripts in a web page is known as Web Scripting. Types of Scripts:-(i) Client Side Scripts: - Client side scripts supports interaction within a webpage. E.g. VB Script, JavaScript, PHP (PHP‟S Hypertext Preprocessor).(ii) Server Side Scripts: - Server side scripting supports execution at server – end. E.g. ASP, JSP, PHP

OPEN SOURCE TERMINOLOGIESFree Software: The S/W’s is freely accessible and can be freely used changed improved copied and distributed by all and payments are needed to make for free S/W.Open Source Software: S/w whose source code is available to the customer and it can be modified and redistributed without any limitation .OSS may come free of cost but nominal charges has to pay nominal charges (Support of S/W and development of S/W).

FLOSS (Free Libre and Open Source Software) : S/w which is free as well as open source S/W.( Free S/W + Open Source S/W).GNU (GNU’s Not Unix) : GNU project emphasize on the freedom and its object ive is to create a system compatible to UNIX but not identical with it.FSF (Free Software Foundation) : FSF is a non –profit organization created for the purpose of the free s/w movement. Organization funded many s/w developers to write free software.OSI (Open Source Initiative) : Open source software organization dedicated to cause of promoting open source software it specified the criteria of OSS and its source code is not freely available.W3C(World Wide Web Consortium) : W3C is responsible for producing the software standards for World Wide Web.Proprietary Software: Proprietary Software is the s/w that is neither open nor freely available, normally the source code of the Proprietary Software is not available but further distribution and modification is possible by special permission by the supplier.Freeware: Freeware are the software freely available , which permit redistribution but not modification (and their source code is not available). Freeware is distributed in Binary Form (ready to run) without any licensing fees.Shareware: Software for which license fee is payable after some time limit, its source code is not available and modification to the software are not allowed.Localization: localization refers to the adaptation of language, content and design to reflect local cultural sensitivities .e.g. Software Localization: where messages that a program presents to the user need to be translated into various languages.Internationalization: Opposite of localization.OPEN SOURCE / FREE SOFTWARELinux : Linux is a famous computer operating system . popular Linux server set of program –LAMP(Linux, Apache, MySQL, PHP)Mozilla : Mozilla is a free internet software that includesa web browseran email clientan HTML editor

IRC clientApache server: Apache web server is an open source web server available for many platforms such as BSD, Linux, and Microsoft Windows etc.Apache Web server is maintained by open community of developers of Apache software foundation.MYSQL : MYSQL is one of the most popular open source database system. Features of MYSQl :MultithreadingMulti –UserSQl Relational Database ServerWorks in many different platformPostgreSQL : Postgres SQL is a free software object relational database server . PostgresSQL canbe downloaded from www.postgressql.org.Pango : Pango project is to provide an open source framework for the layout and rendering ofinternationalized text into GTK + GNOME environment.Pango using Unicode for all of its encoding ,and will eventually support output in all the worlds major languages.OpenOffice : OpenOffice is an office applications suite. It is intended to compatible and directly complete with Microsoft office.OOo Version 1.1 includes:Writer (word processor)Calc(spreadsheet)Draw(graphics program)etcTomcat : Tomcat functions as a servlet container. Tomcat implements the servlet and the JavaServer Pages .Tomcat comes with the jasper compiler that complies JSPs into servlets.PHP(Hypertext Preprocessor) : PHP is a widely used open source programming language for server side application and developing web content.Python: Python is an interactive programming language originally as scripting language for Amoeba OS capable of making system calls.Q. What is protocol? How many types of protocols are there?Ans. When computers communicate each other, there needs to be a common set of rules and instructions that each computer follows. A specific set of communication rules is called a protocol. Some protocol: PPP, HTTP, SLIP, FTP, TCP/IPQ. What is the difference between Networking and Remote Networking?Ans. The main difference between Networking and Remote Networking, is the network which we use in

offices or other places locally such LAN or INTERNET and remote networking is one which we use TERMINAL Services to communicate with the remote users such WAN.Q. What is point-to-point protocol?Ans. A communication protocol used to connect computer to remote networking services include Internet Service Providers. In networking, the Point-to-Point protocol is commonly used to establish a direct connection between two nodes. Its primary use has been to connect computers using a phone line.Q. How gateway is different from router?Ans. A gateway operates at the upper levels of the OSI model and translates information between twocompletely different network architectures. Routers allow different networks to communicate with eachother. They forward packets from one network to another based on network layer information. A gatewaycan interpret and translate the different protocols that are used on two distinct networks. Unlike routersthat successfully connect networks with protocols that are similar, a gateway perform an application layerconversion of information from one protocol stack to another.Q Define the terms Bandwidth.Ans:- Bandwidth is the range of frequencies that is available for the transmission of data. Wider the bandwidth of a communication channel, the more data it can transmit in a given period of time.Q. What is the difference between baseband and broadband transmission?Ans. Baseband is a bi-directional transmission while broadband is a unidirectional transmission.No Frequency division multiplexing possible in base band but possible in broadbandEntire bandwidth of the cable is consumed by a signal where as broadband transmission, signals are sent onmultiple frequencies, allowing multiple signals to be sent simultaneously.QWhat are various data transmission modes?Ans:- There are three modes of data transmissionSimplexHalf-duplexFull-duplex

Q.What is the difference between Simplex and half duplex transmission?Ans:- In simplex transmission mode, the data can be transferred in only one direction where as in half duplex transmission mode, the data can be transmitted in both directions but one at a time.SLIP/PPP (Serial Line Internet Protocol / Point to Point Protocol) SLIP/PPP provides the ability to transport TCP/IP traffic ever serial line between two computers. PPP (Point-to-Point Protocol) is usedfor communication between two computers using a serial interface, mostly a personal computer connected by phone line to a serverFor example, an Internet ServiceProvider(ISP) may provide you with a PPP connection so that the ISP'sserver can respond to your requests, pass them on to the Internet, and forward your requested Internet responses back to you.SWITCHING TECHNIQUES Switching techniques are used for transmitting data across networks. Different types are : Circuit Switching Message Switching Packet Switching 1.Circuit Switching

Circuit switching is a technique in which a dedicated and complete physical connection is established between two nodes and through this dedicated communication channel, the nodes may communicate.

The circuit guarantees the full bandwidth of the channel and remains connected for the duration of the communication session. Even if no communication is taking place in a dedicated circuit, that channel still remains unavailable to other users (idle channels).

The defining example of a circuit-switched network is the early analogue telephone network.2. Message Switching:

In the Message switching technique, no physical path is established between sender and receiver in advance.

This technique follows the store and forward mechanism.3Packet Switching

Packet switching is a switching technique in which packets (discrete blocks of data of fixed size and of any content, type or structure) are routed between nodes over data links shared with other traffic

The main advantage of packet-switching is that the packets from many different sources can share a line, allowing for very efficient use of the communication medium.

Network Terminologies:Before continuing our study on networks let us first learn about some terminologies commonly used in networking.i) Nodes (Workstations)A computer becomes a node (also called a workstation) as soon as it is attached to a network. Each user on a network works on a workstation. If there are no nodes there would be no network.ii) ServerA computer that facilitates sharing of data, software and hardware resources on the network is known as the server. A network can have more than one server also. Each server has a unique name by which it is identified by all the nodes on the network. Servers can be of two types:a) Dedicated andb) Non dedicated serversDedicated Servers: These are generally used on big network installations where one computer is reserved for server's job. It helps all nodes access data, software and hardware resources. Since it does not double up as a workstation but only manages the network, so it is known as a dedicated server and such type of networks are called master- slave networks.Non dedicated servers: In small networks, a workstation can double up as a server. These servers are known as non dedicated servers. The small networks using such a server are known as Peer to Peer networks.iii) Network Interface Unit (NIU)A network interface unit is a device that is attached to each of the workstations and the server which helps to establish communication between the server and workstations. The NIC basically acts like an interpreter and is also known as Terminal Access Point (TAP) or Network Interface

card(NIC).The NIC manufacturer assigns a unique physical address toeach NIC card and this physical address is known as the MAC address.Internet Relay Chat (IRC)IRC protocol is used for chatting. It provides chatting between a group or between two individuals. It was developed by JarkkoOikarinen in Finland in the late 1980s. It is based on client/server model. The IRC client sends and receives messages to and from an IRC server. The IRC server transports the message from one client to another.

VOIPVOIP stands for voice over internet protocol. It enables the transfer of voice using packet switched network rather than using public switched telephone network. By using VOIP software, phone calls can be done using standard internet connection. This method of making phone calls is much cheaper than convectional way because the service of Telecommunication Company is not used.There are three different methods of VoIP service in common use today:ATA - ATA stands for analog-to-digital converted.IP phones - IP phones appear much like an ordinary telephone or cordless phone. TheyComputer-to-computer - It is the most easy and simplest way to use VoIP.

1G Mobile Systems: The 1G Mobile System was introduced in late 1970s and early 1980s.The 1G mobile system was based on the analog cellular technology. They only had voice facility available.2G Mobile Systems: They used digital signals for transmissions of voice. 2G enabled the mobile systems to provide paging, SMS, voicemail and fax services.3G Mobile Systems: The 3G technology adds multimedia facilities to 2G phones by allowing video, audio, and graphics applications.4G Mobile Systems: 4G will provide better-than-TV quality images and video-links.Virus: Virus is a malicious program that attaches itself to the host program. It is designed to infect the host program and gain control over the system without the owner's knowledge.

Worm: Worm is also a malicious program like a virus. But unlike viruses, it does not need to attach itself to a host program. A worm works by itself as an independent object.Trojan horse: A Trojan horse is a program that contains hidden malicious functions. Trojan Horses trick users into installing them by appearing to be legitimate programs.Spam: The term spam means endless repetition of worthless text. In other words, unwanted messages or mails are known as Spam.Cookies: This small text file is a cookie. Generally a cookie contains the name of the website that it has come from and a unique ID tag.Firewall: A firewall is hardware or software based network security system. It prevents unauthorized access (hackers, viruses, worms etc.) to or from a network.Cyber Crime: Cybercrime is defined as a crime in which a computer and internet is used in an illegitimate way to harm the user.Cyber Law: Cyber law is an attempt to integrate the challenges presented by human activity on the internet with legal system of laws applicable to the physical world.Intellectual property rights are the rights given to an individual over the invention of their own. They usually give the creator an exclusive right over the use of his/her creation for a certain period of timeIntellectual property rights (IPR) Issues: Intellectual property rights are the rights given to an individual over the invention of their own. They usually give the creator an exclusive right over the use of his/her creation for a certain period of time.There are only three ways to protect intellectual property :

o Patentso Copyrightso Trademark

Hacking: The term was used for people who engaged themselves in harmless technical experiments and fun learning activities.Cracking: Cracking can be defined as a method by which a person who gains unauthorized access to a computer with the intention of causing damage.HyperText Transfer Protocol (HTTP): HTTP is the protocol that is used for transferring hypertext (i.e. text, graphic,

image, sound, video etc.) between two computers and is particularly used on the World WideWeb. It is a TCP/IP based communication protocol and provides a standard for Web browsers and servers to communicate.WWW (World Wide Web): WWW can be defined as a hypertext information retrieval system on the Internet. Tim Berners -Lee is the inventor of WWW. WWW is the universe of the information available on the internet.Web page: Web page is an electronic document designed using HTML. It displays information in textual or graphical form. It may also contain downloadable data files, audio files or video files.A web page can be classified into two types:Static web pageDynamic web pageWebsite: Related web pages from a single web domain is termed as a website. A website has multiple web pages providing information about a particular entity.Web browser: Web browser is software program to navigate the web pages on the internet. A browser interprets the coding language of the web page and displays it in graphic form.URL (Uniform resource locator): Web address of the web page written on the address bar of the browser is known as the uniform resource locator (URL).Web hosting: Web hosting is the process of uploading/saving the web content on a web server to make it available on WWW.Web 2.0: Web 2.0 refers to new generation of dynamic and interactive websites. Web 2.0 websites uses a new programming language called AJAX (Asynchronous JavaScript and XML).ISCII - Indian Script Code for Information InterchangeGNU: GNU’S is not Unix OSS : (Open source software)GPL: General Public LicenseTTF: True Type FontGPS: Global System For Mobile CommunicationGPRS: General Packet Radio ServiceEDGE: Enhanced Data GIF: Graphical Interchange File FormatTIFF: Tagged Interchanged FormatBMP: BITMAP IMAGE.JPEG: Joint Photograph Expert GroupMPEG: MOTION PICTURES EXPERT GROUPPNG: Portable Network Graphics.

SVG: Scalar Vector GraphicsWIFI: WIRELESS FIDELITY WIFI IS WIRELESS LAN(1Mbps to 20 Mbps)WIMAX: Wordwide operability through microwave access is wireless internet service to entire city(50Mbps to 70Mbps)MPEG-1 or MPEG-2 Audio Layer III, more commonly referred to as MP3, is an encoding format for digital audio which uses a form of lossy data compression.Advanced Audio Coding (AAC) is a standardized, lossy compression and encoding scheme for digital audio.LAMP: LINUX APACHE MYSQL PHPPHP: HYPERTEXT PREPROCESSORFLOSS: FREE LIBRE OPEN SOURCE SOFTWAREUNICODE : UNIOVERSAL CODINGRDBMS: RELATIONAL DATABASE MANAGEMENT SYSTEMHTTP: HYPERTEXT TRANSFER PROTOCOLTCP/ IP: TRANSMISSIOM CONTROL PROTOCOL/ INTERNET PROTOCOLFSF : FREE SOFTWARE FOUNDATION.ASCII: AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE.NRCFOSS : National Resource Centre for Free and Open Source Software.ODF : Open Document format ICT: INFORMATION AND COMMUNICATION TOOLSBOSS Bharat Operating Systems SolutionsURL: Uniform Resource LocatorMAC (Media Access Control)SMTP: Simple mail transfer protocol) is used to send e-mail.POP (post office protocol) is used to access or receive e-mail from servers.UDP: User datagram protocol is used to send data like IP.FTP: File transfer protocol is used to upload and download filesNIC: Network Interface Card / UnitWIFI: WIRELESS FIDELITY

Q1.Explain the difference between pass by value and pass by reference.Passing by value- In this method separate memory created for formal arguments and if any changes done on formal variables, it will not affect the actual variables. So actual variables are preserved in this casePassing by address/reference- In this method no separate memory created for formal variables i.e formal variables share the same location of actual variables and hence any change on formal variables automatically reflected back to actual variables.

Example :void sample( int a, int &b){a=a+100;b=b+200;cout<<a<<b;}void main()

{

int a=50, b=40;cout<<a<<b; // output 50 40sample(a,b) // output 150 240cout<<a<<b; // output 50 240}

1. (a) Run Time Error : Error occurring in a program during its execution. Program execution halts when such an error is encountered.

Example:int A,B,C;cin>>A>>B;C=A/B;//Runtime error if value of B is zero.Syntax Error: Error occurred due to wrong syntax of language detected by the compiler during compilation.Example:cout>>”A C++ Program”;Q (a) What is the difference between automatic type conversion and type casting? Also, give a suitable C++ code to illustrate both.Automatic Type Conversion: it is an implicit process of conversion of a data from one type to another. For exampleint N = 65;char C = N; // Automatic type conversioncout<<C;OUTPUT:AType Casting: It is an explicit process of conversion of a data from one type to another. For exampleint A=1, B=2;float C = (float)A/B; //Type Castingcout<<C;OUTPUT:0.5 Q(a) What is the difference between Object Oriented Programming and Procedural Programming?

Q ( a ) What is the difference between Actual Parameter and Formal Parameters ? Also, give a suitable C++ code to illustrate both.

Q (a) What is the difference between #define and const? Explain with suitable example. #define: It is a pre-processor directive in C++ for creating a Macro.Example:#define sqr(i) i*i const: It is an Access Modifier in C++ that assigns a constant (non modifiable) value to a variable. Any attempt in modifying the value assigned to such a variable is reported as an error by the compiler.Example:

Actual Parameter

Formal Parameter

It is a parameter, which is used in function call to send the value from the calling environment.

It is the parameter, which is used in function header, to receive the value from the actual parameter.

Example :#include <iostream.h> void Calc ( int T ) // T is formal parameter{cout<< 5 * T;}void main ( ){int A=45;Calc ( A ); // A is actual parameter}

const float Pi = 3.14;2(a) What is the purpose of using a typedef command in C++. Explain with suitable example.Ans: Typedef:

This keyword allows creating synonyms or aliases for previously defined data types The general form of typedef is

typedef old_name new_name;ORtypedef is used for renaming a data type.Example:typedef char STR [80]; OR typedef signed char SMALLNUM;OR typedef float REAL; OR typedef long int BIGNUM;OR typedef int MAT[2][3] ;

Q. (a) What is the difference between call by value and call by reference? Give an example in C++ to illustrate both.

Call by value is used to create a temporary copy of the data coming from the actual parameter into the formal parameter. The changes done in the function in formal parameter are not reflected back in the calling environment. It does not use ‘&’ sign.Call by reference is used to share the same memory location for actual and formal parameters and so changes done in the function are reflected back in the calling environment. It uses ‘&’ sign.void Compute(int A, int &B){A++;B++;cout<<”In the function”<<endl;cout<<”A=”<<A<<“&”<<“B=”<<B<<endl;}void main (){int I=50,J=25;cout<<”Before function call “<<endl;cout<<”I=”<<I<<”&”<<”J=”<<J <<endl;Compute (I,J) ;cout<<”After function call “<<endl;cout<<I=”<<I<<”&”<<”J=”<<J <<endl;}OUTPUTBefore function callI=50&J=25In the function

Object Oriented Programming

Procedural Programming

Emphasis on Data

Follows Bottom-Up approach in program design

Data hiding feature prevents accidental change in data

Features like data encapsulation, polymorphism, inheritance are present

Emphasis on doing things (functions)

Follows Top-down approach in program design

Presence of Global variables increase chances of accidental change in data

Such features are not available

A=51&B=26After function callI=50&J=26

Q (a) What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to illustrate both types of parameters.A parameter used in the function call is known as Actual Parameter. It is used to send the data to function. A parameter used in the function definition is known as Formal Parameter, It is used to accept the data from actual parameter.void Seventimes(int A)//A is formal parameter{cout<<7*A;} void main (){int P=6;Seventimes(P);//p is actual parameter}1. (a) What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to illustrate both. Local Variables: Local variables are those variables which are declared within a function or a compound statement and these variables can only be used within that function/scope.Global Variables: Global variables are those variables which are not declared within any function or scope. So, these variables can be accessed by any function of the programExample#include<iostream.h>#include<conio.h.>int G; // Global variable declaredvoid Fun ( ){int L = 25; // Local variable of function Fun ( ) assigned value 25G=5; // Global Variable is accessed and assigned value 5Cout<<G<<endl; // Value of global variable is displayed as 5Cout<<L<<endl; // Value of local variable is displayed as 25}void main ( )

{Fun ( ) ; // Function callG = G + 5; // Global variable is incremented by 5cout<<G<<endl; // Global variable is displayed as 10}1 (a) Differentiate between the post-increment and pre-increment operators. Also, give suitable C++ code to illustrate both.

b) Illustrate the use of #define in C++ to define a macro.ANS: #define is a preprocessor directive that is used to define a

symbolic constant. The symbolic constant defined, replaces the word / statement wherever it appears in the program as a macro substitution.

Syntax : #define symbolic_name value

Example: #define Pi 3.14#define WELCOME cout<<”Hello

World !\n”;1(b) Illustrate the use of inline function in C++ with the help of an example. The inline functions are a C++ enhancement designed to speed up the program. The coding of normal function

Post-increment Pre-increment ++ is an

increment operator to increment the value of a variable by one , when used after the operand it is known as post – increment operator.

When it is used before an operand to increment its value by one, it is called pre – increment operator.

Example :#include <iostream.h>void main ( ){int NUM=9;cout<<++NUM ; // 10 will be displayedcout<<NUM++ ; // 10 will be displayedCout<< NUM ; // 11 will be displayed}

and inline functions is similar except that inline functions definition starts with keyword

inline.The compiler replaces the function

call statement with the function code itself this process is called as expansion and then compiles the entire code.For example:void main() void main(){ {….. …….square(3); code copied here

{ cout<<3 *3 }…… ……….square(5); code copied here

{cout<<5 * 5; }}

2. (a) Define Multilevel and Multiple inheritance in context of Object Oriented Programming.Give suitable example to illustrate the same.. (a) In Multilevel inheritance, a class inherits it’s properties from another derived class transitively.

Class A{……;};Class B :public A{….};Class C: B{…};

In Multiple inheritance, a derived class inherits from multiple base classes.

Class A{……;};Class B :{….};Class C: public A, private C{…};

2. (a) What is “this” pointer ? Give an example to illustrate the use of it in C++.2. (a) While manipulating objects for user programs, C++ maintains an internal pointer called this, to pointto the current object being operated upon. Whenever a member function of an object is called, thecompiler places the address of the object in pointer this before invoking the function. For example :class xyz {int a;public:void read(int a);{this->a=a;}void display(){cout<<"\n a = "<<this->a;}};In the above class xyz, a pointer this has been used to print the value of an even though the pointerhas not been declared anywhere.2. (a) Differentiate between Protected and Private members of a class in context of Inheritance using C++.

CBA

CBA

2. (a) Differentiate between Constructor and Destructor function in context of Classes and Objects using C++ 2. (a) Constructors:

· Name of the constructor functions is same as the name of the class

· No return type required for constructor function.

· Constructor functions are called automatically at the time of creation of the object

· Constructors can be overloaded· Constructor functions are defined in public2. Destructors:

· Name of the destructor is same as the name of the class preceded by ~

· No return type required for destructor function.

· Destructor functions are called automatically when the scope of the object gets over

· Destructor can not be overloaded · Destructor function is defined in

public.2. (a) Differentiate between public and private visibility modes in context of Object Oriented Programming using a suitable example illustrating each.Ans: PUBLIC VISIBILITY MODE:Members of a class declared under this visibility are accessible inside the class (in member functions of the class) as well as by the Objects of that class(in any non member function of the program, prototyped / defined after the class declaration).Ans: PRIVATE VISIBILITY MODE:Members of a class declared under this visibility are accessible only inside the class (in member functions of the class). They can not be accessed outsidethe class.

class Example{int Priv;void Assign ( ){Priv =10; //private member accessible only inside class }} ;void main ( ){Example E;E.Assign( ); //public member accessible by Object}

2. (a) What is copy constructor? Give an example in C++ to illustrate copy constructor.Ans A copy constructor is an overloaded constructor function in which (an) object(s) of the same class is/are passed as a reference parameter(s). It is used when an object’s data value is related to or is initialised using anotherobject’s data value of the same class. In the example below the values of data members of object Q are dependent on the values of data members of object P and Data members of object R dependent on Q.//Example of Copy Constructorclass Play

{int Count, Number;public:Play(); //constructorPlay(Play &);//copy constructorvoid Disp();void Change(int,int);};Play::Play () //constructor{Count=0;Number=0; }Play:: Play (Play &P) //copy constructor{Count=P.Count+l0;Number=P.Number+20;}void Play::Disp(){cout<<Count;cout<<Number<<endl;}void Play::Change(int C,int N){Count=C;Number=N; }void main (){Play P; //Call for constructorP.Disp (); P.Change(90,80) ;Play Q(P); //Copy constructor callQ.Disp();Play R=Q; //Copy constructor ca11 [same as P1ay R(Q);]R. Disp();}2. (a) What is function overloading? Give an example in C++ to illustrate function overloading.Ans Function overloading is an example of polymorphism, where the functions having same name with different set of parameters perform different operations.

ORWhen a function is having more than one definition and differentiable by the number/type of parameters is known as function overloading.Example:void Disp() //Function 1{cout<<”Hello”<<endl;}void Disp(int N) // Function 2

{for (int I=1;I<=N;I++)cout<<I<<end1;}2. (a) What do you understand by Polymorphism.? Also, give an example in C++to illustrate the same. . Ans. The process of using an -operator or a function in different ways for different set of inputs given is known- as polymorphism. Function overloading is- an example of polymorphism, where the functions having same name with different set of parameters perform different operationsExample:void Disp ( ) //Function 1{cout<<“Hello”<<endl;}void Disp(int N) //Function 2{for(int I=1;I<=N;I++)cout<<I<<endl; } void Disp (int N,int M) //Function 3{for (int I=N;I<=M; I++)cout<<N<<“x”<<I<<“=”<<N*I<<endl;}void main ( ){int x=5, y=10;Disp(x); //Function 2 called-Prints numbers from 1 to 5 Disp(x,y) ; //Function 3 called- Prints from multiples of 5 ranging from 5 to 10Disp () ; //Function 1 called- Prints Hello}2. (a) What do you understand by Data Encapsulation and Data Hiding ?’ Also, give an example in C++ to illustrate both. Ans. Data Encapsulation: Wrapping up of data and functions together in a single unit is known as Data Encapsulation. In a class, we wrap up the data and functions together in a single unit.Data Hiding: Keeping the data in private/protected visibility mode of the class to prevent it from accidental change is known as Data Hiding.class Computer{char CPU[lO] ;int RNM; //Data Hidingpublic: //Data Encapeulation

void STOCK();void SHOW();};2. (a) Differentiate between members, which are present within the private visibility mode with those which are present within the public visibility modes.Ans Private members of a class are accessible only to the member functions of the same class.Public members of a class are accessible to the member functions of the same class as well as member functions of its derived class(es) and also to an object of the class.class Base{int N;public:void Assign (){N=10;} };class Derived: public Base{int X;public:void DisplayBase(){cout<<N; //Not AccessibleAssign ( ) ; //Accessible} } ;void main ( ){Base B;B.Assign( ) ; //Accessible}2. (a) Differentiate between Constructor and Destructor function in context of Classes and Objects using C++ 2. (a) Constructors:

· Name of the constructor functions is same as the name of the class

· No return type required for constructor function.

· Constructor functions are called automatically at the time of creation of the object

· Constructors can be overloaded · Constructor functions are defined in

public

2. Destructors: · Name of the destructor is same as

the name of the class preceded by ~

· No return type required for destructor function.

· Destructor functions are called automatically when the scope of the object gets over

· Destructor can not be overloaded · Destructor function is defined in

public.

Class item{int quantity;double Price ;public:item(){Quantity=12;Price=23;}~item(){cout<<”\ndestructor called”;}};void main(){Item a;//constructor calledFor(int i=1;i<=2;i++){Item b;//contructor called}//destructor for b called}//destructor for a called