CLASS XII PA - II ASSIGNMENTS

COMPUTER SCIENCE (083)

SESSION 2017 – 2018

Que 1. (a) What is meant by inheritance in C++ ?

(b) Name and briefly explain different types of inheritances. Also express

them diagrammatically.

(c) What will be the status of the base class members when a new class is

derived in Private mode, Protected mode and public mode.

(b) Differentiate between access specifiers and visibility modes.

(c) Give any four advantages of inheritance.

(d) Differentiate between single, multiple and multilevel

inheritance with an example of each.

(e) Consider following class definitions, answer given questions :

class Book

{ char title[20];

char author [20];

int no_of_pages;

public :

void read ( );

void show( ); } ;

class Textbook : private Book

{ int no_of_chapters , no_of_assignments ;

protected :

int standard ;a

void readTextbook ( );

void showTextbook ( ); };

class Physicsbook : public Textbook

{ char topic[20];

public :

void readPhysicsbook( );

void showPhysicsbook( ); };

(i)  Name the members, which can be accessed from the member

functions of class Physicsbook.

(ii)  Name the members, which can be accessed by an object of class Textbook.

(iii)  Name the members, which can be accessed by an object of class Physics

(iv)  What will be the size(in bytes) of an object of class Physicsbook

(f) What members of a base class will be inherited by a derived class when a class is derived :

(i)  in private mode

(ii)  in protected mode

(iii)  in public mode

Q 5 (a) A company is planning to expand their network in India,

starting with two cities. The company has planned to has its corporate

unit in Delhi and main office in Chennai at three different locations and

named their offices as “Production Unit”, “Finance unit” and

“Media Unit”.

INDIA
Corporate unit
Delhi
Production Unit
Finance Unit
Media Unit
CHENNAI

Approximate distance between these units is as follows:

FROM / TO / DISTANCE
Production Unit / Finance Unit / 70 meters
Production Unit / Media Unit / 15 KM
Production Unit / Corporate Unit / 2112 KM
Finance Unit / Media Unit / 15 KM

In continuation of the above, the company experts have planned to install following number of computers in each of their offices :

Production Unit / 150
Finance Unit / 35
Media Unit / 10
Corporate Unit / 30

(i)  Suggest the network (LAN, MAN or WAN ) for connecting each of their office units :

·  Production Unit and Media Unit

·  Production Un it and Finance Unit

(ii) Which of the following devices will you suggest for connecting all the

Computers within each of their office units ?

·  Switch / Hub

·  Optical Fibre

(iii)Suggest most suitable layout for connecting the Production unit, Media unit

and Finance unit.

(a) What is difference between dereference operator and address

operator ? Give an example for each

(b) Differentiate between ordinary variable and pointer variable with an

example each.

(c) Differentiate between static memory and dynamic memory.

(d) Give two advantages and two disadvantages of Pointers

(e)What is the difference between Global and Local variable?

Also give a suitable C++ code to illustrate both.

Q 6. (a) What is a pointer?

(b) What is pointer arithmetic ? How is it performed ?

(c)Identify and explain the errors in the following C++ code :

float a[ ] = {11.02,12.13,19.11,17.41};

float *j,*k;j=a;

k=a+4; j=j*2;k=k/2;

cout<”*j = “ < *j<” *k “<*k < “\n”;

(d)What is meant by Memory Leak ?

(c)  Briefly explain about Heap Memory.

Q 7. (a) How is a Hacker different from a Cracker ?

(b) Expand the following terms with respect to Networking.

(i) CDMA (ii) FTP

(iii) WLL (iv) HTML

Q 8. C++ Function Overloading Programs

Here are some example programs illustrates the working of function overloading in C++. Let's first look at the following example where the same function named print() is being used to print the different data types:

/* C++ Function Overloading - This C++ program

* demonstrates the concept of function overloading

* in C++ practically.

*/

#include<iostream.h

#include<conio.h

class printData

{

public:

void print(int i) // function 1

{

cout<"Printing int: "<i<"\n";

}

void print(double f) // function 2

{

cout<"Printing float: "<f<"\n";

}

void print(char* c)

{

cout<"Printing characters (string): "<c<"\n";

}

};

void main()

{

clrscr();

printData pdobj;

pdobj.print(5); // called print() to print integer

pdobj.print(50.434); // called print() to print float

pdobj.print("C++ Function Overloading"); // called print() to print string

getch();

}

