12 Thclass
12 Thclass
CLASS XII
Unit-Wise Marks and Period Distribution
Unit No.
Unit Name
Marks
1.
PROGRAMMING IN C++
30
2.
DATA STRUCTURE
14
3.
4.
BOOLEAN ALGEBRA
5.
10
CONCEPTS
Total
70
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 than data.
2. Change in a datatype being processed needs to be propagated to all the functions that use
the same data type. This is a time consuming process.
3. The procedural programming paradigm does not model real world very well.
Q2. Define Class.
Ans. A Class represents a group of objects that share common properties and relationships.
Exp:-
Class ab
{
statements;
}
ab obj;
Class name is ab
{ } are used to write statements with in it
; is termination symbol of the statement
obj is the object of a Class to access the data members of the class
Q3. What are the features of OOP ?
sent to objects of several different classes. In which the same operation is performed
differently depending upon the data type it is working upon.
Q5.
Ans.
int a;
cin>>a;
int a;
cin>>a;
cout<<a;
The multiple use of input or output operators in one statement is called cascading of
I/O operators
like :
cin>>a>>b;
cout<<a<<b;
(b) Arithmetic Operators
+, - , * , / and %
(c) Increment/ Decrement Operators
Increment Operator (++)
Decrement Operator (- -)
We can use both the operators in postfix and prefix mode as per the requirements in
the program statement
example:- postfix
int a=10;
a++;
cout<<a;
prefix
int a=10;
++a;
cout<<a;
output is a=10
a=11
Note:- The postfix form of ++, --, operators follows the rule use-then change.
The prefix form follows the rules change then use
!=
Exp:-
int result;
Result = marks>= 50 ? P : F ;
(g) Some other operators (sizeof)
sizeof num
//
(num is variable name)
sizeof (type)
//
(c++ data type)
(h) Assignment Operator
Example:
(=)
(i)
(ii)
// Single dimensional
The data type of array elements is known as the Base Type of the array. An ARRAY
is a collection of variables on the same type that are referenced by a common
name.
Q9. Explain Two dimensional array with an example.
Ans.
Declaration of Two Dimensional Arrary
Syntax : - datatype arrname [size] [size]
Example:-
int num[2][5]
// Two dimensional
int main( )
{
int sales [5][5];
int i,j, total ;
for (i=0; i<5, i++)
{
total =0;
cout<< \n;
for (j=0 ; j< 5; j ++)
{
cin>>sales[i][j];
total =total + sales [i][j];
}
cout<< sales is = << total;
}
return 0;
}
\\(escape sequence)
10
class cls_name
{
statement
};
Structure: A structure is a collection of variables of different data types referenced under one name.
Variables defined under structure called with the help of structure object. struct keyword is used to
define structure
struct stru_name
{
type varname;
type varname;
};
stru_name obj_name;
cin>>obj_name.varname;
cout<<obj_name.varname;
Q13. What do you mean by variable ?
i)
Ans. Variables: Variables represent named storage locations whose
values can be manipulated
Volume = 3.1459*r*r*h/3;
Q16. Find the syntax error (s) if if any, in the following program:
#include<iostream.h>
int main()
int x;
cin<< x;
for(int y = 0; y < 10; y++)
cout >> x+y;
Ans
Q17. differentiate between a run-time error and syntax error. Give one example of each.
Ans. While execution, a compiled program may not behave properly because of some errors called
run time errors. For example, divide by zero is a run time error. The following program
segment will generate such an error.The following program segment will generate such an
error
while flag
{
.
b = b-1 ;
term = a/b;
.
}
Array indicates out of bound, and range errors are other examples of run time errors. A
syntax error, on the other hand, is because of misuse of a programming language. Any
violation of a grammatical rule of a programming language will produce a syntax error.
Such errors are caught by language compiler. The following statement is not systactically
correct as far as c++ is concerned .
X= y + z** E;
Q18. What is the difference between an object and a class?
Ans. An object is an identifiable entity with some characteristics and behaviour. It represents an
entity that can store data and its associated functions.
A class is a group of objects that share common properties and relationships
Q19. Write a program to input any number and print in reverse order
Ans in this program the number is input by user
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,s=0;
12
getch();
}
void swap(int a,int b)
{
int t=a;
a=b;
b=t;
cout<<a<<b;
}
Call by reference
#include<iostream.h>
#include<conio.h>
void main()
{
void swap( int &a, int &b);
//prototype of a function
int num1,num2;
clrscr();
cout << enter both numbers: num1 & num2:;
cin>>num1;
cout<< \n;
cin>>num2;
cout<< \n Before swapping numbers are \n;
cout<< num1= <<num1;
cout<< \n;
cout<< num2= <<num2;
cout<< \n;
swap(num1,num2);
//calling of function
cout<< \n After swapping numbers are \n;
cout<< num1= <<num1;
cout<< \n;
cout<< num2= <<num2;
cout<< \n;
getch( );
//for freeze the monitor
}
void swap(int &a, int &b)
//function definition
{
int temp=a;
a=b;
b=temp;
}
Q22. Name the header files of following built in functions :
Strcpy(), strcat(),log(), clrscr(),setw(),fabs(),isalnum(),isupper()
Ans. Strcpy()
string.h
Strcat()
string.h
log()
math.h
clrscr()
conio.h
setw
iomanip.h
fabs()
math.h
isalpnum() ctype.h
isupper()
ctype.h
14
Chapter -2
OBJECT ORIENTED PROGRAMMING
Q1. Give an example of polymorphism.
Ans. Polymorphism (overloading)
Function overloading
If a function name is same and use more than one time with different parameters is called
function overloading.
void num( )
{
int a;
a= 5*10;
void num1 (int a)
{
int b;
b= a*a;
return;
}
Q3.
Ans.
Re-use of code
Based on comprehensive approach
Program can be maintained using encapsulation and hiding of data
Easy to maintain , cost effective
Easy to redesign and easy to extend
Illustrate the concept of function overloading with the help a function namely
Area that return a float type value
A function name having several definitions that are differentiable by the number of types of
their arguments, is known as function overloading.
For example, following code overloads a function area to compute areas of circle, rectangle
and triangle.
float area (float radius)
// for computing area of a circle
{
return 3.14 * radius * radius;
}
flaot area ( float length , float breadth)
// for calculation area
{
return length * breadth;
}
15
Chapter -3
CLASSES AND OBJECTS
Q1. What is class? What is its need?
Classes
A class is a way to bind the data describing an entity and its associated functions together. In
C++ , class makes a data type that is used to create objects of this type.
Need for classes
Classes are needed to represent real-world entities that not only have data type properties
(Characteristics) but also have associated operations (their behaviour)
//global object
int main ( )
{
class num
{
public:
int a=10;
void num( )
{
cout<<num;
};
x ob2;
num n1;
n1.num( );
}
#include<conio.h>
class score
{
int a;
class batesman
{
int b;
// for clrscr()
public:
int c;
void total( )
{
cin>>b>>c;
int sum = b+c;
}
batesman( )
{
c=10;
}
};
// end of class batesman
batesman obj2;
// object of class batesman
void second( void)
{
cout<<score :: second()<<endl;
cout<<A = <<a
}
score( )
{
a= 25;
}
};
//end of class score;
void main()
{
score ab;
batesman bc;
score :: batesman cd;
ab.second();
bc.total();
cd.total();
}
Q4.
Ans.
Q5.
Ans
Q6.
Ans
Q7.
Ans
Q8.
Ans
Q9 .
count ++;
int get_count( )
return count;
{
}
};
void main()
{
counter c1,c2;
cout<< \n value for c1 is: <<c1.get_count( );
cout<< \n value for c2 is: <<c2.get_count( );
c1.inc_count();
c2.inc_count();
c2.inc_count();
cout<< \t c1= <<c1.get_count();
cout<< \t c2= <<c2.get_count();
}
Ans
c2=0
c1=1
c2=2
Chapter 4
CONSTRUCTOR AND DESTRUCTORS
Q1. What is Constructor ?
Ans. Constructors:
A constructor is a special member function of a class that is automatically called, when an
object is created of that class. A member function with the same name as its class is called
constructor.
//constructor
19
}
~stud()
{
}
//destructor
};
stud s1;
Q1.
Ans.
The constructor functions have certain special characteristics:1. Constructor fuctions are invoked automatically when the objects are created.
2. If a class has a constructor, each object of that class will be initialized before any use is
made of the object.
3. No return type can be specified for a constructor
4. They can not be inherited through a derived class can call the base class constructor
5. A constructor may not be static.
6. It is not possible to take the address of a constructor
7. Member functions may be called from within a constructor.
Q2.
Ans
Q3.
void compute();
private:
int x;
char ch;
};
which of the following are valid statements
welcome obj (33, a9);
welcome obj1(50, 9);
welcome obj3();
obj1= welcome (45, T);
obj3= welcome;
Ans.
valid
valid
invalid
valid
invalid
20
Q4 .
Ans
Q5 .
Ans
What is the relationship between constructor and its class? Define constructor also
Both carry the same name. It is a function that automatically initializes the data members of
an object at the time of its creation.
Constructor : It removes the memory held by an object, It is the last member function to be
called. Morevoer, it carries the same name of the class with tidle (~) as prefix.
Q6.
How many time is the copy constructor called in the following code?
Sample func(sample u)
{
sample v(u);
sample w=v;
return w;
}
void main()
{
sample x;
sample y = func(x);
sample z = func(y);
}
Ans . 8 times
Q9.
Chapter 5
INHERITANCE: EXTENDING CLASSES
Q1. What is Inheritance ?
Ans. It is a special feature of OOPS. Inheritance is capability to inherit the properties of one
class in to another class.
The derive new class is called derived class (sub class) and old class is called based class
(super class).
The Class whose properties of data members are inherited, is called Base Class or Super
Class and the class that inherits these properties, is called Derived Class or Sub Class.
Exp1:If Class A inherits the data of Class B then we can say A is Sub Class and B is
Super Class.
Q2. What are the different types of inheritance ?
Ans. Type of Inheritance
1. Single Inheritance
Class automobile
Class car
2. Multiple Inheritance
vehicle
automobile
Car
Base class
Derived class
3. Hierarchical Inheritance
Vehicle
automobile
4. Multilevel Inheritance
Class vehicle
Class automobile
Class Car
22
5. Hybrid Inheritance
It is combination of two or more forms of inheritance.
Q4.
Ans
Q5.
#include <iostream.h>
class book
{
char title[20];
char author[20];
int noof pages;
public:
void read();
void show();
};
class textbook: private textbook
{
int noofchapters, noof assignments;
protected:
int standard;
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 physicsbook.
(iv)
What will be the size of an object (in bytes) of class physicsbook.
Ans
(i)
standard , readtextbook(),showtextbook() and topic;
(ii)
readtextbook() and showtextbook()
(iii) readphysicsbook(), showphysicsbook(), readtextbook() and showtextbook()
(iv)
The size of object of physicsbook= size of book + size of Textbook + size of
physicsbook.
= 42+6+20 = 68 bytes
24
Q6.
Consider the following declarations and answer the questions given below:
Class vehicle
{
int wheels;
protected:
int passenger;
public:
void inputdata( int, int);
void outputdata();
};
class heavyvehicle: protected vehicle
{
int dieselpetrol;
protected:
int load;
public:
void readdata( int, int);
void writedata();
};
class bus:private heavyvehicle
{
char marks[20];
public:
void fetchdata(char);
void displaydata();
};
(i)
Name the class and derived class of the class heavyvehicle.
(ii)
Name the data members that can be accessed from function displaydata()
(iii)
Name the data members that can be accessed by an object of bus class
(iv)
Is the member function outputdata() accessible to the objects of heavyvehicle class.
Ans
(i)
(ii)
(iii)
(iv)
Q7 .
Ans
25
Chapter-6
DATA FILE HANDLING
Q1. Define File .
Ans.A file is a bunch of bytes stored on some storage devices.
Q2.
Ans
Q7.
Ans
Q8.
Ans
Ans
Q14.
Write a function to count the number of blanks present in text file named PARA.TXT;
void countblanks()
{
char ch;
int count=0;
ifstream fin(PARA.TXT,ios::in);
while(!fin.eof())
{
fin.get(ch)
if(fin.eof())
break;
if(ch== )
count++;
}
fin.close();
cout<<count;
}
Write a Program to write and read a structure using write() and read() function using a
binary file
#include<fstream.h>
#include<string.h>
#include<conio.h>
struct customer
{
char name[51];
float balance;
};
27
Ans
void main()
{
clrscr();
customer savac;
strcpy(savac.name,Tina Marshall);
savac.balance=21310.75;
ofstream fout;
fout.open(Saving , ios::out|ios::binary);
if(!fout)
{
cout<<File cant be opened \n;
return 1;
}
fout.write(char *)&savac ,sizeof(customer));
fout.close();
ifstream fin;
fin.open(Saving,ios::in|ios::binary);
fin.read(cahr *)&savac,sizeof(customer));
cout<<savac.name;
cout<<has the balance Rs<<savac.balance<<\n;
fin.close();
}
:- Tina Marshall has the balance Rs 21310.75
{
clrscr();
Student arts[3];
fstream filin;
filin.open(Stu.dat,ios::in|ios::out);
if(!filin)
{
cout<<Cannot open file \n;
return 1;
}
cout<<Enter details for 3 students \n;
for(int i=0;i<=3;i++)
{
arts[i].getdata();
filin.write(char *) &arts[i],sizeof(arts[i]));
}
filin.seekg(0);
cout<<the contents of stu.dat are shown below
for(int i=0;i<=3;i++)
{
filin.read(char *) &arts[i],sizeof(arts[i]));
arts[i].display();
}
filin.close();
}
Chapter -8
POINTERS
Pointers :
-
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.
*variable_name;
float *p1;
float *p1;
char *c;
char *c;
Two special unary operator * and & are used with pointers. The & is a unary operator that returns
the memory address of its operand.
Eg. Int a = 10; int *p; p = &a;
Pointer arithmetic:
Two arithmetic operations, addition and subtraction, may be performed on pointers.
When you add 1 to a pointer, you are actually adding the size of whatever the pointer is pointing at.
That is, each time a pointer is incremented by 1, it points to the memory location of the next element
of its base type.
Eg.
Int *p;
P++;
If current address of p is 1000, then p++ statement will increase p to 1002, not 1001.
If *c is char pointer and *p is integer pointer then
Char pointer
c+1
c+2
c+3
c+4
c+5
c+6
c+7
Address
Int pointer
100
101
102
103
104
105
106
107
p+1
p+2
p+3
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];
}
Memory released with delete as below :
Syntax for simple variable :
For array :
Delete pointer-variable;
Eg. delete p;
Array of Pointers :
To declare an array holding 10 int pointers
31
int * ip[10];
That would be allocated for 10 pointers that can point to integers.
Now each of the pointers, the elements of pointer array, may be initialized. To assign the address of
an integer variable phy to the forth element of the pointer array, we have to write
ip[3] = & phy;
Now with *ip[3], we can find the value of phy.
int *ip[5];
Index
address
0
1000
1
1002
2
1004
3
1006
4
1008
b
23
1065
c
34
2001
d
45
2450
e
56
2725
ip[3]
2450
1006
ip[4]
2725
1008
Variable
Value
address
ip[0] = &a;
a
12
1050
Index
Array ip value
address
ip[0]
1050
1000
ip[1]
1065
1002
ip[4] = &e;
ip[2]
2001
1004
=
=
=
=
=
=
=
<< *(*(x)+2)+1;
<< *(*(x+1)+3);
<< *n;
<< *(n+2);
<< (*(n+3)+1);
<< *(n+5)+1;
<< ++*n;
}
Output with Explanation :
1. * ( *(x+2)+1)
=
2. *(*x+2)+5
=
3. *(*(x+1))
=
4. *(*(x)+2)+1
=
5. *(*(x+1)+3)
=
6. *n
=
7. *(n+2)
=
8. (*(n+3)+1)
=
9. *(n+5)+1
=
10. ++*n
=
12
8
6
4
9
1
3
5
7
2
// integer m declaration
// pointer p to an integer m
// ok : increments int pointer p
// a const pointer c to an intger n
// ok : increments int pointer c i.e. its contents
// wrong : pointer c is const address cant be modified
// a const integer cn
// a pointer to a const int
// wrong : int * pc is const contents cant be modified
// ok : increments pointer pc
// a const pointer to a const integer
// wrong : int *cc is const
// wrong : pointer cc is const
void main()
{
int a, b, *c;
cout << \nEnter a :;
cin >> a;
cout << \nEnter b :;
cint >> b;
c = min(a, b);
cout << \n The minimum no is : << *c;
}
int *min(int &x, int &y)
{
if (x < y )
return (&x);
else
return (&y);
}
Dynamic structures :
The new operator can be used to create dynamic structures also i.e. the structures for which the
memory is dynamically allocated.
struct-pointer = new struct-type;
student *stu;
stu = new Student;
A dynamic structure can be released using the deallocation operator delete as shown below :
delete stu;
Objects as Function arguments :
Objects are passed to functions in the same way as any other type of variable is passed.
When it is said that objects are passed through the call-by-value, it means that the called function
creates a copy of the passed object.
A called function receiving an object as a parameter creates the copy of the object without invoking
the constructor. However, when the function terminates, it destroys this copy of the object by
invoking its destructor function.
If you want the called function to work with the original object so that there is no need to create and
destroy the copy of it, you may pass the reference of the object. Then the called function refers to the
original object using its reference or alias.
Also the object pointers are declared by placing in front of a object pointers name.
Class-name * object-pointer;
Eg. Student *stu;
The member of a class is accessed by the arrow operator (->) in object pointer method.
Eg :
#include<iostream.h>
class Point
{
private :
int x, y
public :
Point()
{
36
x = y = 0;
}
void getPoint(int x1, int y1)
{
x = x1; y = y1;
}
void putPoint()
{
cout << \n Point : ( << x << , << y << );
}
};
void main()
{
Point p1, *p2;
cout << \n Set point at 3, 5 with object;
p1.getPoint(3,5);
cout << \n The point is :;
p1.putPoint();
p2 = &p1;
cout << \n Print point using object pointer :;
p2->putPoint();
cout << \n Set point at 6,7 with object pointer;
p2->getPoint(6,7);
cout<< \n The point is :;
p2->putPoint();
cout << \n Print point using object :;
p1.getPoint();
}
If you make an object pointer point to the first object in an array of objects, incrementing the pointer
would make it point to the next object in sequence.
student stud[5], *sp;
--sp = stud;
// sp points to the first element (stud[0])of stud
sp++;
sp + = 2;
sp--;
You can even make a pointer point to a data member of an object. Two points should be considered :
1.
A Pointer can point to only public members of a class.
2.
The data type of the pointer must be the same as that of the data member it points to.
this Pointer :
In class, the member functions are created and placed in the memory space only once. That is only
one copy of functions is used by all objects of the class.
Therefore if only one instance of a member function exists, how does it come to know which
objects data member is to be manipulated ?
37
Member Function1
Object 1
Member Function2
Object 2
Member Function3
Object 3
Data Member 1
Data Member 1
Data Member 1
Data Member 2
Data Member 2
Data Member 2
For the above figure, if Member Function2 is capable of changing the value of Data Member3 and
we want to change the value of Data Member3 of Object3. How would the Member Function2 come
to know which Objects Data Member3 is to be changed ?
To overcome this problem this pointer is used.
When a member function is called, it is automatically passed an implicit argument that is a pointer to
the object that invoked the function. This pointer is called This.
That is if ojbect3 is invoking member function2, then an implicit argument is passed to member
function2 that points to object3 i.e. this pointer now points to object3.
The friend functions are not members of a class and, therefore, are not passed a this pointer.
The static member functions do not have a this pointer.
Summary :
Pointers provide a powerful way to access data by indirection. Every variable has an address, which
can be obtained using the address of operator (&). The address can be stored in a pointer.
Pointers are declared by writing the type of object that they point to, followed by the indirection
operator (*) and the name of the pointer. Pointers should be initialized to point to an object or to null
(0).
You access the value at the address stored in a pointer by using the indirection operator (*). You can
declare const pointers, which can't be reassigned to point to other objects, and pointers to const
objects, which can't be used to change the objects to which they point.
To create new objects on the free store, you use the new keyword and assign the address that is
returned to a pointer. You free that memory by calling the delete keyword on the pointer. delete frees
the memory, but it doesn't destroy the pointer. Therefore, you must reassign the pointer after its
memory has been freed.
Solved Questions
Q. 1 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. 2 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. 3 Find the error in following code segment :
Float **p1, p2;
P2 = &p1;
38
Ans : In code segment, p1 is pointer to pointer, it means it can store the address of another pointer
variable, whereas p2 is a simple pointer that can store the address of a normal variable. So
here the statement p2 = &p1 has error.
Q. 4 What will be the output of the following code segment ?
char C1 = A;
char C2 = D;
char *i, *j;
i = &C1;
j = &C2;
*i = j;
cout << C1;
Ans : It will print A.
Q. 5 How does C++ organize memory when a program is run ?
Ans : Once a program is compiled, C++ creates four logically distinct regions of memory :
(i)
area to hold the compiled program code
(ii)
area to hold global variables
(iii)
the stack area to hold the return addresses of function calls, arguments passed to the
functions, local variables for functions, and the current state of the CPU.
(iv)
The heap area from which the memory is dynamically allocated to the program.
Q. 6 Identify and explain the error(s) in the following code segment :
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;
Ans : The erroneous statements in the code are :
j = j * 2;
k = k / 2;
Because multiplication and division operations cannot be performed on pointer and j and k
are pointers.
Q. 13 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 the
object by just copying the contents of the passed object. It invokes the objects copy
constructor to create its copy of the object. However, the called function destroys its
copy of the object by calling the destructor function of the 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.
UNSOLVED QUESTIONS
1.
Differentiate between static and dynamic allocation of memory.
2.
Identify and explain the error in the following program :
#include<iostream.h>
int main()
{
39
int x[] = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
{
cout << *x;
x++;
}
return 0;
3.
4.
5.
6.
7.
8.
9.
}
Give the output of the following :
char *s = computer;
for (int x = strlen(s) 1; x >= 0; x--)
{
for(int y =0; y <= x; y++)
cout << s[y];
cout << endl;
}
Identify the syntax error(s), if any, in the following program. Also give reason for errors.
void main()
{
const int i = 20;
const int * const ptr = &i;
(*ptr++;
int j= 15;
ptr = &j; }
What is this pointer ? What is its significance ?
Are pointers really faster than array ? How much do function calls slow things down ? Is
++i faster than i = i + 1 ?
What will be the output of following program ?
#include<iostream.h>
void main()
{
char name1[] = ankur;
char name2[] = ankur;
if (name1 != name2)
cout << \n both the strings are not equal;
else
cout << \n the strings are equal;
}
Write a function that takes two string arguments and returns a string which is the larger
of the two. The larger string has larger ASCII value. Also show how this function will be
invoked.
Give and explain the output of the following code :
void junk (int, int *);
int main()
{
int i = 6, j = -4;
junk (i, &j);
cout << i = << i << , j = << j << \n;
return 0;
}
void junk(int a, int *b)
{
a = a* a;
*b = *b * *b;
}
40
10.
What is wrong with the following while loops ( ans how does the correct ones look like):
(i)
Ans
counter + +;
}
(ii) In this loop there are not brackets surrounding the code block of the while loop.
Therefore, only the line immediately following the while statement repeats. To fix, we need
to add grouping bracket around the indented lines after the while statement i.e. as :
Q2.
Ans
while (counter<10)
{
cout<<counter<<\n;
counter++;
}
Write a c++ function that converts a 2-digit octal number into binary number and
prints the binary equivalent.
Assume that a header file and main() is including in a program
The function is as follows:
Void octobin(int oct)
{
long binn=0;
41
int a[6];
/*Each octal digit is converted into 3 bits thus for 2 octal digits
-- space for 6 bits has been reserved here*/
int d1,d2,q,r,;
d1=oct%10;
d2= oct/10;
for int (i=0; i<6; i++)
{
a[i] =0;
}
for (i=0; i<3; i++)
{
q=d1/2;
r=d1%2;
a[i]=r;
d1=q;
}
for ( ; i<6;i++)
{
q=d2/2;
r=d2%2;
a[i]=r;
d2=q;
}
for (i=i-1; i>=0;i - -)
{
binn * =10;
binn += a[i];
}
cout<<endl<<binn<<endl;
}
Q3.
Ans
Write a program that the roll numbers, marks in English, Computers, Maths out of 100 for
50 students (i.e. need no read them)
Write a function in c++, using structures, to calculate the following:(i)
(ii)
(iii)
Ans
#include<iostream.h>
#include<conio.h>
const int size=50;
struct kvstudent
{
int kvrollno;
float kveng;
float kvcomp;
float kvmaths;
}
kvstudent sarr[size],t1,t2;
float total,avg,top1=0,top2=0;
int ndist=0, nfail=0;
void kvresult()
{
clrscr();
for (int= 0;int<size;i++)
{
total= sarr[i].kveng + sarr[i].kvcomp+sarr[i].kvmaths;
avg= total/3;
if (avg>=75)
ndist++;
else if(avg<40)
nfail++;
if(top1<avg)
{
top1=avg;
t1=sarr[i];
}
43
What do you think about polymorphism and how you can explain for effective coding
as a part of Object Oriented Language?
Ans
Polymorphism in an object oriented programming language works under main() and with
statements like decision statements and looping statements and works under the pointers and
structures. A polymorphism is also be understandable as a function overloading. This is the
ability of an object to behave differently in different circumstances can effectively be
implemented in programming through function overloading.
It helps in coding to represent the same function in different modes of program. The
programmer is relieved from the burden of choosing the right function for a given set of
values. This important responsibility is carried out by the compiler when a function is
overloaded.
Q6.
Ans
Binary Operator can be overloaded in the same manner as unary operator. We can take an
example of overloading equal to (= =) operator.
We will use this operator to compare the strings, returning values true if strings are same
and false otherwise.
Program of overloading binary operator(= =), declaration of functions inside the class.
#include <iostream.h>
#include<string.h>
enum boolean { true , false };
// use of enum
class string
{
private:
char s[100];
public:
string()
{
strcpy(s, );
}
44
Deposit:: Deposit()
{
principal =time=rate=0.0;
}
Deposit:: Deposit(long p, int t, float r)
{
principal=p;
time=t;
rate =r;
}
Deposit:: Deposit(long p, int t)
{
principal=p;
time=t;
rate =0.07;
}
Deposit:: Deposit(long p, float r)
{
principal=p;
time=4;
rate =r;
}
void Deposit::calc_amt(void)
{
totat_amt= principal +(principal *time * rate)/100;
}
void Deposit::display (void)
{
cout<< \n Principal Amount : Rs.<<principal;
cout<< \n Period of Investment: << time << years;
cout<< \n Rate of intrest :<<rate;
cout<< \n Total amount is:Rs. :- > <<total_amt;
}
void main()
{
clrscr();
Deposit D1;
Deposit D2(5000,2,0.05);
Deposit D3(6000,4);
Deposit D4(4000,0.08);
D1.calc_amt();
D2.clac_amt();
D3.calc_amt();
D4.clac_amt();
cout<< \n display of object One is: ;
D1.display();
cout<< \n display of object Two is: ;
46
Q8.
D2.display();
cout<< \n display of object Three is: ;
D3.display();
cout<< \n display of object Four is: ;
D4.display();
}
Find the errors in the following program. State reasons:
#include<iostream.h>
class A
{
int a1;
public:
int a2;
protected:
int a3;
};
class B: public A
{
public:
void func()
{
int b1,b2,b3;
b1=a1;
b2=a2;
b3=a3;
}
};
class C: A
{
public:
void f()
{
int c1,c2,c3;
c1=a1;
c2=a2;
c3=a3;
}
};
int main()
{
int p,q,r,i,j,k;
B 01;
C 02;
p=01.a1;
q=01.a2;
r=01.a3;
i=01.a1;
j=01.a2;
k=01.a3;
47
return 0;
Ans
Q9.
8
8
Write a program that reads a string and counts the number of vowels, words and blank
spaces present in the string.
Ans
#include<iostream.h>
#include<stdio.h>
main()
Q11
Ans
48
1.
2.
3.
4.
Q12
Name the header file for using in built functions in the program
(i) setw(), (ii) puts(), (iii) isdigit(), (iv) fabs()
Ans
Q13. Write a program to generate a function with parameters and array in function
e.g. show is function name
then
show(int[ ],int);
Ans
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[5];
void show(int[],int);
// declaration of a function (prototype)
cout<<"enter the number=";
for(int i=0;i<5;i++)
{
cin>>a[i];
}
cout<<"ARRAYS"<<endl;
show(a,5);
// calling of function
getch();
// for freeze the monitor
}
void show(int s[ ],int n)
//defining of a function
{
for(int i=0;i<n;i++)
{
cout<<s[i]<<endl;
}
}
Q. 14 What will be the output of following code fragment ?
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[] = {3, 5, 6, 7};
int *p, **q, ***r, *s, *t, ** ss;
p = a;
s = p + 1;
q = &s;
t = (*q + 1);
49
ss = &t;
r = &ss;
cout << *p << \t << **q << \t << ***r << end;
}
Ans : 3
Q15
What is the relationship between an array and a pointer ? Given below a function to tranverse
a character array using For-loop. Use a pointer in place of an index X and substitute for-loop
with while-loop so that the output of the function stringlength() remains the same.
int strlength(char s[])
{
int count = 0;
for (int x = 0; s[x]; x++)
cout ++;
return (count);
}
Ans : The relationship between an array and a pointer is that the name of an array is actually a
pointer pointing to the first element of the array.
int strlength(char s[])
{
int count = 0;
while (*s)
{
count++;
s++;
return (count);
Q16
}
}
Give the output of the following program segment : (assuming all required header files
are included in the program)
char *name = KenDriYa;
for (int x = 0; x < strlen(name); x++)
if (islower (name[x]} )
name[x] = toupper (name[x]);
else
if ( isupper (name[x]) )
if (x%2 != 0)
name[x] = tolower (name[x-1])
else
name[x]--;
cout << name << endl;
Ans : jENnRIXA
Q17
What do you under by memory leaks ? What are the possible reasons for it ? How can
memory leaks be avoided ?
Ans : If the objects, that are allocated memory dynamically, are not deleted using delete, the
memory block remains occupied even at the end of the program. Such memory blocks are
known as orphaned memory blocks.
50
This orphaned memory blocks when increase in number, bring as adverse effect on the
system. This situation is known as memory leak. The possible reasons for this are :
(i)
A dynamically allocated object not deleted using delete.
(ii)
Delete statement is not getting executed because of some logical error.
(iii)
Assigning the result of a new statement to an already occupied pointer.
The memory leaks can be avoided by
(ii)
making sure that a dynamically allocated object is deleted.
(iii)
A new statement stores its return values (a pointer) in a fresh pointer.
Q18 Predict and explain the output of the following program :
Ans : #include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
float x = 5.999;
float *y, *z;
y = &x;
z = y;
cout << x << , << (&x) << , << *y << , << *z << \n;
return 0;
}
Ans : The output of this program will be
5.999, 5.999, 5.999, 5.999
The reason for this is x gives the value stored in the variable x. *(&x) gives the data value
stored in the address &x i.e. address of x i.e. the data value of x. Since y points to x ( y =
&x), *y gives the value of x. And because z has the same address as that of y. *z also gives
the value of x i.e. 5.999.
Q19
Ans :
26
26
182
7
208
208
51
Unit II
Chapter -9 & 10
ARRAYS & LINKED LIST
Defination of Datastructure
A data structure is a logical method of representing data in memory using the simple and complex
data types provided by the language.
Arrays:
An array is collection of the homogeneous elements that are referred by a common name. It is also
called a subscripted variable as the elements of an array are used by the name of an array and an
index or subscript.
Array are of two types:
1. One-dimensional arrays
2. Multi-dimensional arrays.
Address Calculation:
The array elements are stored in contiguous memory locations by sequential allocation technique.
Address of arr[i] = B+(I-LB)*S
Sequential Allocation:
The process of storing elements in a fixed order in a data structure where the time required for such
access is dependent on the order of the elements.
Using Row Major order the add of a [i] [j] is given by,
Address of a [i] [j]= B+[(i-LB1)*N+(j-LB2)]*S
Using column Major order the add of a [i] [j] is given by,
Address of a [i] [j]= B+[(i-LB1)+(j-LB2)*M]*
One Dimensional Array:
The simplest type of data structure is a one dimensional array in which each elements of a
linear array is referenced by one subscript.
The operations one normally perform on any linear structure include the following:
(a) Traversal: processing each elements in the list.
(b) Search: finding the location of the element with a given value or the record with a given key.
Linear Search: this is a neutral searching method in which we search for a element by
traversing through the entire list from beginning until we get the element.
Binary Search: the search can be made faster by an algorithm in which the list or the array
should be sorted in advance is called binary search.
(c) Insertion: adding a new element to the list.
(d) Deletion: removing an element from the list.
(e) Sorting: arranging the elements in some types of order.
Insertion sort: this sorting method divides the list into sorted part and unsorted part. It
picks up one element from the front of the unsorted part and inserts it at its proper place in
the sorted part and repeats this action till the unsorted part is exhausted.
Selection sort: it is very simple way of sorting data stored in a one dimensional array. All
the elements in the array are searched for the smallest element. The selected element is
exchanged with the first element in the array.
Bubble sort: it is also very simple sorting algorithm. This method proceeds by looking the
array for left to right, and whenever a pair of adjacent elements is found to be out of order,
52
the elements are exchanged. Therefore, after the first pass, the largest element is the array
will have bubble up to one end of the array.
(f) Merging: merging is the process of combining two or more sorted arrays into another array
which is also sorted.
Concatenation of Two Linear Array
Concatenation means joining the element of two arrays to form a new array. First copy all
the elements of one array and then copy all the elements of other array into the new array.
The size of the concatenated array must be equal to or greater than that of the sum of sizes of
the two arrays to be concatenated.
Two Dimensional Array:
A two dimensional array(having two subscripts) is suitable for table processing or matrix
manipulation.
Traversal: it means visiting each element one after the other.
Finding sum/difference of two NM arrays containing numeric values:
The sum/difference of two NM arrays containing numeric values can be obtained by
adding/subtracting the corresponding elements of the two arrays. The result can either be
directly displayed on monitor or stored into third array of size NM and then this resulting
array can be displayed.
For example, the sum of two arrays A and B of size 32 is shown below.
4
6
5
2
9
8
7
1
1
8
8
9
5
3
2
4
7
7
Array A
Array B
resultant after addition
If difference of two arrays of size 33 is required then we get result as illustrated by the following
example :
40
18
70
25
55
62
Array A
73
29
47
31
10
20
20
36
32
Array B
41
15
17
9
5
32
8
19
14
50
30
30
Result after difference
For example,
1
4
7
Given
2
5
8
Array
3
1
4
6
2
5
9
3
6
Array after interchange
7
8
9
Stacks :
A stack is a list of elements in which an element may be inserted or deleted only at one end, called
the TOP of the stack. This means, in particular, that elements are removed from a stacks in the
reverse order of that in which they were inserted into the stack.
53
Deletion from a linked stack (popping) :-Deletion i.e., popping also requires modification of top , that is , top is made to point to the next
node in the sequence as shown:---
Solved Questions
Q1.
Ans.
What is the difference between linear and non- linear data structures?
Single level data structures where elements form a sequence are called linear data structures
eg. Stacks, queues, linked list etc. are linear data structures.
54
Q2.
Ans.
Q3.
Ans.
Q4 .
Ans.
Q5 .
Ans.
Multilevel data structures are called non-liner data structures eg. Trees and graphs are nonlinear data structures.
Describe the similarities and differences between queues and stacks.
Similarities:
(a)
Both queues and stacks are special cases of linear lists.
(b)
Both can be implemented as arrays or linked lists.
Dissimilarities :
(a)
A Stack is a LIFO list, a queue is a FIFO list.
(b)
There are no variations of a stack, a queue, however, may be circular or dequeue.
What is meant by the term Overflow & Underflow?
Overflow means attempt to INSERT when the list is full and no free space is available.
Underflow means attempt to DELETE an item from an empty list.
Distinguish between infix, prefix and postfix algebric expression giving examples of
each.
Infix Notation : In this notaion, the operator symbol is placed in between the operands eg.
A+B, (A-C)* B
Prefix Notation : In this notation, the operator symbol is placed before its operands eg.
+AB, *-ACB
Postfix Notation : In this notation, the operator symbol is placed after its operands eg.
AB+, AC-B*, ABC*+
Evaluate the following postfix notation of expression, show status of stack for each
operation
500, 20, 30, + , 10, * , +
Adding ] to mark the end of given postfix expression ie. 500, 20, 30 +, 10, *, + ]
First 500 will be added to the stack, then 20 and then 30.
Then we get an operator + so 20 will be added to 30 and pushed to the stack. Then 10 is
pushed to the stack.
Then * operator is found thus it multiplies 10 with 50 and the result is pushed into the stack.
Then again + operator is found which adds 500 with 500 that is placed in the stack. And we
get the result 1000.
Unsolved Questions
Q. 1. How is computer memory allotted for a 2D array?
Q. 2. Binary search is to be used on the following sorted array to search for 30 and 60.
1
2
3
4
5
6
7
8
Index:
11
22
30
33
40
44
55
60
66
Value:
Give the index of the element that would be compared with at every step. Repeat the process
replacing 30 by 60.
10
70
Q. 3. Consider the single dimensional array AAA [45] having base address 300 and 4 bytes is the
size of each element of the array. Find the address of AAA [10], AAA [25] and AAA [40].
55
Q. 4. Given two dimensional array A[10][20], base address of A being 100 and width of each
element is 4 bytes, find the location of A[8][15] when the array is stored as a) column wise b) Row
wise.
Q. 5. Write a C++ function to find and display the sum of each row and each column of a 2
dimensional array of type float. Use the array and its size as parameters with float as the return type.
Q. 6. Differentiate between a FIFO list and LIFO list.
Q. 7. Transform the following expression to prefix and postfix form:
(A+B*C-D)/E*F
Q2.
Ans.
Q3.
Ans.
=1000+56
=1056
UNIT III
Chapter 11 & 12
DATABASE CONCEPTS & SQL
Database :
Database is a collection of different kinds of data which are connecting with some relation.
In different way, it is a computer based record keeping system. The collection of data referred to as a
database.
Purpose of Database :
Years ago, for keeping record, a typical file-processing system is used. A number of different
application programs are written to extract records from and add records to the appropriate files. But
this scheme has a number of major limitations and disadvantages, such as data redundancy, data
inconsistency, unsharable data, unstandardized data, insecure data, incorrect data, etc.
A database management system is answer to all these problems as it provides a centralized control of
the data.
1.
2.
3.
4.
5.
6.
Data : It is row facts, figures, characters, etc with which we have to start.
Information : The processed data or meaningful data is known as information.
Database : An organized collection of relational data is called as database.
DBMS : It is a Database Management System. It is a system to used for create database, store the
data, secure it and fetch data whenever required. MS Access, Oracle is the example of DBMS.
Database Abstraction :
A major purpose of a database system is to provide the users only that much information that is
required by them. This means that the system does not disclose all the details of data, rather it hides
certain details of how the data is stored and maintained. A good database system ensures easy,
smooth and efficient data structures in such a way so that every type of database user : end user,
application system analyst, and physical storage system analyst, is able to access its desired
information efficiently.
Various Levels of Database Implementation :
1.
2.
3.
Internal Level (Physical Level) : This level describes how the data are actually stored
on the storage medium. At this level, complex low-level data structures are described in
details. Eg. RollNo is in Byte(4), offset = 34.
Conceptual Level : It describes what data are actually stored in the database. It also
describes the relationships existing among data. Eg. ItemCode is in Numeric(5).
External Level (View Level Logical Level) : This is the level closest to the users. It is
concerned with the way in which the data are viewed by individual users. Most of the
users of the database are not concerned with all the information contained in the database.
Eg. View 1 contains RollNo, Name, DOB.
57
Data Independence :
The ability to modify a scheme definition in one level without affecting a scheme definition in the
next higher level is called Data Independence.
i.
Physical Data Independence : It refers to the ability to modify the scheme followed at the
physical level without affecting the scheme followed at the conceptual level.
ii.
Logical Data Independence : It refers to the ability to modify the conceptual scheme
without causing any changes in the schemes followed at view levels.
Data Models :
The external level and conceptual level user certain data structures to help utilize the database
efficiently. There are three data models that are used for database management system are :
1. Relational Data Model
2. Hierarchical Data Model 3. Network Data Model
THE RELATIONAL MODEL :
The relational model was propounded by E.F. Codd of the IBM and has since been acknowledged as
a very important concept in DBMS. The relational model has established itself as the primary data
model for commercial data processing applications.
Relation : A relation is a table, i.e. data arranged in rows and columns.
Domain : It is a pool of values from which the actual values appearing in a given column are drawn.
Item#
101
102
103
101
102
103
Item Numbers
Item_Name
Computer
Chair
Table
Fund
VVN
SF
SF
Item_Master
Item#
101
101
102
102
103
Purchase_Master
Pur_Date
Supplier
25/04/2007 Super Mart Computers
15/05/2008 Supreme Computers
21/03/2007 Sharma Furnitures
11/12/2007 Shiv Furnitures
12/02/2008 Sharma Furnitures
Quantity
20
25
50
24
30
Eg. The values appearing in the ItemCode# column of both the Item_Master table and the
Pur_Master are drawn from the underlined domain of all valid Item Codes.
A domain is said to be atomic if elements of the domain are considered to be indivisible units.
Tuple : The rows of tables are generally referred to as Tuples.
Attributes : The columns of tables are generally referred to as attributes.
Degree : The number of attributes in a relation determine the degree of a relation. A relation having
5 attributes is said to be a relation of degree 5.
Cardinality : The number of tuples in relation is called the Cardinality of the relation. Eg.
Cardinality of Purchase_Master relation is 5.
58
Views :
A view is a kind of table whose contents are taken from other tables depending upon a conditions.
Views do not contain data of their own. The contents of a view are determined by carrying out the
execution of the given query.
A view is a virtual table that does not really exists in its own right but is instead derived from one or
more underlying base table(s).
Keys : It is important to be able to specify how rows in a relation are distinguished conceptually,
rows are distinct from one another, but from a database perspective the difference among them must
be expressed in terms of their attributes. Keys come here for a rescue.
Primary Key : It is a set of one or more attributes that can uniquely identify tuples within the
relation. Eg. Item# is the primary key for Item_Master.
Candidate Key : All attributes combinations inside a relation that can serve as primary key are
Candiadate keys as they are candidates for the Primary Key position.
Alternate Key : A candidate key that is not the primary key is called an alternate key.
Foreign Key : A non-key attribute, whose values are derived from the primary key of some other
table, is known as Foreign Key in its current table. Here Item# of Purchase_Master is foreign key,
because it is derived from Item_Master.
Referential Integrity : It is a system of rules that a DBMS uses to ensure that relationships between
records in related tables are valid, and that users dont accidentally delete or change related data.
The Relational Algebra :
It is set of operations that can be used to manipulate relations. Each operation operates on one or
more than one relation and produces a new relation.
(i)
Union : If the degree of two relations is same and their corresponding attributes are
defined on the same domain then the relations are called union compatible. The operator
for union is ;
Ex : C = A B
(ii)
Intersection : If two relations A and B are union compatible then they can also
participate in an intersection operation. Its result is the common tuples. The operator for
intersection is ;
Ex : C = A B
(iii)
Difference : The operator is -;
Ex : C = A B
The tuples of C are belonging to A which do not belong to B.
(iv)
Cartesian Product : It returns a concatenation of each tuple of A with each tuple of B.
Ex : C = A X B
(v)
Select :Whenever user desires to search or select tuples of a relation depending upon a
condition being true, the operation is known as a select operation. The operator is .
Ex : marks > 95 (Students)
(vi)
Projection : A projection operation on a relation produces a vertical subset of the relation
in the sense that it returns the relation minus certain columns.
Ex : name, roll (Students)
(vii) Natural Join ( |X| ) :
If two relations A and B have at least one common attribute then they can participate in a
Join operation. The resultant relation contains the attributes of both A and B.
SQL is the set of commands that is recognized by nearly all RDBMS. It is a language that enables us
to create and operate on relational databases, which are sets of related information stored in tables.
Processing Capabilities of SQL :
1.
2.
3.
4.
5.
6.
7.
Data Definition Language : The SQL DDL provides commands for defining relation
schemas, deleting relations, creating indexes, and modifying relation schemas.
Interactive Data Manipulation Language : The SQL DML includes a query language
based on both the relational algebra and the tuple relational calculus. It includes also
commands to insert, delete and modify tuples in the database.
Emedded Data Manipulation Language : The embedded form of SQL ids designed for
use within general-purpose programming languages such as PL/1, Cobol, Fortran, etc.
View Definition : The SQL DDL also includes commands for defining views.
Authorization : The SQL DDL includes commands for specifying access rights to
relations and views.
Integrity : The SQL provides forms of integrity checking. Future products and standards
of SQL are likely to include enhanced features for integrity checking.
Transaction Control : SQL includes commands for specifying the beginning and ending
of transactions along with commands to have a control over transaction processing.
1. Procedural DMLs require a user to specify what data is needed and how to get it.
2. Non-procedural DMLs require a user to specify what data is needed without specifying how
to get it.
INSERT INTO, DELETE, SELECT, LOCK TABLE, etc.
TCL Commands :
A transaction is successfully completed if and only if all its constraints steps are successfully
completed. To manage and control the transactions, the transaction control commands are used.
COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION
Schema Objects :
A schema refers to the collection of logical structures of data.
Eg. Clusters, Database triggers, Indexes, Packages, Stored Functions, Procedures, Tables, Views.
Data Types :
Data Types are means to identify the types of data and associated operations for handling it.
There are various data types in Oracle :
1.
2.
3.
4.
5.
6.
7.
8.
Varchar2(size) : Variable length character string having maximum length size bytes.
Number(p, s) : Number having precision p and scale s.
Long : Character data of variable length up to 2 gigabytes.
Date : Valid date range from January 1, 4712 BC to December 31, 4712 AD.
Raw(size) : Raw binary data of length size bytes.
Long Raw : Raw binary data of variable length up to 2 gigabytes.
Rowid : Hexadecimal string representing the unique address of a row in its table.
char(size) : Fixed length character data of length size bytes.
Constraints :
Constraints are the means by which user can prevent invalid data entry into the table.
i.
Not Null constraint : It ensures that the column cannot contain a NULL value.
Create Table Student
(RollNo number(2) Not Null,
Name varchar2(20) Not Null,
Dob date,
City varchar2(20) );
61
ii.
Unique constraint : A candidate key is a combination of one or more columns, the value
of which uniquely identifies each row of a table.
Create table student
(RollNo number(2) Unique,
Name varchar2(20) Not null,
Dob date,
City varchar2(20) );
iii.
Primary Key : It ensures two things : (i) Unique identification of each row in the table.
(ii) No column that is part of the Primary Key constraint can contain a NULL value.
Create table student
(RollNo number(2) Primary Key,
Name varchar2(20) Not null,
Dob date,
City varchar2(20) );
iv.
v.
Check Constraint : Sometimes we may require that values in some of the columns of
our table are to be within a certain range or they must satisfy certain conditions.
Create table Employee
(EmpNo number(4) Primary Key,
Name varchar2(20) Not null,
Salary number(6,2) check (salary > 0),
DeptNo number(3)
);
2.
Create View :
A view is defined as a logical table based on a database table or another view.
Syntax :
Create View <view name> As Select <column list> from <table name>[Where <condition>];
Eg.
3.
Drop Table :
It is used to delete a table.
Syntax :
Drop Table <table name>;
Eg.
Drop Table student;
4.
Drop View :
It is used to delete a view.
62
Syntax :
Eg.
5.
6.
7.
Insert into :
To insert data into the table.
Syntax :
Insert into <table name> [<column list>]
Values (<list of values>);
1.
2.
8.
9.
Select :
To fetch data from the table or a group of tables.
Syntax :
63
Group By Clause :
The rows of a table can be grouped together based on a common value by using the Group By clause
of SQL in a select statement.
Syntax :
SELECT <attribute name>, <attribute name> ---- [functions]
FROM <relation name>
64
Unsolved Questions :
1. Write SQL commands for (i) to (iv) and give outputs for (v) to (viii) for the given table
Library.
B_Code Title
Author
Type
Pub
Price
102
C++
S P Mathur
Prog
McGraw
150
206
VB
M K Sharma Prog
BPB
175
355
DOS Guide
Norton
OS
PHI
250
392
Mastering
Cowart
OS
BPB
510
Windows
455
Network
Norton
Net
ZPress
410
Concepts
(i)
Select all the BPB publication books from the library.
(ii)
Display different book type from the library.
(iii)
Display book title in order by their price.
(iv)
Insert a record in table with the details (324, JAVA, Palmer, Prog, McGraw,
300)
(v)
Select count(*) from library;
(vi)
Select max(price) from library where pub = BPB;
(vii) Select sum(price) from library where type = OS;
(viii) Select title, type from library order by B_Code desc;
2. Write SQL commands for (i) to (vi) for the given table Employee.
EmpNo
2045
1265
4502
4007
1101
(i)
Name
Designation
Dept
M K Sharma
Clerk
Finance
S P Yadav
Manager
Finance
M L Mourya
Account
Finance
J P Singh
Clerk
Computer
K Natarajan
Administrator
Purchase
Display all the records of the table Employee
Salary
15000
25000
20000
12500
32500
65
(ii)
(iii)
(iv)
(v)
(vi)
Q2.
All candidate keys, which are not the primary key of the table are called alternate keys.
(i)
Ans.
(ii)
Ans.
(iii)
Ans.
(iv)
Ans.
(v)
Ans.
SenderCity
Mumbai
66
New Delhi
(vi)
Ans.
(vii)
A.SenderName
B.RecName
R Jain
H Singh
S Jha
P K Swamy
Ans.
RecName
RecAddress
S Mahajan
116, A Vihar
S Tripathi
RecID
RecName
ND08
S Mahajan
ND48
S Tripathi
67
Unit -IV
CHAPTER- 13
BOOLEAN ALGEBRA
Boolean algebra
Boolean algebra:- a modern algebra which uses the set of numbers 0 and 1,the logic numbers used to
solved logic problems.
Binary decision:-. The decision which results into yes or no. Also called logical statements or truth
function.
Truth table:- a table representing all possible input-output combinations for a given logical
problem/expression.
Tautology:-a Boolean expression that always results in true or 1.
Fallacy:-a Boolean expression that always results in false or 0.
Cononical expression :- a Boolean expression having all minterms or maxterms.
Minterm:-product of all the literals(with or without the bar) within the logic system.
Maxterm:-sum of all the literals(with or without the bar) within the logic system.
Karnaugh Map:- it is a graphical representation of the truth table of the given expression.
Logic Gates
Logic gates serve as the building blocks to digital logic circuits using combinational logic. We're
going to consider the following gates: NOT gates (also called inverters), AND gates, OR gates,
NAND gates, NOR gates, XOR gates, and XNOR gates.
We'll also discuss the concept of gate deltay.
NOT gates
NOT gates or inverters have a single bit input and a single bit of output.
This is a diagram of a NOT gate. It is a triangle with a circle on the right. The circle indicates
"negation".
AND2 gates
AND2 gates have two bits of input and a single bit of output. The subscript, 2, indicates how many
inputs this AND gate has. For example, AND3 gates have 3 inputs.
The output of AND2 gate is 1 only if both inputs are 1. Otherwise, the output is 0.
x1
x0
OR2 gates
OR2 gates have two bits of input and a single bit of output. The subscript, 2, indicates how many
inputs this OR gate has. For example, OR3 gates have 3 inputs.
The output of OR2 gate is 0 only if both inputs are 0. Otherwise, the output is 1.
x0
NAND2 gates
NAND2 gates have two bits of input and a single bit of output. The subscript, 2, indicates how many
inputs this NAND gate has. For example, NAND3 gates have 3 inputs.
NANDk gates is define unusually. Since NAND2 is not associative, the definition is based on AND2.
In particular
x0
NOR2 gates
OR2 gates have two bits of input and a single bit of output. The subscript, 2, indicates how many
inputs this OR gate has. For example, NOR3 gates have 3 inputs.
The output of NOR2 gate is the negation of OR2.
x0
tables.
The function is not associative. This can be verified by using truth tables.
Because of these properties, NORk is defined from ORk, and not built from NOR2 gates.
XOR2 gates
XOR2 gates have two bits of input and a single bit of output.
The output of XOR2 gate is 1 only if the inputs have opposite values. That is, when one input has
value 0, and the other has value 1.. Otherwise, the output is 0.
This is called exclusive-or. The definition of OR2 is inclusive-or, where the output is 1 if either input
is 1, or if both inputs are 1.
XOR2 can be defined using AND2, OR2, and NOT.
If you look carefully at the drawing of the gate, there is a second arc behind the first one near the
inputs. Since this second arc is hard to see, it's usually a good idea to write the word "XOR" inside
the gate.
The truth table defines the behavior of this gate.
x1
x0
XNOR2 gates
XNOR2 gates have two bits of input and a single bit of output.
The output of XNOR2 gate is the negation of XOR2 and has 1 when both inputs are the same.
71
If you look carefully at the drawing of the gate, there is a second arc behind the first one near the
inputs. Since this second arc is hard to see, it's usually a good idea to write the word "XNOR" inside
the gate.
The truth table defines the behavior of this gate.
x1
x0
Solved questions
Q1.
Ans
Principal of duality states that from every Boolean relation, another Boolean relation can be
derived by
i) Changing each OR sign(+) to an AND sign(.)
ii) Changing each an AND sign(.) to an OR sign(+)
iii) Replacing each 1 with 0 and each 0 with 1
Q2. Define the following terms:
(a) Logical constant
(b) Logical variable
(c) Binary valued quantity
(d) Boolean literal
Ans:- (a) the truth values true(1) or false(0)are known as logical constants.
(b) A variable that can store the truth-values (TRUE or FALSE) is called logical variable.
(c ) quantity can be represented in terms of TRUE or FALSE is known as binary valued
quantity.
(d) a single Boolean variable(logical variable) or its complement e.g X or Y or Z is known
as literals.
Q3. State Demorgans laws.
____
Ans Demorgans first law: -it states that X+Y= X.Y
____
Demorgans second law: -it states that X.Y=X+Y
72
Q4 .
Ans.
Q5.
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Ans.
In SOP F= (1,2,3,5,7)
=XYZ+X YZ+ XYZ+XYZ
In POS F=(0,3,4,6)
=(X+Y+Z)(X+Y+Z) (X+Y+Z)(X+Y+Z).
Q6.
0
1
1
0
0
1
0
1
Ans.
X
0
0
1
1
0
1
0
1
X+Y
X.(X+Y)
0
1
1
1
0
0
1
1
From the above table it is obvious that X.(X+Y) = X because both the columns are identical.
Q7.
Ans.
LHS = X.(X+Y)
= X.X+X.Y
=X+X.Y
=X.(1+Y)
=X.1 = X = RHS
Q8.
State the distributive laws of Boolean algebra. How are they different from
distributive laws of ordinary algebra.
Ans.
Q9.
Ans.
0
0
1
1
0
1
0
1
0
1
1
1
1
0
0
0
1
1
0
0
XY
1
0
1
0
1
0
0
0
State Demorgans laws. Verify one of the Demorgans laws using truth tables.
De Morgans first theorem. It states that X + Y = X . Y
De Morgans second theorem. It states that X . Y = X + Y
Truth table for second theorem
X
Y
X.Y
X.Y
X
Y
Ans.
0
0
1
1
0
0
1
1
0
1
0
0
1
1
1
0
X.Y and X+Y are identical.
1
1
0
0
1
0
1
0
X+Y
1
1
1
0
Q10. Why are AND and NOR gates called Universal gates?
Ans.
NAND and NOR gates are less expensive and easier to design. Also, other switching
functions (AND, OR) can easily be implemented using NAND/NOR gates. Thus, these
(NAND, NOR) gates are also reffered to as Universal Gates.
Q11. By means of truth table, demonstrate the validity of the following Postulates /
Laws of Boolean algebra:
(a)
(b)
(c)
Ans
Commulative law
Absorption law
Idempotent law
Y
0
1
0
1
X+Y
0
1
1
1
Output
Y+X
0
1
1
1
Comparing the columns X+Y and Y+X, we see both of these are identical. Hence proved.
74
Output
Y.X
0
0
0
1
Comparing the columns X.Y and Y.X, we see both of these are identical. Hence proved.
The absorption law states that
(i) X+XY = X
(ii) X(X+Y) =X
(i) Truth table for
X+XY = X is given below :
Input
X
Y
XY
0
0
1
1
0
1
0
1
Output
X+XY
0
0
0
1
0
0
1
1
X+Y
X(X+Y)
0
0
1
1
0
1
0
1
0
1
1
1
0
0
1
1
X+X
0
1
0
1
0
1
75
X.X
0
1
0
1
0
1
Q12. Obtain the simplified form of a boolean expression using Karnaugh map.
F(u,v,w,x) = (0, 3, 4, 5, 7, 11, 13, 15)
[00]WZ
[01] WZ
[11]WZ
1
1
1
[10]WZ
1
2 quads, 1 pair.
Quad 1(m3+m7+m11+m15) reduces to WZ
Quad 2(m5+m7+m13+m15) reduces to VZ
Pair 1(m0,m4) reduces to UWZ
Therefore F=WZ + VZ + UWZ
Q13 . Draw the logic circuit diagram for the following expression :
Y=ab+bc+ca
76
XYZ
XY
XYZ + XY
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
1
1
1
0
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
1
1
0
0
0
0
1
0
1
1
0
0
Q15. Write the equivalent expression for the following logic circuit :
Q16. Draw the circuit diagram for F = ABC + CB using NAND to NAND logic only.
Ans.
F=ABC + CB =((A)NAND(B)NAND(C))NAND((C)NAND B)
Q17. Write the Sum of Products form of the function G(U,V,W). Truth table representation
of G is as follows :
U
V
W
G
0
0
0
0
0
0
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
1
0
1
0
1
1
Ans.
To get the product of sums form, we need to add maxterms for all those input combinations
that produce output as 0. Thus ,
G(U,V,W) = (U + V + W) (U + V + W) (U + V + W) (U + V + W)
Ans.
(X + Y)(X + Y)(X + Y)
77
Unsolved Questions:
1. Define Binary logic.
2. What is a Boolean Operation ?
3. Define a boolean function.
4. Define a Boolean Expression.
5. Name the three primary and secondary operators of Boolean Algebra.
6. State any four postulates of boolean algebra.
7. Define Idempotent Law & Absorptive Law.
8. Define Involution Law.
9. What is De Morgans Theorem ?
10. State the principle of duality.
11. Define the Sum Of Products format of a boolean expression.
12. Define the Product of Sums format of a boolean expression.
13. What is a Full Adder ?
14. Differentiate between an Encoder and a Decoder ?
15. Define the working of a XOR gate ?
16. What is a Canonical Sum of Products ?
17. What is a Canonical Product of Sums ?
18. State and verify duality principle.
19. What do you understand by a minterm and a maxterm?
20. F(x,y,z,w)=(1,3,4,5,7,9,11,12,13,15) using k-map.
State the principle of duality in Boolean Algebra and give the dual of the Boolean expression (X + Y) . (Xf + Zf) . (Y + Z)
Principle of Duality states that from every Boolean relation, another boolean relation can be
derived by Changing each OR sign to AND and vice versa Replacing each 1 by 0 and vice
versa. The new derived relation is known as the dual of the original relation.
Dual of (X + Y) . (Xf + Zf) . (Y + Z) is X.Y + Xf.Zf + Y.Z
Q2.
Ans:
Seven inverters are cascaded one after another. What is the output if the input is 1?
0.
Q3.
Ans:
Q4.
Obtain a simplified form for the following Boolean ex-pression using Karnaughfs
Map:
F(a, b, c, d) = (0, 1, 2, 4, 5, 7, 8, 9, 10, 11, 14).
Ans:
78
Quad 1 = afcf , Quad 2 = abf , Pair 1 is afbd, Pair 2 is bfcdf , Pair 3 is acdf
The simplified form is: afcf + abf + afbd + bfcdf + acdf
Q5. Prove XY+YZ+YZf=Y algebraically.
Ans:- XY+YZ+YZf
=XY+Y(Z+Zf)
=XY+Y=Y(1+X)=Y hence proved
Q6. Simplified ABfCDf+ABfCD+ABCDf+ABCD.
Ans. ABfCDf+ABfCD+ABCDf+ABCD
=
ABfC(Df+D)+ABC(Df+D)
=
ABfC.1+ABC.1
=
AC(Bf+B)
=
AC.1=AC.
Q7.
Draw the diagram of digital circuit for
F(a,b,c)= AB+BC+CD using NAND-to- NAND logic.
Ans.
F(a,b,c)= AB+BC+CD
=(A NAND B) NAND (B NAND C) NAND (C NAND D)
Thus the logic circuit is
Q8. Prepare a truth table for XfYf+XfY
Ans XfYf+XfY is a 2- Variable ex-pression ,its truth table is as follows
X Y Xf Yf XfYf XfY XfYf+XfY
0 0 1 1
1
0
1
0 1 1 0
0
1
1
1 0 0 1
0
0
0
1 1 0 0
0
0
0
Q9.
Ans
Q10. Convert the following function into canonical product of sums form
F(X,Y,Z)=(0,2,4,5).
Ans F(X,Y,Z)=(0,2,4,5)= MO.M2.M4.M5
M0=000=X+Y+Z
M2=010=X+Yf+Z
M4=100=Xf+Y+Z
M5=101=Xf+Y+Zf
F= (X+Y+Z )(X+Yf+Z )(Xf+Y+Z )(Xf+Y+Zf)
79
Unit V
CHAPTER-14
Communication and Network Concpets
Key Points
Solved Questions
Q1. What factors affect data transmission?
Ans Several factors affect how data is transmitted. They include the following
(i)
Transmission rate-Frequency and bandwidth
(ii)
Line Configurations-Point to point versus multipoint.
(iii)
Serial and Parallel transmission
(iv)
Direction of transmission-Simplex, Half Duplex, and Full Duplex
(v)
Transmission Mode-Asynchronous and synchronous.
(vi)
Circuit switching and Packet switching
(vii) Multiplexing
(viii)Protocols
80
Q2.
Ans
Ans
(v) Bridge
(vi) Gateway
(i) Node:- A node is a piece of hardware on the system that can be addressed by a message
from another node, that is , a computer, printer , fax, modem or CD-ROM drive.
(ii) Hub:- Node are connected to a hub, also called a concentrator, whose purpose is to
simplify wiring of nodes to each other and to route signals between the nodes.
(iii) Backbone:-A backbone is a high capacity link to which many nodes or hub can be
connected ,it is design to carry lots of traffic.
(iv) Router:-A router is a special computer that direct communicating messages when
several networks are connected together.
(v) Bridge:-A bridge is an interface used to connect the same type of networks.
(vi)Gateway:- A gateway is an interface permitting communication between dissimilar
networks-for instance ,between a LAN and a WAN or between two LANs based on different
network operating system or different layouts.
Q4.
Ans
Ans
Q7.
Ans
Q8.
Ans
Q9.
(i)
Ans
Q10.
Ans
Q11.
Ans
Q12.
Ans
Q13.
Ans
The Web Browser fetches the page requested, interprets the text and formatting commands
that it contains and display the page property formatted on the screen.
Write two advantages and disadvantages for STAR topology.
Advantages of STAR topology:
(i)
One device per connection.
(ii)
Easy to access
Disadvantages of STAR topology:
(i)
Central node dependency
(ii)
Long cable length.
Write one difference between Telnet and FTP.
Telnet-to connect to remote computers. Telnet is a program or command that allows the user
to connect to remote computers on the Internet using a user name and password.
FTP(File transfer protocol) is a method whereby the user can connect to a remote computer
known as FTP site and transfer files to his/her own microcomputers hard disk. Some FTP
files are open to the public, some are not
Explain the following terms in short:
DHTML
(ii)
ISP
DHTML is the next generation of HTML.It describes how text and images are displayed on
a web page. Dynamic HTML, developed by Netscape and the World Wide Web Consortium
(W3C) is based entirely on industry standard HTML and Java. New features in Dynamic
HTML, such as absolute positioning and layers , give designers and developers much greater
control over the look and feel of web pages.
ISP(Internet Service Provider) is a company that connects your communication line to is
servers, or central (host)computer, which connects you to the internet via another companys
network access points. ISPs have a wide range of prices and packages for users to choose
from
What are firewalls?
Firewalls are defensive barriers that fence off a private network from the internet.
What is the difference between Message Switching technique and Packet Switching
technique?
Message Switching:-It is better known as store and forward. In this mechanism a node on
receiving a message, stores it till the appropriate route is not free, then forwards it on the
route when the route is free.
Packet Switching:-It is best for data. In a packet switched network, data are transmitted in
discrete units called packets. A packet is a fixed length block of data for transmission. The
maximum length of the packet is established by the network. Longer transmissions are
broken up into multiple packets. The packets have headers with priority codes and source and
destination addresses along with data to be sent. The packets are sent over the network node
to node, kept there for a small time and then routed according to the information in its header
Write two applications of Cyber Law
Two applications of Cyber Law are given below
(i) Restricting/Penalising unathorised user
(ii) Promoting , coordinating and controlling e-Business.
Write a not on Fast Ethernet Technology.
The growing importance of LANs and the increasing complexity of desktop computing
applications are fueling the need for high performance networks. 100BASE-T(Fast Ethernet)
provides a cost effective and high-performance for small workgroups. SMBs(Small to
Medium Business), and any network supporting bandwidth-intensive applications. Fast
Ethernet technology operates at 10 times the speed of traditional Ethernet, offering maximum
performance and enhanced capability for existing Ethernet- based networks.
82
Q14. What is the diffrence between XML and HTML? Write two differences.
Ans The major differences between XML and HTML
XML
HTML
Doesnt specify either semantics or tag set.
The semantics and tag set are fixed.
It is a language for documents containing It is a language used to design the layout of a
structured information and all semantics are document and to specify the hyperlinks.
defined by the applications that process them.
Q15. Expand the following terminologies:
(i) TCP/IP
(ii) XML
(iii) CDMA
(iv) WLL
Ans
Unsolved Questions
Q1) What do you mean by network topology ? What are the most popular topologies.
Q2) What are repeaters and routers?
83
Maximum Marks : 70
(a) Differentiate between a Call by Value and Call by Reference, giving suitable examples
of each.
2
(b) Name the header files to which the following belong:
1
(i) abs( )
(ii) strcmp( )
(c) Rewrite the following program after removing the syntactical error(s), if any.
Underline each correction.
2
#include <iostream.h>
const int Multiple 3;
void main ()
{
Value=15;
for (int Counter = 1;Counter=<5;Counter++,Value-=2)
if (Value%Multiple==0)
cout<<Value * Multiple;
cout<<endl;
else
cout<<Value+Multiple<<endl;
}
(d) Find the output of the following program:
#include<iostream.h>
struct MyBox
{
int Length, Breadth, Height;
};
void Dimension (MyBox M)
{
cout<<M.Length<<"x"<<M.Breadth<<"x";
cout<<M.Height<<endl;
}
void main ()
{
MyBox B1={10,15,5}, B2, B3;
++B1.Height;
Dimension(B1);
B3 = B1;
++B3.Length;
B3.Breadth++;
Dimension(B3);
B2 = B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}
86
(iv) 1 2 3
2.
(a) Define the term Data Hiding in the context of Object Oriented Programming. Give a
suitable example using a C++ code to illustrate the same.
2
(b) Answer the questions (i) and (ii) after going through the following class:
2
class Test
{
char Paper[20];
int Marks;
public:
Test () // Function 1
{
strcpy (Paper, Computer)
Marks = 0;
}
Test (char P [] ) // Function 2
{
strcpy(Paper,P);
Marks = 0;
}
Test (int M) // Function 3
{
strcpy(Paper,Computer);
Marks = M;
}
Test (char P[], int M) // Function 4
{
strcpy (Paper, P);
Marks = M;
}
};
(i) Which feature of Object Oriented Programming is demonstrated using Function 1,
Function 2, Function 3 and Function 4 in the above class Test?
(ii) Write statements in C++ that would execute Function 2 and Function 4 of class Test.
(c) Define a class TravelPlan in C++ with the following descriptions :
4
Private Members:
PlanCode of type long
Place of type character array (string)
Number_of_travellers of type integer
Number_of_buses of type integer
Public Members:
A constructor to assign initial values of Plan Code as 1001, Place as Agra,
Number_of_travellers as 5, Number_of_buses as 1
A function NewPlan( ) which allows user to enter PlanCode, Place and
Number_of_travellers. Also, assign the value of Number_of_buses as per the
following conditions :
Number_of_travellers
Number_of_buses
Less than 20
1
Equal to or more than 20 and less than 40
2
Equal to 40 or more than 40
3
A function ShowPlan( ) to display the content of all the data members on screen.
88
(d) Answer the questions (i) to (iv) based on the following code:
4
class Medicines
{
char Category[lO];
char Date_of_manufacture[lO];
char Company[20];
public:
Medicines();
void entermedicinedetails();
void showmedicinedetails();
};
class Capsules: public Medicines
{
protected:
char capsule_name[30];
char Volume_label[20];
public:
float Price;
Capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics: public Capsule
{
int Dosage_units;
char Side_effects[20];
int Use_within_days;
public:
Antibiotics() ;
void enterdetails();
void showdetails();
};
(i) How many bytes will be required by an object of class Medicines and an object
of class Antibiotics respectively?
(ii) Write names of all the member functions accessible from the object of class
Antibiotics.
(iii) Write names of all the members accessible from member functions of class Capsules.
(iv) Write names of all the data members, which are accessible from objects of class
Antibiotics.
3.
(a) Write a function in C++ which accepts an integer array and its size as
arguments/parameters and exchanges the values of first half side elements with the
second half side elements of the array.
3
Example:
If an array of eight elements has initial content as
2,4,1,6,7,9,23,10
The function should rearrange the array as
7,9,23,10,2,4,1,6
(b) An array Arr[15][35] is stored in the memory along the column with each of its
elements occupying 8 bytes. Find out the base address and the address of an element
Arr[2][5], if the location Arr[5][10] is stored at the address 4000.
4
89
(a) Observe the program segment given below carefully, and answer the question that
follows:
1
class Book
{
int Book no;
char Book_name[20];
public:
//function to enter Book details
void enterdetails();
// function to display Book details
void showdetails();
//function to return Book_no
int Rbook_no (){return Book_no;}
};
void Modify(Book NEW)
{
fstream File;
File.open(BOOK.DAT,ios::binary|ios::in|ios::out);
Book OB;
int Recordsread = 0, Found = 0;
while (!Found && File.read((char*)&OB, sizeof (OB)))
{
Recordsread ++ ;
if (NEW.RBook_no() = = OB.RBook_no))
{
______________ //Missing Statement
File.write((char*)&NEW, sizeof (NEW));
Found = 1;
}
90
else
File.write((char*)&OB, sizeof(OB));
}
if (! Found)
cout<<" Record for modification does not exist;
File.close();
}
If the function Modify( ) is supposed to modify a record in file BOOK.DAT with the
values of Book NEW passed to its argument, write the appropriate statement for
Missing Statement using seekp( ) or seekg( ), whichever needed, in the above code
that would write the modified record at its proper place.
(b) Write a function in C++ to count and display the number of lines starting with
alphabet A present in a text file LINES.TXT.
2
Example:
If the file LINES.TXT contains the following lines,
A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets and numbers are allowed in the password.
The function should display the output as 3
(c) Given a binary file STUDENT.DAT, containing records of the following class
Student type
3
class Student
{
char S_Admno[lO]; //Admission number of student
char S_Name[30]; //Name of student
int Percentage; //Marks Percentage of student
public:
void EnterData()
{
gets(S_Admno);gets(S_Name);cin>>Percentage;
}
void DisplayData()
{
cout<<setw(12)<<S_Admno;
cout<<setw(32)<<S_Name;
cout<<setw(3)<<Percentage<<endl;
}
int ReturnPercentage(){return Percentage;}
};
Write a function in C++, that would read contents of file STUDENT.DAT and display the
details of those Students whose Percentage is above 75.
5.
(a) What do you understand by the terms Primary Key and Degree of a relation in
relational database?
2
(b) Consider the following tables EMPLOYEES and EMPSALARY. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
91
6
EMPLOYEES
EMPID FIRSTNAMELASTNAME
ADDRESS
CITY
010
105
152
215
244
George
Mary
Sam
Sarah
Manila
Smith
Jones
Tones
Ackerman
Sengupta
Howard
Losantiville
Paris
Upton
New Delhi
300
Robert
Samuel
83 First Street
842 Vine Ave.
33 Elm St.
440 U.S. 110
24 Friends
Street
9 Fifth Cross
335
400
441
Henry
Rachel
Peter
Williams
Lee
Thompson
12 Moore Street
121 Harrison St.
11 Red Road
Boston
New York
Paris
SALARY
BENEFITS
DESIGNATION
75000
65000
80000
75000
50000
45000
40000
32000
28000
15000
15000
25000
12500
12000
10000
10000
7500
7500
Manager
Manager
Director
Manager
Clerk
Clerk
Clerk
Salesman
Salesman
Washington
EMPSALARY
EMPID
010
105
152
215
244
300
335
400
441
(i) To display Firstname, Lastname, Address and City of all employees living in
Paris from the table EMPLOYEES.
(ii) To display the content of EMPLOYEES table in descending order of
FIRSTNAME.
(iii) To display the Firstname, Lastname, and Total Salary of all Managers from
the tables EMPLOYEES and EMPSALARY, where Total Salary is calculated as
Salary + Benefits.
(iv) To display the Maximum salary among Managers and Clerks from the table
EMPSALARY.
(v)
SELECT FIRSTNAME, SALARY
FROM EMPLOYEES, EMPSALARY
WHERE DESIGNATION = Salesman AND
EMPLOYEES.EMPID=EMPSALARY.EMPID;
(vi)
SELECT COUNT (DISTINCT DESIGNATION)FROM EMPSALARY;
(vii) SELECT DESIGNATION, SUM(SALARY)
FROM EMPSALARY
GROUP BY DESIGNATION HAVING COUNT (*)>2;
(viii) SELECT SUM (BENEFITS)
FROM EMPLOYEES
92
6.
2
2
(c) Write the SOP form of a Boolean Function F, which is represented by the following truth
table:
1
A
0
0
0
0
1
1
1
1
7.
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
0
1
0
0
1
1
93
50m
70m
125m
80m
175m
90m
50
30
150
15
(i) Suggest a most suitable cable layout of connections between the Wings, and
topology.
1
(ii) Suggest the most suitable place (i.e. Wing) to house the server of this organisation with a
suitable reason, with justification.
1
(iii) Suggest the placement of the following devices with justification:
1
(1) Repeater
(2) Hub/Switch
(iv) The organization is planning to link its head office situated in Delhi with the
offices at Srinagar. Suggest an economic way to connect it; the company is ready to
compromise on the speed of connectivity. Justify your answer.
1
Maximum Marks : 70
(a) Differentiate between a default constructor and copy constructor, giving suitable
examples of each.
2
(b) Name the header files to which the following belong :
1
(i) puts ( )
(ii) isalnum ( )
(c) Rewrite the following program after removing the syntactical error(s), if any. Underline
each correction.
2
#include <iostream.h>
const int Dividor 5;
void main()
94
{
Number=15;
for (int Count = l;Count=<5;Count++,Number-=3)
if (Number%Dividor==0)
cout<<Number / Dividor;
cout<<endl;
else
cout<<Number + Dividor<<endl;
}
#include<iostream.h>
struct Package
{
int Length, Breadth, Height;
};
void Occupies(Package M)
{
cout<<M.Length<<x<<M.Breadth<<x;
cout<<M.Height<<endl;
}
void main()
{
Package Pl={100,150,50}, P2, .P3;
++P1.Length;
Occupies(P1);
P3 = P1;
++P3.Breadth;
P3.Breadth++;
Occupies (P3);
P2 = P3;
P2.Breadth+=50;
P2. Height--;
Occupies(P2);
}
#include<iostream.h>
#include<string.h>
#include<ctype.h>
void Change(char Msg[],int Len)
{
for (int Count =0; Count<Len; Count++ )
{
if (islower(Msg[Count]))
Msg[Count]= toupper{Msg[Count]);
else if (isupper(Msg[Count]))
Msg[Count]= tolower(Msg[Count]);
else if (isdigit(Msg[Count]))
Msg[Count]= Msg[Count] + 1;
else Msg[Count] = * ;
}
}
void main()
{
char Message [] = "2005 Tests ahead";
95
(f) Observe the following program GAME.CPP carefully, if the value of Num entered by the
user is 14, choose the correct possible output(s) from the options from (i) to (iv), and justify
your option.
2
//Program : GAME.CPP
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
int Num, Rndnum;
cin>>Num;
Rndnum = random (Num) + 7;
for (int N = 1; N<=Rndnum ; N++)
cout<<N<<" ";
}
Output Options :
(i) 1 2 3
(ii) 1 2 3 4 5 6 7 8 9 10 11
(iii) 1 2 3 4 5
(iv) 1 2 3 4
2.
(a) Define the term Data Encapsulation in the context of Object Oriented Programming.
Give a suitable example using a C++ code to illustrate the same.
2
(b) Answer the questions (i) and (ii) after going through the following class :
2
class Exam
{
int Marks;
char Subject[20];
public:
Exam () //Function 1
{
Marks = 0;
strcpy (Subject,Computer);
}
Exam(char S[]) //Function 2
{
Marks = 0;
strcpy(Subject,S);
}
Exam(int M) //Function 3
{
Marks = M;
strcpy(Subject,Computer);
96
}
Exam(char S[], int M) //Function 4
{
Marks = M;
strcpy (Subject,S);
}
};
(i) Write statements in C++ that would execute Function 3 and Function 4 of class Exam.
(ii) Which feature of Object Oriented Programming is demonstrated using Function 1,
Function 2, Function 3 and Function 4 in the above class Exam ?
(c) Define a class Travel in C++ with the following descriptions :
4
Private Members :
TravelCode of type long
Place of type character array (string)
No_of_travellers of type integer
No_of_buses of type integer
Public Members :
A constructor to assign initial values of TravelCode as 201, Place as Nainital,
No_of_travellers as 10, No_of_buses as 1
A function NewTravel() which allows user to enter TravelCode, Place and
No_of_travellers. Also, assign the value of No_of_buses as per the following
conditions :
No_of_travellers
No_of_buses
Less than 20
1
Equal to or more than 20 and less than 40
2
Equal to 40 or more than 40
3
A function ShowTravel( ) to display the content from all the data members on screen.
(d) Answer the questions (i) to (iv) based on the following code :
4
class Drug
{
char Category[10];
char Date_of_manufacture[10];
char Company[20];
public:
Drug();
void enterdrugdetails();
void showdrugdetails{);
};
class Tablet : public Drug
{
protected:
char tablet_name[30];
char Volume_label[20];
public:
float Price;
Tablet();
void entertabletdetails();
void showtabletdetails ();
};
class PainReliever : public Tablet
{
97
int Dosage_units;
char Side_effects[20];
int Use_within_days;
public:
PainReliever();
void enterdetails();
void showdetails();
3.
};
(i) How many bytes will be required by an object of class Drug and an object of class
PainReliever respectively ?
(ii) Write names of all the data members which are accessible from the object of class
PainReliever.
(iii) Write names of all the members accessible from member functions of class Tablet.
(iv) Write names of all the member functions which are accessible from objects of class
PainReliever.
(a) Write a function in C++ which accepts an integer array and its size as
arguments/parameters and exchanges the values of first half side elements with the second
half side elements of the array.
3
Example :
If an array of eight elements has initial content as
8, 10, 1, 3, 17, 90, 13, 60
The function should rearrange the array as
17, 90, 13, 60, 8, 10, 1, 3
(b) An array Arr[35][15] is stored in the memory along the row with each of its element
occupying 4 bytes. Find out the base address and the address of an element Arr[20][5], if the
location Arr[2][2] is stored at the address 3000.
4
(c) Write a function in C++ to perform a DELETE operation in a dynamically allocated
queue considering the following description :
4
struct Node
{
float U,V;
Node *Link;
};
class QUEUE
{
Node *Rear,*Front;
public:
QUEUE(){Rear=NULL;Front=NULL;}
void INSERT();
void DELETE();
~QUEUE();
};
(d) Write a function in C++ to print the sum of all the values which are either divisible by 3
or are divisible by 5 present in a two dimensional array passed as the argument to the
function. 3
(e) Evaluate the following postfix notation of expression :
20 10 + 5 2 * 10 / 2
98
4.
(a) Observe the program segment given below carefully, and answer the question that
follows:
class Member
{
int Member_no;
char Member_name[20];
public :
//function to enter Member details
void enterdetails{) ;
// function to display Member details
void showdetails();
//function to return Member_no
int RMember_no() {return Member_no; }
};
void Update(Member NEW)
{
fstream File;
File.open(MEMBER.DAT,ios::binary|ios::in|ios::out);
Member OM;
int Recordsread = 0, Found = 0;
while (!Found && File.read((char*)&OM, sizeof(OM)))
{
Recordsread ++;
if (NEW.RMember_no() == OM.RMember_no())
{
___________________//Missing Statement
File.write((char*)&NEW, sizeof(NEW));
Found = 1;
}
else
File.write((char*)&OM, sizeof(OM));
}
if (!Found)
cout<<Record for modification does not exist;
File.close();
}
If the function Update ( ) is supposed to modify a record in file MEMBER.DAT with the
values of Member NEW passed to its argument, write the appropriate statement for Missing
Statement using seekp( ) or seekg( ), whichever needed, in the above code that would write
the modified record at its proper place.
(b) Write a function in C++ to count and display the number of lines not starting with
alphabet A present in a text file STORY.TXT.
2
Example :
If the file STORY.TXT contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
The function should display the output as 3
99
(c) Given a binary file APPLY.DAT, containing records of the following class Applicant
type 3
5.
class Applicant
{
char A_Rno[10]; //Roll number of applicant
char A_Name[30]; //Name of applicant
int A_Score; //Score of applicant
public:
void Enrol()
{
gets (A_Rno); gets (A_Name) ; cin>>A_Score;
}
void Status()
{
cout<<setw(12)<<A_Admno;
cout<<setw(32)<<A_Name;
cout<<setw(3)<<A_Score<<endl;
}
int ReturnScore(){return A_Score;}
};
Write a function in C++, that would read contents of file APPLY.DAT and display the details
of those Students whose A_ Score is below 70.
(a) What do you understand by the terms Candidate Key and Cardinality of a relation in
relational database ?
2
(b) Consider the following tables WORKERS and DESIG. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii) :
6
WORKERS
W_ID
FIRSTNAME
LASTNAME
102
105
144
210
255
300
335
403
451
Sam
Sarah
Manila
George
Mary
Robert
Henry
Ronny
Pat
Tones
Ackerman
Sengupta
Smith
Jones
Samuel
Williams
Lee
Thompson
DESIG
W_ID
102
105
144
210
255
300
335
400
451
SALARY
75000
85000
70000
75000
50000
45000
40000
32000
28000
ADDRESS
33 Elm St.
440 U.S. 110
24 Friends Street
83 First Street
842 Vine Ave.
9 Fifth Cross
12 Moore Street
121 Harrison St.
11 Red Road
BENEFITS
15000
25000
15000
12500
12000
10000
10000
7500
7500
CITY
Paris
New York
New Delhi
Howard
Losantiville
Washington
Boston
New York
Paris
DESIGNATION
Manager
Director
Manager
Manager
Clerk
Clerk
Clerk
Salesman
Salesman
100
6.
(i) To display W_ID, Firstname, Address and City of all employees living in New York from
the table WORKERS.
(ii) To display the content of WORKERS table in ascending order of LASTNAME.
(iii) To display the Firstname, Lastname, and Total Salary of all Clerks from the tables
WORKERS and DESIG, where Total Salary is calculated as Salary + Benefits.
(iv) To display the Minimum salary among Managers and Clerks from the table DESIG.
(v)
SELECT FIRSTNAME, SALARY
FROM WORKERS, DESIG
WHERE DESIGNATION = Manager AND
WORKERS.W_ID=DESIG.W_ID;
(vi) SELECT COUNT(DISTINCT DESIGNATION) FROM DESIG;
(vii) SELECT DESIGNATION, SUM(SALARY)
FROM DESIG
GROUP BY DESIGNATION HAVING COUNT(*)<3;
(viii) SELECT SUM(BENEFITS)
FROM WORKERS
WHERE DESIGNATION = Salesman;
(a) State and verify Absorption law in Boolean Algebra.
2
(b) Write the equivalent Boolean expression for the following Logic Circuit :
2
(c) Write the POS form of a Boolean Function F, which is represented by the following
truth table :
7.
X
Y
Z
F
0
0
0
1
0
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
1
1
1
0
00
1
1
1
(d) Reduce the following Boolean expression using K - Map :
F (A, B, C, D) =
(0, 1, 2, 3, 4, 5, 10, 11, 15)
(a) Compare Optical Fiber and Coaxial transmission media.
(b) Expand the following terminologies :
(i) HTML
(ii) GSM
(c) What is the difference between XML and HTML ? Write two differences.
(d) What do you understand by the terms Cookies and Firewall ?
(e) The Cyber Mind Organisation has set up its new Branch at Mizoram for its office and
web based activities. It has 4 Wings of buildings as shown in the diagram :
3
1
1
1
1
101
40m
60m
135m
70m
165m
Wing Z to Wing U
80m
Number of Computers
Wing X
Wing Z
Wing Y
Wing U
50
130
140
15
(el) Suggest a most suitable cable layout of connections between the Wings and topology. 1
(e2) Suggest the most suitable place (i.e. Wing) to house the server of this organization with
a suitable reason with justification.
1
(e3) Suggest the placement of the following devices with justification :
1
(i) Repeater
(ii) Hub/Switch
(e4) The organization is planning to link its head office situated in Delhi with the offices as
Mizoram. Suggest an economic way to connect it; the company is ready to compromise on
the speed of connectivity. Justify your answer.
1
102
Maximum Marks : 70
(a) Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of
each in C++.
2
(b) Name the header file(s) that shall be needed for successful compilation of the following
C++ code.
1
void main ( )
{
char String [20];
gets (String);
strcat (String, CBSE);
puts (String);
}
(c) Rewrite the following program after removing the syntactical error(s) if any.
Underline each correction.
2
# include <iostream.h>
const int Max 10;
void main ( )
{
int Numbers [Max];
Numbers = { 20, 50,10, 30,40 } ;
for (Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout>>Numbers [Loc];
}
(d) Find the output of the following program :
2
# include < iostream.h>
void main ()
{
intArray[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<#;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=l; I<5; I + + )
cout << Array [I-1] << @;
cout << endl;
}
(e) Find the output of the following program :
3
103
(a) Differentiate between Constructor and Destructor function in context of Classes and
Objects using C++
2
(b) Answer the questions (i) and (ii) after going through the following class
class Maths
{
char Chapter [20];
int Marks;
public:
Maths ( ) //Member Function 1
{
strcpy (Chapter, Geometry);
Marks = 10;
cout<<Chapter Initialised;
}
~Math () //Member Function 2
{
104
cout<<Chapter Over;
}
};
(i) Name the specific features of class shown by Member Function 1 and Member Function 2
in the above example.
(ii) How would Member Function 1 and Member Function 2 get executed?
(c) Define a class Tour in C++ with the description given below :
3
Private Members :
TCode
of type string
NoofAdults
of type integer
NoofKids
of type integer
Kilometres
of type integer
TotalFare
of type float
Public Members :
A constructor to assign initial values as follows :
TCode with the word NULL
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
A function AssignFare ( ) which calculates and assigns the value of the data member
TotalFare as follows
For each Adult
Fare(Rs)
For Kilometres
500
>=1000
300
<1000&>=500
200
<500
For each Kid the above Fare will be 50% of the Fare mentioned in the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
A function EnterTour( ) to input the values of the data members TCode, NoofAdults,
NoofKids and Kilometres; and invoke the Assign Fare( ) function.
A function ShowTour( ) which displays the content of all the data members for a Tour.
(d) Answer the questions (i) to (iv) based on the following code :
4
class Trainer
{
char TNo [5], TName [20], Specialisation [10];
int Days;
protected :
float Remuneration;
void AssignRem (float);
public :
Trainer ( ) ;
void TEntry ( );
void TDisplay ( );
};
105
class Learner
{
char Regno [10], LName [20], Program [10];
Protected :
int Attendance, Grade;
public:
Learner ( );
void LEntry ( );
void LDisplay ( );
};
class Institute : public Learner, public Trainer
{
char ICode[10], IName [20];
public:
Institute ( );
void IEntry ( );
void IDisplay ( );
};
(i) Which type of Inheritance is depicted by the above example?
(ii) Identify the member function(s) that cannot be called directly from the objects of class
Institute from the following
TEntry( )
LDisplay()
IEntry()
(iii) Write name of all the member(s) accessible from member functions of class Institute.
(iv) If class Institute was derived privately from class Learner and privately from class
Trainer, then, name the member function(s) that could be accessed through Objects of class
Institute.
3.
(a) Write a function in C++ which accepts an integer array and its size as arguments and
replaces elements having odd values with thrice its value and elements having even values
with twice its value.
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as
9, 8, 15, 32, 27 4
(b) An array Array[20][15] is stored in the memory along the column with each element
occupying 8 bytes. Find out the Base Address and address of the element Array[2][3] if the
element Array [4] [5] is stored at the address 1000.
4
(c) Write a function in C++ to delete a node containing Books information, from a
dynamically allocated Stack of Books implemented with the help of the following structure.
4
struct Book
{
int BNo;
char BName[20];
Book *Next;
};
(d) Write a function in C++ which accepts a 2D array of integers and its size as arguments
and displays the elements which lie on diagonals.
2
106
4.
If the function AllocateMarks () is supposed to Allocate Marks for the records in the file
MARKS.DAT based on their value of the member TimeTaken. Write C++ statements for the
107
5.
statement 1 and statement 2, where, statement 1 is required to position the file write
pointer to an appropriate place in the file and statement 2 is to perform the write operation
with the modified record.
(b) Write afunction in C++ to print the count of the word is as an independent word in at text
file DIALOGUE.TXT.
2
For example, if the content of the file DIALOGUE. TXT is
This is his book. Is this book good?
Then the output of the program should be 2.
(c) Given a binary file GAME.DAT, containing records of the following structure type 3
struct Game
{
char GameName [20];
char Participant [10] [30];
};
Write a function in C++ that would read contents from the file GAME.DAT and creates a file
named BASKET.DAT copying only those records from GAME.DAT where the game name
is Basket Ball.
(a) Differentiate between primary key and alternate key.
2
(b) Consider the following tables. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii) 6
TABLE:SENDER
SenderlD
SenderName
SenderAddress
ND01
R Jain
MU02
H Sinha
MU15
S Jha
ND50
T Prasad
TABLE : RECIPIENT
RecID
KO05
ND08
MU19
MU32
ND48
SenderlD
ND01
MU02
ND01
MU15
ND50
RecName
R Bajpayee
S Mahajan
H Singh
P K Swamy
S Tripathi
2, ABC Appts
12, Newtown
27/A, Park Street
122-K, SDA
RecAddress
5, Central Avenue
116, A Vihar
2A, Andheri East
B5, C S Terminus
13, B1 D, Mayur Vihar
SenderCiry
New Delhi
Mumbai
Mumbai
New Delhi
RecCity
Kolkata
New Delhi
Mumbai
Mumbai
New Delhi
(viii)
6.
7.
(a) State Distributive law and verify the same using truth table.
2
(b) Write the equivalent Canonical Sum of Product expression for the following Product of
Sum Expression
2
(c) Write the equivalent Boolean Expression for the following Logic Circuit.
2
1
2
(c) Which of the following unit measures the speed with which data can be transmitted from
one node to another node of a network? Also, give the expansion of the suggested unit. 1
(i) Mbps
(ii) KMph
(iii) MGps
(d) Bhartiya Connectivity Association is planning to spread their offices in four major
cities in India to provide regional IT infrastructure support in the field of Education &
Culture. The company has planned to setup their head office in New Delhi in three locations
and have named their New Delhi offices as Front Office, Back Office and Work
Office. The company has three more regional offices as South Office, East Office and
West Office located in other three major cities of India. A rough layout of the same is as
follows :
4
Place From
Place To
Distance
BackOffice
Front Office
10KM
Back Office
Work Office
70 Meter
Back Office
East Office
1291 KM
BackOffice
West Office
790 KM
Back Office
South Office
1952 KM
In continuation of the above, the company experts have planned to install the
following number of computers in each of their offices :
Back Office
100
Front Office
20
Work Office
50
East Office
50
West Office
50
South Office
50
(i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set
of their offices :
Back Office and Work Office
Back Office and South Office
(ii) Which device you will suggest to be procured by the company for connecting all the
computers with in each of their offices out of the following devices?
Switch/Hub
Modem
Telephone
(iii) Which of the following communication medium, you will suggest to be procured by the
company for connecting their local offices in New Delhi for very effective and fast
communication?
Telephone Cable
Optical Fiber
Ethernet Cable
(iv) Suggest a cable/wiring layout for connecting the companys local offices located in New
Delhi. Also, suggest an effective method/technology for connecting the companys regional
offices-East Office, West Office and South Office with offices located in New Delhi.
110
Maximum Marks : 70
(a) Define any two features of OOPs. Also give suitable example in C++.
2
(b) Name the Header file(s) that shall be needed for successful compilation of the
following C++ code
void main()
{
int a[10];
for(int i=0;i<10;i++)
{
cin>>a[i];
if(a[i]%2==0)
a[i]=pow(a[i],3);
else
a[i]=sqrt(a[i]);
if(a[i]>32767)
exit(0);
}
getch();
}
1
(c) Rewrite the following program after removing syntactical error(s) if any.
Underline each correction.
2
#include<iostream.h>
type def int integer;
struct number
{
integer a [5];
}
void main()
{
number x;
for(int i=0;i<5;i++)
cin>>x[i].a;
getch();
}
(d) Find the output of the following program :
2
#include<iostream.h>
#include<string.h>
void main()
{
char *a[2]={Amit,Sumit};
for(int i=0;i<2;i++)
{
int l=strlen(a[i]);
for(int j=0;j<l;j++,a[i]++)
cout<<*a[i]<< : ;
111
cout<<endl;
}
}
(e) Find the output of the following program
#include<iostream.h>
class student
{
public:
student()
{
cout<<\n Computer Science;
}
~student()
{
cout<< subject;
}
}st;
void main()
{
cout<< is my best
}
(f) In the following C++ program , what will the maximum and minimum value of
r generated with the help of random function.
2
#include<iostream.h>
#include<stdlib.h>
void main()
{
int r;
randomize();
r=random(20)+random(2);
cout<<r;
}
(g) Define macro with a suitable example.
2
2. (a) Differentiate between a Constructor and Destructor in context of class
and object . Give suitable example in C++.
2
(b) Answer the questions (i) and (ii) after going through the following class : 2
class Computer
{
char C_name[20];
char Config[100];
public:
Computer(Computer &obj); // function1
Computer();
//function 2
Computer(char *n,char *C); // function3
};
(i)
Complete the definition of the function 1.
(ii)
Name the specific feature of the OOPs shown in the above example.
112
(c) Define a class Student in C++ with the description given below :
4
private members
rno
integer
name
array of 40 characters
address
array of 40 characters
marks
array of 5 integers
percentage
float variable
calper()
a function which will calculate & return the percentage of a
student.
public members
init()
function to ask and store the values of rno, name, address and
marks in 5 subjects.
display()
function to which will invoke calper () and display the details
of the item in the following format :
MARK SHEET
Roll No :
<Roll no of student>
Name :
<Student Name >
Address :
<ADDRESS >
Marks :
<subject1 marks><subject 2 marks ><.subject 5 marks>
Percentage : <percentage of the student>
Also create main() function which will invoke all the public member functions.
(d)
public :
Payment();
~Payment();
void show();
(i)
(ii)
(iii)
3.
(iv)
(a)
(b)
(c)
(d)
};
Name the type of Inheritance depicted in the above example.
Name the member functions accessible through the object of class Payment.
From the following, Identify the member function(s) that can be called directly from
the object of class Daily_wager class
show()
getd()
get()
Name the base & derived class of Daily_wager class.
Write a function in C++ which accepts a integer array and its size as an
arguments and prints the output (using nested loops) in following format :
Example : if the array is having
12459
Then the output should be
1
22
4444
55555
999999
4
An array A[10][20] is stored in the memory with each element occupying 2 bytes of
storage. If the Base address of array in the memory is 800 , determine the location of
A[9][10] when the array is stored as (i) Row Major (ii) column major.
Write a function in C++ to delete a node containing names of student ,
from a dynamically allocated Queue of names implemented with the help
of following structure :
3
struct student
{
char name[20];
student *next;
}*front , *rear;
Consider the following portion of a program , which implements a linked
stack for Library . Write the definition of function PUSH(),to insert a new node in the
stack with required information
3
struct Library
{
int id;
char names[20];
};
class stack
{
Library *top;
public :
stack()
{
top=NULL;
}
114
void PUSH();
void POP();
(e)
4.
(a)
(b)
(c)
5.
(a)
(b)
};
Convert the following infix expression into postfix. show the stack status
after execution of each operation:
2
TRUE OR FALSE AND NOT FALSE OR FALSE
Differentiate between ios::app and ios::ate file opening modes.
Write a function in C++ which will print the size of a text file story.txt in the form
of bytes.
2
Write a function in C++ which will increase the qty of a particular type of item from
the file stock.dat . Assuming that the binary file is containing the records of
following structure :
3
struct Products
{
int id;
char Iname[30];
int type;
int qty;
};
Accept the item type from user whose qty has to be increased .
What do you understand by Primary Key.
2
Consider the following tables Employee and salary. Write SQL commands
for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
6
Table : Employee
Eid Name
Deptid Qualification
1
Deepali Gupta 101
MCA
2
Rajat Tyagi
101
BCA
3
Hari Mohan
102
B.A
4
Harry
102
M.A
5
Sumit Mittal
103
B.Tech
6
Jyoti
101
M.Tech
(i)
(ii)
(iii)
(iv)
(v)
Sex
F
M
M
M
M
F
Table : Salary
Eid Basic DA HRA Bonus
1
6000 2000 2300 200
2
2000 300 300
30
3
1000 300 300
40
4
1500 390 490
30
5
8000 900 900
80
6
10000 300 490
89
To display the frequency of employees department wise.
To list the names of those employees only whose name starts with H
To add a new column in salary table . the column name is total_sal.
To store the corresponding values in the total_sal column.
Select name from employee where eid=(select eid from salary where basic=
(select max(basic) from salary));
115
(vi)
(vii)
(viii)
6.
7.
7.
(a)
(b)
(c)
Draw the Logical circuit of the following expression with the help of NAND
gate only
1
x+yz
(d)
(a)
(b)
(c)
W1
W2
W3
W4
W4
25
Computers in each wing are networked but wings are not networked. The company has
now decided to connect the wings also.
i) Suggest a most suitable cable layout & topology of the connection between the wings.
[1]
ii) The company wants internet accessibility in all the wings. Suggest an economic
technology .
[1]
iii) Suggest the placement of the following devices with justification if the company
wants minimized network traffic :
[1]
1)Repeater
2) Hub
3) Switch
4) Bridge
iv) The company is planning to link its head office situated in India with the offices
at Reliance. Suggest a way to connect it; the company does not want to compromise with the
speed of connectivity. Justify your answer.
[1]
117
(b) Name the header file(s) that shall be needed for successful compilation of the
following C++ code
void main ( )
{
char string [20];
gets (string);
strcat(String, CBSE);
puts (string);
}
Ans : stdio.h
string.h
(c) Rewrite the following program after removing the syntactical error(s) if any.
Underline each correction.
# include <iostream.h>
const int max 10;
void main ( )
{
int Number [max];
Numbers = {20, 50, 10, 30, 40};
for (Loc = Max-1; Loc> =0; Loc--)
cout >> Numbers [Loc];
}
Ans :
#include<iostream.h>
const int max +10; //OR
void main ( )
{
int numbers[max]={20,50,10,30,40};
int Loc;
for (int Loc= max-1;Loc>=0; loc--)
cout<<Numbers[Loc];
}
(d)
4#6#10#
12@18@30@36@
(e)
Find the output of the following program:
#include<iostream.h>
{
void withdef(int hisnum; I+=5)
{
for (int I=20; I<=hiusnum; I+=5)
cout<<I<<``,`` ;
cout<<endl;
}
void control(int &mynum) ; }
void main( )
{
int yourNum=20;
control(yourNum) ;
withdef( ) ;
cout<<``number=``<<yourNum<<endl;
Ans :
20,25,30,
20,25,30,
Number=30
119
(f) In the following C++ program what is the expected value of MyMarks from options
(ii) 94
(iv) None of the above
(ii) 94
2. (a) Differentiate between constructor and destructor function in context of classes and
objects using C++
Ans :
Constructor :
1.
Name of the constructor functions is same as the name of the class.
2.
No return type required for constructor functions.
3.
Constructor functions are called automatically at the time of creation of the object.
4.
Constructor can be overloaded.
5.
constructor functions are defined in public.
Destructor :
1.
Name of the destructor is same as the name of the class preceded by.
2.
No return type required for destructor function.
3.
Destructor functions are called automatically when the scope of the object gets over.
4.
Destructor can not be overloaded.
5.
Destructor function is defined in public.
(b) Answer the questions (i) and (ii) after going through the following class :
Class maths
{
char chapter [20];
int Marks [20]
public:
Maths ( )
{
strcpy (chapter, ``geometery
120
Marks =10;
cout <<``chapter Intialised ;
}
~Maths ( )
//member Function 2
{
cout<<`` chapter over
}
};
(i)
Name the specific features of class shown by member function1 and member
function 2 in above example?
Ans : FUNTION 1: constructor OR default constructor
(ii)
How would Member Function 1 and Member Function 2 get get executed?
Ans.
Example :
{
Maths S1;
..
}
}
(c)
//constructor is invoked
//Destructor is invoked
TotalFare as 0
A function assign fare ( ) which calculates and assign
The value of the data member Total Fare as follows
For each adult
Fare (Rs)
For kilometers
500
>=1000
300
<1000 & >=500
200
<500
For each Kid the above Fare will be 50% of the fare mentioned in the above table
For example:
If Kilometers is 850, Noofadults= 2 and Noofkids=3
Then TotalFare shouls be calculated as
Num of adults* 300 +Noofkids*150
i.e. 2* 300+ 3* 150 = 1050
A function entered to ( ) to input the values of the data members TCode, NoofAdults,
NoofKids and Kilometers;and invoke the AssignFare( ) function.
A function ShowTour( ) which displays the content of all the data members for a
Tour.
Ans.
Class tour
{
Char TCode [10]; or char *Tcode;
int NoofAdults;
int NoofKids;
int KILometers;
float TotalFare;
public:
tour ( )
{
Strcpy (TCode,``NULL): OR TCode [0]=`\0 OR strcpy(TCode, ``\0)
Noofadults = 0;
Noof kids = 0;
Kilometers = 0;
TotalFare = 0
};
Void tour: : assignfare ( )
{
if (kilometers>=1000)
Totalfare =500* Noofadults+250* Noof kids ;
else if (kilometers>=500)
Totalfare =300* Noofadults+150*Noofkids;
else
Total fare = 200* Noofadults+100*Noofkids;
122
}
void tour : : enter ( )
{
gets ( TCode ); //or cin >> TCode;
cin>>Noofadults>>Noofkids>>kilometers;
Assignfare( );
}
void tour::show tour( )
{cout<<tcode<<Noofkids<<kilometers <<total fare<<end1;
}
(d)
Class trainer
{char TNo [20],specializations [10];
int days;
Protected:
float remuneration ;void assignrem(float);
Public:
Trainer( );
void TEntry( );
void TDisplay( );
};
class Learner
{
char Regno[10],LName[20],Program[10];
protected:
int Attendance, grade;
public:
learner( );
void TEntry( );
void TDisplay( );
};
class institute : public Learner, Public Trainer
{
char ICode[10],IName[20];
public:
Intitute ( ) ;
void Ientry ( ) ;
voidIdisplay( );
};
(i)
Ans :
(ii)
Multiple Inheritance
Identify the member function (s) that cannot be called directly from the objects of the
class institute from the following
Tentry( )
LDisplay( )
IEntry( )
Ans :
(iii)
Ans.
None
Write the names of all the member(s) accessible from member functions of class
Institute.
DATA MEMBERS : ICode, IName, Attendance, Grade, Renumeration
MEMBER FUNCTIONS : IEntry( ), IDisplay( ), LEntry( ), LDisplay( ),
AssignRem( ), TEntry( ), TDisplay( )
(iv)
If class Institute was derived privately from class Learner and privately from class Trainer,
then name the member function(s) that could be accessed through Objects of Class Institute
Ans.
IEntry( ) , IDisplay( )
3. (a)
Write a function in C++ which accepts an integer array and its size as
arguments and replaces elements having odd values with thrice its value and
elements having even values with twice its value.
Example :
Ans.
(b)
An array Array[20][15] is stored in the memory along the column with each element
occupying 8 bytes. Find out the base address and address of the element Array[2][3] if
the element Array[4][5] is stored at the address 1000.
Ans.
(c)
Ans.
(d)
Write a function in c++ which accepts a 2D array of integers and its size as
arguments and displays the elements which lie on diagonals.
125
[Assuming the 2D Array to be square matrix with odd dimension ie. 3X3, 5X5, 7X7
etc]
Example, if the array content is
5
4
3
6
7
8
1
2
9
Output through the function should be :
Diagonal One :
5
7
9
Diagonal two :
3
7
1
Ans. void Diagonals(int Arr[][100], int size)
{ int Row, Col;
cout<<Diagonal One : ;
for(Row =0;Row<Size;Row++)
for(Col=0;Col<Size;Col++)
if(Row = = Col)
cout<<Arr[Row][Col];
cout<<Diagonal Two : ;
for(Row =0;Row<Size;Row++)
for(Col=0;Col<Size;Col++)
if(Row + Col = = Size -1)
cout<<Arr[Row][Col];
}
(e)
Ans.
Operator Scanned
25
8
3
/
6
*
10
+
Stack Content
25
25, 8
25, 8, 3
25, 5
5
5, 6
30
30, 10
40
4.(a) Observe the program segment given below carefully and answer the questions that
follows :
class PracFile
{
int Pracno;
char PracName[20];
int TimeTaken;
int Marks;
126
public:
//function to enter PracFile details
void EnterPrac( );
//function to display PracFile details
void ShowPrac( );
//function to return Time taken
int RTime( ) { return TimeTaken;}
//function to assign Marks
void Assignmarks(int M)
{
Marks = M;
};
void AllocateMarks( )
{
fstream File;
File.open(Marks.Dat.,ios::binary|ios:in|ios:out);
PracFile P;
int Record = 0;
while(File.read((char *)&P, sizeof(P)))
{
if (P.RTime( ) > 50)
P.Assignment(0)
else
P.Assignment(10)
______________________//statement 1
______________________//statement 2
Record++;
}
File.Close( );
}
If the function Allocate Marks( ) is supposed to allocate Marks for the records in the file
MARKS.DAT based on their value of the member TimeTaken. Write C++ statements for the
statement1 and statement2, where statement1 is required to position the file write pointer to
an appropriate place in the file and statement2 is to perform the write operation with the
modified record.
Ans.
Statement 1 :
File.seekp(Record * sizeof(P));
Or
File.seekp(Record * sizeof(PracFile));
Or
File.seekg(Record * sizeof(P));
Statement 2 :
File.write((char *)&P, sizeof(P));
127
Or
File.write((char *)&P, sizeof(PracFile));
(b)
Write a function in C++ to print the count of the word is as an independent word in a
text file DIALOGUE.TXT.
For example, if the content of the file DIALOGUE.TXT is
This is his book. Is this book good?
Then the output of the program should be 2.
Ans.
void countis( )
{
ifstream Fil;
Fil.open(Dialogue.txt);
char Word[50];
int Count=0;
while (!Fil.eof( ))
{
Fil>>Word;
if(strcmpi(Word,is)==0)
count++;
}
cout<<count;
Fil.close( );
}
(c)
Given a binary file GAME.DAT, containing records of the following structure type
struct Game
{
char GameName[20];
char Participant[10][30];
};
Write a function in C++ that would read the contents from the file GAME.DAT and creates a
file named BASKET.DAT copying only those records from GAME.DAT where the game
name is Basket Ball
fin.close( );
fout.close( );
}
5. (a)
Ans.
All candidate keys, which are not the primary key of the table are called alternate keys.
(b)
Consider the following tables Consignor, Consignee and Consignment. Write SQL
commands for the statements (i) to (iv) and give the outputs for SQL queries (v) to
(viii).
(i)
(ii)
(iii)
(iv)
(v)
(vi)
Ans.
129
S Jha
(vii)
Ans.
P K Swamy
6.(a)
Ans.
State Distributive law and verify the same using truth table.
If X, Y, Z are Boolean Variables then
X.(Y + Z) = X.Y + X.Z
or
X+Y.Z = (X+Y).(X+Z)
X
0
0
0
0
1
1
1
1
(b)
Ans.
(c)
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
Y+Z
0
1
1
1
0
1
1
1
X.(Y+Z)
0
0
0
0
0
1
1
1
X.Y
0
0
0
0
0
0
1
1
X.Z
0
0
0
0
0
1
0
1
X.Y+X.Z
0
0
0
0
0
1
1
1
Write the equivalent Canonical Sum of Product expression for the following Product
of Sum Expression
F(X, Y, Z) = (1 , 3, 6, 7)
F(X, Y, Z) = (0, 2, 4, 5)
=X. Y. Z + X.Y.Z + X.Y.Z + X.Y.Z
Write the equivalent Boolean Expression for the following Logic circuit.
130
(d)
7.(a)
Ans.
(b)
Ans.
(c)
Ans.
Which of the following unit measures the speed with which data can be transmitted
from one node to another node of a network? Also, give the expansion of the
suggested unit.
(i) Mbps
(ii) KMph
Mbps(Mega Bits Per Second)
(iii) MGps
131
(d)
Approximate distances between these offices as per network survey team is as follows :
Place Form
Place To
Distance
Back Office
Front Office
10km
Back Office
Work Office
70 Meter
Back Office
East Office
1291km
Back Office
West Office
790 km
Back Office
South Office
1952 km
In continuation of the above , the company experts have planned to install the following number of
computers in each of their offices :
Front Office
100
Work Office
20
East Office
50
West Office
50
South Office
50
Front Office
50
(1)
Suggest network types (out of LAN , MAN, WAN) for connecting each of the following
set of their offices :
Back Office and Work Office
Back Office and South Office
Ans. Back Office and Work Office -LAN
Back Office and South Office - WAN
(2)
Which device you will suggest to be procured by the company for connecting all the
computers with in each of their offices out of the following devices?
Switch/Hub
Modem
Telephone
132
Ans.
( 3)
Switch / Hub
Which of the following communication medium, you will suggest to be procured by the
company for connecting their local offices in New Delhi for every effective and fast
communication?
Telephone Cable
Optical Fiber
Ethernet Cable
Ans. Optical Fiber
(4)
Suggest a cable/wiring layout for connecting the companys local offices located in New
Delhi. Also, suggest an effective method/technology for connecting the companys
regional offices East Office, West Office and South Office with Offices located
in New Delhi.
Ans.
133
Maximum Marks 70
General Instructions
1. All Questions are compulsory
2. Programming Language : C++
1.
(a) Differentiate between a Logical Error and Syntax Error. Also give suitable examples
of each in C++.
2
Ans :
Logical Error:Error occurred due to incorrect logic applied by the programmer.
Syntax Error: Error occurred due to not following the proper grammar/syntax of the
language
OR
Error occurred due to violating rules of the programming language
Example:
//Program to find area and perimeter of rectangle
void main()
{
int A,B,AR,P;
A=10;
B=20;
AR=2*(A*B); //Logical Error Wrong Formula
P=2*(A+B);
cout<<A<<P>>endl; //Syntax Error Use of >> with cout
}
(b) Name the header file(s) that shall be needed for successful compilation of the following
C++ code :
void main( )
{
char Text[40];
strcpy(Text,AISSCE);
puts(Text);
}
Ans :
string.h
stdio.h
(c) Rewrite the following program after removing the syntactical error(s), if any. Underline
each correction.
2
#include <iostream.h>
134
Ans :
2@4@8@
4 # 8 # 16 # 20 #
(e) Find the output of the following program :
#include<iostream.h>
void Indirect(int Temp=20)
{
for (int 1=10; I<=Temp; I+=5)
cout<<I<< , ;
cout<<endl;
135
}
void Direct (int &Num)
{
Num+=10;
Indirect(Num);
}
void main()
{
int Number=20;
Direct(Number) ;
Indirect();
cout<< Number= <<Number<<endl ;
}
Ans:
10, 15, 20, 25, 30,
10, 15, 20,
Number=30
(f) In the following C++ program what is the expected value of Myscore from Options (i) to
(iv) given below. Justify your answer.
2
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize();
int Score[] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2 + random(2)];
cout<<Myscore<<endl;
}
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
Ans :
(ii) 34
2.
Ans :
Base Class
Protected
Private
Access Specifier
Private
Protected
Public
Private
Protected
Public
Derived Class
Private
Protected
Protected
Not Accessible
Not Accessible
Not Accessible
136
(b) Answer the questions (i) and (ii) after going through the following class:
2
class Science
{
char Topic[20];
int Weightage;
public:
Science ( ) //Function 1
{
strcpy (Topic, Optics );
Weightage = 30;
cout<<Topic Activated;
}
~Science( ) //Function 2
{
cout<<Topic Deactivated;
}
(i) Name the specific features of class shown by Function 1 and Function 2 in the above
example.
Ans :
Function 1: Constructor/ Default Constructor
Function 2: Destructor
(ii) How would Function 1 and Function 2 get executed ?
Ans:
Function 1 is executed or invoked automatically when an object of class Science is created.
Function 2 is invoked automatically when the scope of an object of class Science comes to an
end.
OR
Example:
{
Science s1;//Constructor is invoked
} // the destructor is invoke
(c) Define a class Travel in C++ with the description given below :
Private Members :
T_Code of type string
No_of_Adults of type integer
No_of_Children of type integer
Distance of type integer
TotalFare of type float
Public Members :
A constructor to assign initial values as follows :
T_Code with the word NULL
No_of_Adults as 0
No_of_Children as 0
Distance as 0
TotalFare as 0
137
A function AssignFare( ) which calculates and assigns the value of the data member
TotalFare as follows :
For each Adult
Fare (Rs) For Distance (Km)
500 >=1000
300 <1000 & >=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned in the above table.
For example :
If Distance is 750, No_of_Adults = 3 and No_of_Children = 2 Then TotalFare should
be calculated as
No_of_Adults * 300 + No_of_Children * 150 i.e. 3 * 300 + 2 * 150 = 1200
A function EnterTraveK ) to input the values of the data members
T_Code, No_of_Adults, No_of_Children and Distance; and invoke the AssignFare( )
function.
A function ShowTraveK) which displays the content of all the data members for a
Travel.
Ans :
class Travel
{
char TCode[5]; //OR char *Tcode;
int No_of_Adults;
int No_of_Children;
int Distance;
float TotalFare;
public:
Travel();
void AssignFare();
void EnterTravel();
void ShowTravel();
};
Travel::Travel()
{
strcpy(TCode,NULL);// OR TCode[0]=\0 OR strcpy(TCode,\0)
// OR TCode=NULL if TCode is declared as char pointer
No_of_Adults = 0;
No_of_Children = 0;
Distance = 0;
TotalFare = 0;
}
void Travel::AssignFare()
{
if(Distance>=1000)
TotalFare = 500*No_of_Adults+250*No_of_Children;
else
if (Distance >= 500)
TotalFare = 300*No_of_Adults+150*No_of_Children;
else
TotalFare = 200*No_of_Adults+100*No_of_Children;
}
void Travel::EnterTravel()
{
gets(TCode); // or cin >> TCode;
cin>>No_of_Adults>>No_of_Children>>Distance;
AssignFare();
138
}
void Travel::ShowTravel()
{
cout<<TCode<<No_of_Adults<<No_of_Children <<Distance<<TotalFare<<endl;
}
(d) Answer the questions (i) to (iv) based on the following code :
class Teacher
{
char TNo[5], TName[20], DeptflO];
int Workload;
protected:
float Salary;
void AssignSal(float);
public:
Teacher( ) ;
void TEntry( ) ;
void TDisplay( );
};
class Student
{
char Admno[10], SName[20], Stream[10];
protected:
int Attendance, TotMarks;
public:
Student( );
void SEntry( );
void SDisplay( );
};
class School : public Student, public Teacher
{
char SCode[10], SchName[20];
public:
School ( ) ;
void SchEntry( );
void SchDisplay( );
};
(i)
Which type of Inheritance is depicted by the above example ?
Ans :
Multiple Inheritance
(ii) Identify the member functiion(s) that cannot be called directly from the
objects of class School from the following :
TEntry( )
SDisplay( )
SchEntry( )
Ans :
None
(ii)
Write name of all the member(s) accessible from member functions of class
School.
Ans : Data Members: SCode, SchName, Attendance, TotMarks, Salary
Member Functions: SchDisplay(), SchEntry(), SEntry(), SDisplay( ),TEntry( ),
139
TDisplay( ),AssignSal( )
(iv) If class School was derived privately from class Teacher and privately from class Student,
then, name the member function(s) that could be accessed through Objects of class School.
Ans : SchEntry( ), SchDisplay( ).
3.
(a) Write a function in C++ which accepts an integer array and its size as arguments and
replaces elements having even values with its half and elements having odd values with twice
its value.
4
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as
6, 2, 10, 8, 18
Ans :
void Display(int NUM[],int N)
{
for(int i=0;i<N;i=i+1)
{
if(NUM[i]%2==0)
NUM[i]=NUM[i]/2;
else
NUM[i]=2*NUM[i];
}
}
OR
void Display(int NUM[],int N)
{
for(int i=0;i<N;i=i+1)
NUM[i]=(NUM[i]%2!=0)?2*NUM[i]:NUM[i]/2;
}
(b) An array Arr[15][20] is stored in the memory along the row with each element occupying 4
bytes. Find out the Base Address and address of the element Arr[3][2], if the element Arr[5][2] is
stored at the address 1500.
4
Ans :
Assuming LBR=LBC=0
S=4 bytes
Number of Rows(N)=15
Number of Columns(M)=20
LOC(Arr[I][J]).
= B +((I-LBR)*M+(J-LBC))*S
LOC(Arr[5][2]).
= B +((5-0)*20+(2-0))*4
1500. = B +(100+2)*4
B.= 1500-408
B.= 1092
LOC(Arr[3][2].= 1092+((3-0)*20+(2-0))*4
..
= 1092 + (62*4)
.
.= 1092+248
.
= 1340
OR
Assuming LBR=LBC=1
S=4 bytes
140
Number of Rows(N)=15
Number of Columns(M)=20
LOC(Arr[I][J]).= B +((I-LBR)*M+(J-LBC))*S
LOC(Arr[5][2]).= B +((5-1)*20+(2-1))*4
1500 .= B +(80+1)*4
B .= 1500-324
B .= 1176
LOC(Arr[3][2]).= 1176+((3-1)*20+(2-1))*4
..
= 1176 + (41*4)
.= 1176+164
.
= 1340
(c) Write a function in C++ to delete a node containing customers information, from a
dynamically allocated Queue of Customers implemented with the help of the following
structure :
4
struct Customer
{
int CNo;
char CName[20];
Customer *Link;
};
Ans :
class QUEUE
{
Customer *Rear,*Front;
public:
QUEUE( ) { Rear=NULL; Front=NULL;}
void DELETE( );
~QUEUE( );
};
//Function definition DELETE()
void QUEUE::DELETE()
{
if(Front==NULL) // OR if(!Front)
cout<<\n Queue Underflow\n;
else
{
Customer *Temp;
Temp=Front;
cout<<Front->Cno<<:<<Front->Cname <<Deleted<<endl;//To be ignored
Front=Front->Link;
delete Temp;
if (Front==NULL)
Rear=NULL;
}
}
(d) Write a function in C++ which accepts a 2D array of integers and its size as arguments and
displays the elements of middle row and the elements of middle column.
2
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 33, 55, 77 etc...]
141
4.
15
15, 3
15, 3, 2
15, 5
3
3, 7
10
10, 2
20
(a) Observe the program segment given below carefully, and answer the question that
follows :
1
class Labrecord
{
int Expno;
char Experiment[20];
char Checked;
int Marks;
public :
//function to enter Experiment details
void EnterExp( );
//function to display Experiment details
void ShowExp ( ) ;
//function to return Expno
char RChecked ( ) {return Checked;}
//function to assign Marks
void Assignmarks(int M)
142
{ Marks = M;}
};
void MpdifyMarks()
{
fstream File;
File.open(Marks.Dat,ios::binary|ios::in|ios::out);
Labrecord L;
int Rec = 0;
while (File.read((char*)&L, sizeof(L)))
{
if(L.RChecked( )== N )
L.Assignmarks(0)
else
L.Assignmarks(10)
_____________________ //statement 1
______________________ //statement 2
Rec ++ ;
}
File.close ();
}
If the funption ModifyMarks() is supposed to modify Marks for the records in the file
MARKS.DAT based on their status of the member Checked (containing value either V or
N). Write C++ statements for the statement 1 and statement 2, where, statement 1 is
required to position the file write pointer to an appropriate place in the file and statement 2
is to perform the write operation with the modified record.
Ans :
Statement 1:
File.seekg(-1*sizeof(L),ios::cur);
OR
File.seekg(Rec*sizeof(L));
OR
File.seekp(-1*sizeof(L),ios::cur);
OR
File.seekp(Rec*sizeof(L));
OR
Statement 2:
File.write((char *) &L,sizeof(L));
OR
(b) Write a function in C++ to print the count of the word the as an independent word
inatextfileSTORY.TXT.
2
For example, if the content of the file STORY.TXT is
There was a monkey in the zoo. The monkey was very naughty. Then the output of the
program should be 2.
Ans :
void thewordCount()
{
ifstream Fil(STORY.TXT);
char String[20];
int C=0;
while(!Fil.eof())
{
143
Fil>>String;
if(strcmpi(String,the)==0)
C=C+1;
}
cout<<C<<endl;
Fil.close();
(c) Given a binary file SPORTS.DAT, containing records of the following structure type
:
struct Sports
{
char Event[20];
char Participant[10][30];
};
(d) Write a function in C++ that would read contents from the file SPORTS.DAT and creates a
file named ATHLETIC.DAT copying only those records from SPORTS.DAT where the
event name is Athletics.
3
Ans :
void SP2AT()
{
fstream IS,OA;
Sports S;
IS.open(SPORTS.DAT,ios::binary|ios::in);
OA.open(ATHLETIC.DAT,ios::binary|ios::out);
while(IS.read((char*) &S,sizeof(S)))
{
if(strcmp(S.Event,Athletics)==0)
OA.write((char *)&S,sizeof(S));
}
IS.close();
OA.close();
}
5.
(a) What is the importance of a Primary Key in a table ? Explain with a suitable
example. 2
Ans :
The Primary Key is an attribute/set of attributes that identifies a tuple/ row/ record uniquely.
Example:
Rollnumber in the table STUDENT
(b) Consider the following tables Consignor and Consignee. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
6
TABLE : CONSIGNOR
CnorlD
CnorName
ND01
ND02
MU15
MU50
R Singhal
Amit Kumar
R Kohli
S Kaur
CnorAddress
24, ABC Enclave
123, Palm Avenue
5/A, South Street
27-K, Westend
City
New Delhi
New Delhi
Mumbai
Mumbai
144
TABLE : CONSIGNEE
CneelD
CnorlD
CneeName
CneeAddress
CneeCity
MU05
ND08
KO19
MU32
ND48
ND01
ND02
MU15
ND02
MU50
Rahul Kishore
P Dhingra
A P Roy
S Mittal
B P Jain
5, Park Avenue
16/J, Moore Enclave
2A, Central Avenue
P245, AB Colony
13, Block D, A Vihar
Mumbai
New Delhi
Kolkata
Mumbai
New Delhi
(ii) To display the CneelD, CnorName, CnorAddress, CneeName, CneeAddress for every
Consignee.
Ans :
SELECT B.CneeID, A.CnorName, A.CnorAddress, B.CneeName , B.CneeAddress
FROM Consignor A, Consignee B
WHERE A.CnorID=B.CnorID;
(iii)
Ans :
SELECT * FROM CONSIGNEE ORDER BY CneeName;
(v)
Ans :
DISTINCT CneeCity
Mumbai
New Delhi
Kolkata
(vi)
Ans :
A.CnorName
R Singhal
Amit Kumar
(vii)
B.CneeName
Rahul Kishore
S Mittal
FROM Consignee
WHERE CneeCity NOT IN (Mumbai, Kolkata);
Ans :
CneeName
P Dhingra
B P Jain
(viii)
CneeAddress
16/J,Moore Enclave
13,Block D,A Vihar
Ans :
CneeID
MU05
KO19
CneeName
Rahul Kishore
A P Roy
6.
(a) State De Morgans Theorems and verify the same using truth table.
Ans :
If X, Y B
(X+Y)=X.Y
X
0
0
1
1
Y
0
1
0
1
X
1
1
0
0
Y
1
0
1
0
X+Y
0
1
1
1
(X+Y) X.Y
1
1
0
0
0
0
0
0
X
0
0
1
1
Y
0
1
0
1
X
1
1
0
0
Y
1
0
1
0
X.Y
0
0
0
1
(X.Y) X+Y
1
1
1
1
1
1
0
0
(X.Y)=X+Y
(b) Write the equivalent Canonical Product of Sum Expression for the following Sum of
Product Expression
F(X, Y, Z) =
2
Ans :
F(X, Y, Z) = p (1, 3, 6, 7)
OR
F=(X+Y+Z)(X+Y+Z)(X+Y+Z)(X+Y+Z)
(c) Write the equivalent Boolean expression for the following Logic Circuit.
146
Ans:
F=A.B+C.D
(d) Reduce the following Boolean expression using K-Map :
F(A, B, C, D) = (5,6,7,8,9,12,13,14,15)
Ans:
F(A,B,C,D)=(A+C).(B+D).(B+C)
7.
(a) What is the significance of Cyber Law ?
1
Ans :
Cyber law encompasses a wide variety of political and legal issues related to the Internet and
other communications technology, including intellectual property, privacy, freedom of
expression, and jurisdiction.
(b) Expand the following terms with respect to Networking :
(i) XML
(ii) WWW
(iii) WLL
(iv) TCP/IP
(c) Which of the following units measures the speed with which data can be transmitted from one
node to another node of a network ? Also, give the expansion of the suggested unit. 1
(i) KMph
(ii) Mbps
(iii) MGps
147
Approximate distances between these offices as per network survey team is as follows :
Place From
Place To
Distance
Head Office
Sales Office
10 KM
Head Office
Tech Office
70 Meter
Head Office
Kolkata Office
1291 KM
Head Office
Ahmedabad Office
790 KM
Head Office
Coimbatore Office
1952 KM
In continuation of the above, the company experts have planned to install the following
number of computers in each of their offices :
Head Office
Sales Office
100
20
Tech Office
Kolkata Office
Ahmedabad Office
Coimbatore Office
50
50
50
50
(i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set
of their offices :
Head Office and Tech Office
Head Office and Coimbatore Office
148
149
Maximum Marks 70
General Instructions
3. All Questions are compulsory
4. Programming Language : C++
Q1. a. Name the header file to which the following belong:
(1 )
i.
pow( )
ii.
random( )
b. Illustrate the use of inline function in C++ with the help of an example.
(2)
c. Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction.
(2)
#include <iostream.h>
void main( )
{ struct movie
{
char movie_name [20];
char movie type;
int ticket cost = 100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
d. Find the output of the following program:
(3)
#include<iostream.h>
#include<string.h>
class student
{
char *name;
int l ;
public:
student( ) {l=0; name=new char I1+1]; }
student (char *s)
{
I =strlen(s); name=new char[I+1];
strcpy (name,s);
}
void display( ) {cout<<name<<endl;}
void manipulate(student & a, student & b)
{ I = a. I + b.I;
delete name;
name=new char[I+1];
strcpy(name, a.name);
strcat(name, b.name);
}
};
150
void main( )
{
char * temp = Jack;
student name1 (temp), name2( Jill), name3(John),S1,S2;
S1 .manipulate (name1, name2);
S2.manipulate (SI, name3);
S1.display ( );
S2.display ( );
}
e. Find the output of the following program:
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
f. What is a default constructor? How does it differ from destructor?
Q2. What is this pointer? Give an example to illustrate the use of it in C++.
(2)
(2)
a. Answer the questions (I) and (ii) after going through the following class:
class Exam
{ int year;
public:
Exam(int y) {year=y;} //Constructor 1
Exam(Exam & t);
///Constructor 2
};
i.
Create an object, such that it invokes Constructor I.
(1)
ii.
Write complete definition for Constructor 2.
(1)
b. Define a class named HOUSING in C++ with the following descriptions:
(4)
Private members
REG_NO
integer(Ranges 10 1000)
NAME
Array of characters(String)
TYPE
Character
COST
Float
Public Members
Function Read_Data( ) to read an object of HOUSING type
Function Display() to display the details of an object
Function Draw Nos( ) to choose and display the details of 2 houses selected randomly
from an array of 10 objects of type HOUSING Use random function to generate the
registration nos. to match with REGNO from the array.
151
Q3.
a. Write a function in C++ which accepts an integer array and its size as arguments/parameters and
assign the elements into a two dimensional array of integers in the following format: (3)
If the array is 1, 2, 3,4,5,6
if the array is 1, 2, 3
The resultant 2 D array is given below
The resultant 2 D array is given below
b.
If the array is 1, 2, 3, 4, 5, 6
If the array is 1, 2, 3
The resultant 2 D array is given below
The resultant 2 D array is given below
1
2
0
0
0
0
1
0
0
1
2
0
0
0
0
1
2
0
1
2
3
0
0
0
1
2
3
1
2
3
4
0
0
1
2
3
4
5
0
1
2
3
4
5
0
152
c. An array MAT [20] [10] is stored in the memory along the row with each element occupying
4 bytes of memory. Find out the base address and the address of element MATE[10][5] if the
location of MAT [3][7] is stored at the address 1000.
(4)
d. Introduction class stack
{
int data [10];
int top;
public:
stack( ) { top=-l }
void push( ); //to push an element into the stack
void pop( ); //to pop an element from the stack
void Delete(int ITEM); //To delete all elements which are equal to ITEM
};
Complete the class with all function definitions. Use another stack to transfer data
temporarily.
(4)
e. Write a function in C++ to perform Insert operation in dynamically allocated Queue
containing names of students.
(3)
f. Write the equivalent infix expression for
(2)
10,3, *, 7,1, *, 23, +
Q. 4.
a. void main( )
{
char ch=A;
fstream fileout( data.dat, Ios::app);
fileout<<ch;
int p fileout.tellg( );
cout<<p;
What is the output if the file content before the execution of the program is the string ?
ABC (Note that are not part of the file)
(1)
b. Write a function to count the number of blanks present in a text file named PARA.TXT.(2)
c. Following is the structure of each record in a data file named PRODUCT.DAT.
struct PRODUCT
{
char Prodact_Code[10];
char Product_Descriptionil[10];
int Stock;
};
Write a function in C++ to update the file with a new value of Stock. The Stock and the
Product Code, whose Stock to be updated, are read during the execution of the program. (3)
Q. 5.
a. What are DDL and DML?
(2)
b. Study the following tables FLIGHTS and FARES and write SQL commands for the
questions (i) to (iv) and give outputs for SQL queries (v) to (vi).
TABLE : FLIGHTS
FL_NO
STARTING
ENDING
NO_FLIGHTS
NO STOPS
IC301
MUMBAI
DELHI
IC799
BANGALORE
DELHI
MC101
INDORE
MUMBAI
IC302
DELHI
MUMBAI
AM812
KANPUR
BANGALORE
153
IC899
MUMBAI
KOCHI
AM501
DELHI
TRIVANDRUM
MU499
MUMBAI
MADRAS
IC701
DELHI
AHMEDABAD
TABLE : FARES
FL_NO
AIRLINES
FARE
1C701
Indian Airlines
6500
10
MU499
Sahara
9400
AM501
Jet Airways
13450
IC899
Indian Airlines
8300
1C302
Indian Airlines
4300
10<
1C799
Indian Airlines
10500
10
MC101
Deccan Airlines
3500
i.
ii.
iii.
iv.
v.
vi.
TAX%
Display FL_NO and NO_FLIGHTS from KANPUR to BANGALORE from the table
FLIGHTS.
Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
Display the FLNO and fare to be paid for the flights from DELHI to MUMBAI using the
tables FLIGHTS and FARES, where the fare to be paid = FARE +FARE*TAX%/100.
Display the minimum fare Indian Airlines is offering from the table FARES.
SELECT FL_NO, NO_FLIGHTS, AIRLINES from FLIGHTS, FARES where
STARTING=DELHI and FLIGHTS.FL_NO=FARES.FL_NO.
SELECT count (distinct ENDING) from FLIGHTS. (6)
Q. 6.
a. State and verify Associative Law.
b. Write the equivalent expression for the following logical circuit:
(2)
(2)
(1)
(3)
(1)
(2)
iv.
MAN
(1)
154
d. INDIAN PUBLIC SCHOOL in Darjeeling is setting up the network between its different wings.
There are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and HOSTEL(H).
Distance between various wings are given below:
Wing A to Wing S
100m
Wing A to Wing J
200m
Wing A to Wing H
400m
Wing S to Wing J
300m
Wing S to Wing H
100m
Wing J to Wing H
450m
Number of Computers
Wing A
10
Wing S
200
Wing J
100
Wing H
50
i.
ii.
iii.
iv.
(1)
(1)
(1)
(1)
155