Académique Documents
Professionnel Documents
Culture Documents
4/6/15
Max. Marks: 70
Time: 3 hrs
General Instructions:Please check that this question paper contains 6 printed pages.
Please write down the serial number of the question before attempting it.
Programming Language : C++
1 a)
Find the correct identifiers from the following which can be used for naming 2
variable, functions etc.
int_num, Marks Maths, Break, count, 12Grade, Amt_in_$, Sqrt, random
int_num, Break, count, Sqrt
mark for each
b)
Name the header files required to execute the following code:
1
void main()
{
int ctr= 0 , num1;
char string[] = 2015 Batch Comp. Sc. DPS;
for ( int k = 0 ; string[k]!=\0; k++)
if(isupper(string[k])
ctr++;
cout<<(string);
}
ctype.h iostream.h mark for each
c)
Rewrite the following code after removing syntax errors
2
#include <iostream.h>
const int Num = 3;
void main ()
{
int Value=15;
for (int K = 1; K<=5; K++,Value -= 2)
if (Value % Num==0)
{ cout<<Value * Num;
cout<<endl; }
Page 1 of 9
d)
e)
f)
a)
b)
else
cout<<Value + Num<<endl;
} // for each error
Find the output of the following program code:
Note: Assume all required header files are included.
a is 28 b is 12
a is 48 b is 12
a is 48 b is 70
mark for each correct value printed.
Go through the C++ code shown below, and find out the possible output(s)
from the suggested output options (i) to(iv).
iii) 11:12:13:14:15:#
iv) 14:15:#
1 mark each for correct answer
Write a function power() that takes two arguments, a double for n and an
integer value for p and returns the result as double. The function takes a
default value of p as 3, so that a cube is calculated if this argument in
omitted. Use of the inbuilt function pow() is NOT ALLOWED.
double power(double n, int p) // mark
{
double val= 1;
for( int k = 0 ; k<p ; k++) // mark
val = val * n; // mark
return val; // mark
}
What do you understand by function overloading in context with Object
oriented Programming. Explain giving suitable examples (codes).
A function having same name but several definitions which are
differentiable by the signature i.e. number or type of their arguments
is known as function overloading.
Example:
void disp() { cout<<\n Hello; }
void disp(int n) { for ( int i = 0 ; i<n ; i++) cout<< \n<< i; }
void disp( int n, int m) { for( int i = n; i<=m ; i++) cout<< \n<< n*m; }
void disp( int n, char a[]) { for ( int k = 0 ; k<n ;k ++) { cout<< \n<< a;}
1 mark for correct explanation of function overloading
1 mark for valid example
Define a class student with the given specifications
class student
Page 2 of 9
a)
b)
c)
i)
long admno;
char name[20], course[30];
float fee;
public:
student()
{ admno = 0; strcpy(name, Not Initialized;
strcpy( course, Not Initialized; fee = -100.00; }
student( long a, char na[], char co[])
{ admno = a; strcpy(name, na); strcpy(course, co);
if strcmpi(course, Oracle)==0) fee = 4590;
else if (strcmpi(course, Java)==0) fee = 6570;
else if ( strcmpi(course, Graphic Designing) ==0) fee = 9000;
}
student(student & s)
{ admno = s.admno +1; strcpy(name, s.name);
strcpy(couse, s.course); fee = s.fee; }
void print() { cout<< \n<< admno; cout<<\n<< name;
cout<< \n<<course<< \n<<fee; }
~student() { cout<< \n Work done; }
};
// 1 mark for default constructor
// 1 mark for parameterized constructor
// 1 mark for copy constructor
// mark for print and for destructor
Abstract class: The class that serves only as a base class form which other 1
classes are derived but no object of this base class type exists.
Concrete class : The class that acts as a base class but objects of this class
do exist.
// 1 mark for each definition
Define a class Worker having the following specifications
4
// mark for correct sytax of class header
// 1 mark for correct definition of function assign_wage
// 1 mark for correct definition of calc_wage
// mark for accept and correct invocation of assign_wage
// 1 mark for Print and correct invocation of calc_wage
Using the given class Member, write functions for the following:
To display the records of members paying charges between 10000 and 2
15500.
Page 3 of 9
ii)
a)
}
Answer questions i) to iv) based on the following:
Hierarchical // 1 Mark
Perimeter, fencing cost, calc(), display(), length, breadth, Accept
and Print // 1 mark
iii)
None // 1 mark
iv)
Rectangle , Perimeter // 1 Mark
v)
36 // 1 Mark
What is the difference between members in private visibility mode and the
members in protected visibility mode? Give a suitable C++ code to illustrate
both.
1 mark for difference and 1 for example.
Explain the difference between get() and getline() functions.
get() is used to read characters whereas getline is used to read strings.
Get takes only 1 parameter whereas getline takes 3/2 parameters.
mark for explaining each.
Assuming a text file Textbook.txt contains strings of data. Write functions
for:
i)
void Read()
i)
ii)
b)
a)
b)
Page 4 of 9
1
1
1
1
1
2
ii)
iii)
}
3
int Count()
{
ifstream f1(Textbook.txt); // mark
int count= 0; char words[20]; // mark
if(!f1)
cout<<File could not be opened;
while(f1>>words) // mark
{
if(strcmpi(Words,Database)==0||
strcmpi(Words,Boolean)==0) // mark
count++; // mark
f1.close();
return count;// mark
}
//Deduct mark if function header does not reflect int return
type
void Print()
{
ifstream f1(Textbook.txt); // mark
char words[20]; // mark
if(!f1)
cout<<File could not be opened;
while(f1>>words) // mark
{
for(int k = 0 ; words[k]!=\0; k++)// mark
{
switch(toupper(words[k])) // 1 mark
{
Page 5 of 9
case A :
case E :
case I :
case O :
case U : break;
default : cout<<words<<\n;
}
f1.close();
iv)
v)
}
void CountAD()
{
ifstream f1(Textbook.txt); // mark
int count1= 0, count2=0; char words; // mark
if(!f1)
cout<<File could not be opened;
while(f1>>words) // mark
{
if(isalpha(words))
count1++; // mark
else if ( isdigit(words))
count2++; // mark
f1.close();
cout<<\n not of alphabets are<< count1;
cout<<\n Non of digits are << count2;
// mark for printing both
}
void Copy()
{
ifstream f1(Textbook.txt); ofstream f2(Mfile.txt);
// mark each for opening both correctly
char Lines[90]; // mark
if(!f1)
cout<<File could not be opened;
while(f1.getline(Lines, 90, #)) // mark
{
If(Lines[0]==M ||Lines[0] ==m)// mark
Page 6 of 9
f2<<words<<endl; // mark
f1.close();
f2.close();
a)
b)
c)
d)
e)
a)
}
State De Morgans theorem and prove any one algebraically.
De Morgan states that
(X.Y) = X + Y
(X+Y) = X. Y
1 mark for stating both theorems and 1 for proof of any one
Find the complement and dual of the given expression
( XY +Z W )
Complement (X +Y) ( Z + W)
Dual ( X + Y) ( Z + W)
mark for each correct expression
Convert [( X Y ) +( X Z)] into Canonical SOP form.
= XYZ + XYZ + XYZ + XYZ +XYZ
//2 MARK FOR THE CORRECT SOP
Draw a logic circuit using NAND gates only.
( X + Y ) ( XY +XY)
= X Y + XY
= (XY + XY)
= ((XY). (XY))
// 1 mark for expression and 1 for logic circuit
Reduce the given expression using K- Map
F(P, Q, R, S) = ( 0, 2, 3, 4, 6, 7, 9, 11, 12, 13)
b)
link to another switching station and sends data to that station. This
process continues until data is delivered to the destination computer.
This type of switching technique is also known as "store and forward"
switching.
( Marks for written OR diagrammatic explanation of correct Packet
Switching)
( Marks for written OR diagrammatic explanation of correct Message
Switching)
Differentiate between the following
2
i)
BUS and STAR topology of networks.
Bus Topology
Star Topology
Slower as compared to star
Expensive as compared to Bus
Breakage of wire at any point Long wire length
disturbs the entire network
(1/2 Marks for written or diagrammatic explanation of correct Bus Topology)
(1/2 Marks for written or diagrammatic explanation of correct Star Topology)
ii)
c)
d)
ii)
iii)
iv)
Page 9 of 9