Here is the output produced by the above C++ program:

Here is another C++ program, also demonstrating function overloading in C++ practically

/* C++ Function Overloading - This C++ program

* demonstrates the working of default arguments

* in C++

*/

#include<iostream.h

#include<conio.h

void amount(float pri, int tim=2, float rat=0.06);

void amount(float pri, int tim, float rat)

{

cout<"\n\tPrincipal Amount = "<pri;

cout<"\n\tTime = "<tim;

cout<"\n\tRate = "<rat;

cout<"\n\tInterest Amount = "<(pri*tim*rat)<"\n";

}

void main()

{

clrscr();

cout<"Results on amount(2000)";

amount(2000);

cout<"\nResults on amount(2500, 3)";

amount(2500, 3);

cout<"\nResults on amount(2300, 3, 0.11)";

amount(2300, 3, 0.11);

cout<"\nResults on amount(2500, 0.12)";

amount(2500, 0.12);

getch();

}

Here is the output of the above C++ program:

C++ Function Overloading Programs

Here are some example programs illustrates the working of function overloading in C++. Let's first look at the following example where the same function named print() is being used to print the different data types:

/* C++ Function Overloading - This C++ program

* demonstrates the concept of function overloading

* in C++ practically.

*/

#include<iostream.h

#include<conio.h

class printData

{

public:

void print(int i) // function 1

{

cout<"Printing int: "<i<"\n";

}

void print(double f) // function 2

{

cout<"Printing float: "<f<"\n";

}

void print(char* c)

{

cout<"Printing characters (string): "<c<"\n";

}

};

void main()

{

clrscr();

printData pdobj;

pdobj.print(5); // called print() to print integer

pdobj.print(50.434); // called print() to print float

pdobj.print("C++ Function Overloading"); // called print() to print string

getch();

}

Here is the output produced by the above C++ program:

Here is another C++ program, also demonstrating function overloading in C++ practically

/* C++ Function Overloading - This C++ program

* demonstrates the working of default arguments

* in C++

*/

#include<iostream.h

#include<conio.h

void amount(float pri, int tim=2, float rat=0.06);

void amount(float pri, int tim, float rat)

{

cout<"\n\tPrincipal Amount = "<pri;

cout<"\n\tTime = "<tim;

cout<"\n\tRate = "<rat;

cout<"\n\tInterest Amount = "<(pri*tim*rat)<"\n";

}

void main()

{

clrscr();

cout<"Results on amount(2000)";

amount(2000);

cout<"\nResults on amount(2500, 3)";

amount(2500, 3);

cout<"\nResults on amount(2300, 3, 0.11)";

amount(2300, 3, 0.11);

cout<"\nResults on amount(2500, 0.12)";

amount(2500, 0.12);

getch();

}

Here is the output of the above C++ program:

Que 9. Name and briefly explain basic concepts of OOP.

Que 10. Why do you think function overloading must be a part of an Object Oriented

Language?

Que 11. A function printchar is defined as

void printchar(char ch = ‘*’,int len = 40)

{ for(int x = 0; x< len; x + +)cout < ch;

cout < endl ; }
How will you invoke the function printchar for the following output :

(i)to print ’*’ 40 times (ii) to print ’*’ 20 times (iii) to print ’=’ 40 times

(iv) to print ’=’ 30 times

Que 12. Discuss briefly how the best match is found when a call to an overloaded

function is encountered. Give example(s) to support your answer.

Que 13. (a) What is a class in C++ ? Why we need it ?

(b) Give any three differences between an object and a class.

(c) Differentiate between different access specifiers inside a class. Also

give suitable examples.

(d) Write a program using a class demonstrating the use of outline functions.

(e) Write a program using a class demonstrating the use of inline functions.

Que 14. (a) What is meant by inheritance in C++ ?

(b) Name and briefly explain different types of inheritances. Also express

them diagrammatically.

(c) What will be the status of the base class members when a new class is

derived in Private mode, Protected mode and public mode.

Que 15. (a) What is meant by Database ?

(b) What is significance of Database Manager ?

(c) What is meant by Networking ?

(d) Differentiate between LAN, MAN and WAN.

(e) Name and explain different types of Topologies.

Que 16. (a) What is meant by SQL ?

(b) Differentiate between DDL, DML and DCL in SQL.

(c) Write SQL commands to create a table Student with following

descriptions:

Rollno, Name, class and marks in five subjects.

(d) Write SQL commands to give data for the above mentioned attributes for

five students

Que 17. ALGORITHM FOR BINARY SEARCH IN ARRAY

CASE I : Array AR[L:U]is stored in ascending order

/* Initialise segment variable segment variable */

1. Set beg = L , last = U //In C++,L is 0 and U is size -1

2 .Repeat steps 3 through 6 UNTIL beg > last //INT () is used to extract integer part

3. mid=INT ((beg+last)/2)

4. if AR[mid]==ITEM then

{ print “Search Successful “

print ITEM, “ found at “ , mid

break // go out of the loop

}

5. if AR[mid]<ITEM then

Beg = mid+1

6. if AR[mid]>ITEM then

Last=mid-1

//End of repeat

7 .if beg !=last

Print “Unsucessful Search “

8. End.

Traversing an Array

Traversing means to visit each element of an array at least once from the beginning of an array tiil the end of an array.

// if nothing is mentioned, algorithm can be written as follow also

1. Declare an array A with size such as A[5]

2. Declare a counter variable that keeps track of each element, say C

3. Initialize C with 0, as the index number of first element if 0 and it will be incremented for every nect element’s index number, i.e., C =C + 1

4. Process A[C]

5. The counter C will stop incrementing as soon as its value becomes greater than or equal to the size of an array, otherwise repeat step 3 and 4

6. End of the program

// Program demonstrating the concept of traversing elements of an array

#include <conio.h

#include<iostream.h

void main( )

{ clrscr();

int arr[10], n, i ;

cout<”\n Enter the number of elements :”;

cin>n;

cout<”\n Enter””<n<”elements”;

for(i =0; i < n; i++)

cinarr[i];

cout<”\n Entered array elements are :”;

coutarr[i];

getch(); }

Searching in One – Dimensional Arra

Searching is a method to find a particular value/element in an array. It displays whether the searched value is present in an array or not, and if present, then at what position. The simplest method to search a value is Linear search (Sequential Search), in which each element of an array is compared with the given value which is to be searched.

There are two methods of searching in one-dimensional array :

1.  Linear search 2. Binary Search

Algorithm for Linear Search on one-dimensional array

1.  Declare a variable say ‘a’ with size 10

2.  Declare a variable for storing key value

3.  Start the searching value in the array using loop

4.  If the value is matched with the corresponding element in an array, then stop the loop and display the index number and position of element in array

5.  If not found, then continue with step 3 until all the elements are searched

6.  Stop the program

Program to search as element in an array using Linear Search

#include<iostream.h

#include<conio.h

int lsearch(int [ ], int, int) ;

void main( )

{ int A[20], N, index, i, val ;

clrscr();

cout<”\n Enter number of elements “;

cin> N;

cout<”\n Enter the elements “;

for ( i = 0; i<N ; i++)

cin>A[i];

cout<”\n Enter value/element to be searched “;

cinval;

index = lsearch(A, N, val);

if ( index == 1)

cout<”Element not found in the array “;

else

cout<”\n Element found at index”<index<”and at position”<index + 1;

getch(); }

int lsearch( a[ ], int n , int val)

{ for ( int i = 0 ; i<n ; i++)

if ( a[i] == val)

return i ; }

return – 1; }

Binary Search

The compulsory condition for binary search is that the array must be sorted in either ascending order or descending order. In this type of search, the array is divided into two parts known as subarrays, and the middle element of the array is extracted. This technique is also known as divide and conquer method/technique. To search an element, say “val”, in a sorted array(in ascending order), the val is compared with the middle element first. If the searched value is equal to the middle value, then the index number and position number of this element is returned. If the val is greater than the middle element, then second half of the array becomes new segment in which value to be searched is compared, and if the val is less than the middle element, the first half becomes new segment to be scanned, and this process is repeated until the val is found or the range to be scanned is reduced to single element and still val is not found ( in such case, it is unsuccessful search)

Algorithm for Binary Search

1.  Find the middle element as n/2 where n is total size of the array

2.  Enter the value to be searched in array

3.  Compare the middle element with the value to be searched

4.  If the middle value of the array equals the searched value, the algorithm stops

5.  Otherwise, two conditions will arise :

·  If searched value is less than middle element, then repeat steps 1 to 3

·  If searched value is greater than middle element, the go to step 1 to step 3 for searching subsequent part of the array after middle element

6.  Otherwise , the element is not found and unsuccessful search.

7.  End of the Program