Cs PDF
Cs PDF
1 Mark Questions
1. Name the header files to which the following belong:
(i) puts() (ii) isalnum()
2. Write the name of the header files to which the following belong:
(i) strcat() (ii) atoi()
3. Name the header files in which the following belong:
(i) pow() (ii) random()
4. Name the header files in which the following belong:
(i) gets() (ii) open()
5. 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);
}
6. Name the header files that shall be needed for the following code:
void main() {
char word[] = Exam;
cout<<setw(20)<<word;
}
7. What is cascading?
8. What is the purpose of default clause in a switch statement?
9. What are the applications of void data type in C++?
10. What is the effect of absence of break in switch-case statement?
11. Give the output of the following program segment:
Int I =200, = 18;
cout<< i/j << endl;
12. When will you make a function inline?
13. What is the significance of any empty parentheses in a function declared?
14. How are abstraction and encapsulation inter-related?
15. Write the declaration of inline function named bar() that takes one argument of type float and
return type int.
16. Observe the following C++ and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler.
void main()
{
float Area,Side;
cin>>Area;
Side = sqrt (Area):
cout<< One Side of the Square=<<Side<<endl ;
}
17. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler.
void main ()
{
Int Number;
cin>>Number;
if (abs (Number) = = Number);
cout<< Positive<<endl;
}
18. Name the header file(s), which are essentially required to run the following program segment.
void main ()
{
char A= K,B;
if (islower (A) )
B=toupper (A);
else
B= *;
cout<<A>> turned to <<B<<endl;
}
19. Write the names of the headers files to which the following belong:
(i) puts ( ) (ii) sin ( )
20. Write the name of the header file to which the following belong:
(i) puts ( ) (ii) randomize ( )
21. Observe the following C++ code and write the name(s) of the header file (s), which will be
essentially required to run in a C++ compiler.
void main ( )
{
char Text[20],c;
cin>>Text;
C=tolower (Text[0]);
cout<<C<< is the first char of<<Text<<endl;
}
22. Observe the following C++ code and write the name(s) of the header file (s), which will be
essentially required to run in a C++ compiler.
void main ( )
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<< starts with<<CH<<endl; }
23. Which C++ header files(s) are essentially required to be included to run/execute the following C++
source code?
void main ( )
{char STRING[ ]=Something;
cout<<Balance Characters :<<160-
strlen (STRING)<<CH<<endl;
}
(Note Do not include any header file, which is /are not required).
24. Which C++ header file(s) are essentially required to be include to run/execute the following C++
source code?
void main ( )
{
char Text[ ]=SomeThing;
cout<< Remaining SMS Chars:<< 160-
strlen (STRING) <<endl;
}
(Note Do not include any header file, which is /are not required).
25. Write the names of the header files, which is/are essentially required to run, execute the following
C++ code.
void main ( )
{
char C, string[ ]= Excellence Overload;
for (int I=0; string[ I ] != \0;I++)
if(string[ I ]== )
cout<<endl;
else
{
C=toupper (Text[ I ]) ;
cout<<C;
}
}
26. Write the names of the header files, which is/are essentially required to run/execute the following
C++ code.
void main ( )
{
char CH, Text[ ]= +ve Altitude;
for (int I =0; Text [ I ] != \0;I++)
if(Text[ I ]== 1 )
cout<<endl;
else
{
CH =toupper (Text[ I ]) ;
cout<<CH;
}
}
27. Which C++ header file(s) will be essentially required to be included to run/execute the following C++
code?
void main ( )
{
Int Rno=24;
char Name[]= Aman Singhania;
cout<<setw(10)<<Rno<<setw(20)
<<Name<<endl;
}
28. Name the header files that shall be needed for the following code
void main ( )
{
char Text[ ]= computers;
cout<<setw(15)<<Text;
}
29. Name the header files that are essential to run the following code segment successfully
void main()
{ char ch[10];
cout<<"enter ur name \n"; cin.getline(ch,10);
int l=strlen(ch);
cout.write(ch,l);
}
30. Find the correct identifiers out of the following, which can be used for naming
variable, constants or functions in a C++ program :
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
31. Find the correct identifiers out of the following, which can be used for naming Variable,
Constants or Functions in a C++ program :
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
32. Name the header files that are essential to run the following code segment successfully
void main()
{
int r;
float A,B;
cout<<"enter the radius of circle\n";
cin>>r;
A=3.14*pow(r,2);
B=32767;
cout<<"area =\t"<<A<<endl;
cout<<B;
}
33. Which of the following are valid identifiers?
Data_rec Data rec, 1 data, data 1, my.file, asm, switch, goto
34. What is the result of following expression? Y= (t=4, t+3);
35. What is the significance of preprocessor directive?
36. Why is char often treated as integer data type in C++ ?
37. Why main function is special in C++ ?
38. Write the names of the headers files to which the following belong:
randomize(), getch( )
39. Write the names of the headers files to which the following belong:
fabs(), atoi( )
40. Observe the following program very carefully and write the names of those header file(s),
which are essentially needed to compile and execute the following program successfully:
typedef char TEXT[80]
void main()
{
TEXT Str[] = Peace is supreme
int Index=0
while (Str[Index]!=\0)
if (isupper(Str[Index]))
Str[Index++]=#
else
Str[Index++]=*
puts(str)
}
41. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and
Statement 2 using seekg( ), seekp( ), tellp( ) and tellg( ) functions for performing the required task.
#include<fstream.h>
class PRODUCT
{ int Pno; char Pname[20); int Qty;
public :
void ModifyQty( ) ; // The function is to modify quantity of a
PRODUCT
} ;
void PRODUCT: :ModifyQty ( )
{ fstream File ;
File.open ("PRODUCT.DAT", ios::binary |ios :: in| ios::out) ;
int MPno;
cout<<"Product No to modify quantity : ";
cin>>MPNo;
while (File.read ((char*) this, sizeof(PRODUCT))
{ if (MPno == Pno)
{ cout<<"Present Quantity:"<<Qty<<end1 ;
cout<<"Changed Quantity:";cin>>Qty ;
int Position = _______________; //Statement 1
_____________________________; // Statement 2
File.write ((char*) this, sizeof (PRODUCT)) ; //Re-writing the
record
} }
File.close ( );
}
42. Find the output of the following C++ code considering that the binary file MEMBER.DAT
exists on the hard disk with records of 100 members:
class MEMBER
{
int Mno char Name[20]
public:
void In()void Out()
}
void main()
{ fstream MF
MF.open("MEMBER.DAT,ios::binary|ios::in)
MEMBER M
MF.read((char*)&M,sizeof(M))
MF.read((char*)&M,sizeof(M))
MF.read((char*)&M,sizeof(M))
int POSITION=MF.tellg()/sizeof(M)
cout<<"PRESENT RECORD:"<<POSITION<<endl
MF.close() }
43. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and
Statement 2 using tellg() and seekp() functions for performing the required task.
#include <fstream.h>
class Client
{
long Cno;
charName[20],Email[30] ;
public:
//Function to allow user to enter
//the Cno, Name,Email
void Enter() ;
//Function to allow user to enter
//(modify) Email
void Modify() ;
long ReturnCno()
{
return Cno;
}
};
void ChangeEmail()
{
Client C;
fstream F;
F.open (INFO.DAT,ios::binary|ios::in|ios::out);
long Cnoc; //Clients no. whose
//Email needs to be changed
cin>>Cnoc;
while (F.read((char*)&C,
sizeof(C)))
{
if (Cnoc= =C.ReturnCno())
{
C.Modify(); //Statement 1
int Pos = __________
//To find the current position
//of file pointer
_______________ // Statement 2
//To move the file pointer towrite the modified recordback onto the file for thedesired Cno
F.write((char*)&C, sizeof(C));
}
}
F.close();
}
44. Observe the program segment given below carefully and fill in the blanks marked as Line 1 and Line
2 using fstream functions for performing the required task.
#include <fstream.h>
class Stock
{
long Ino ; //Item Number
char Item [20] ; //Item Name
int Qty ; //Quantity
public:
void Get(int);
//Function to enter the content
void show( );
//Function to display the content
void Purchase (int Tqty)
{
Qty + = Tqty ;
} //Function to increment in Qty
long KnowIno ( )
{
return Ino;
}
};
void Purchaseitem(long PINo, int PQty)
//PINo -> Ino of the item purchased
//PQty -> Number of item purchased
{f
stream File;
File.open(ITEMS.DAT, ios ::binarylios ::inlios :: out);
int Pos = 1 ;
Stock S ;
while (Pos = = 1 && File.read((char*) &S,sizeof (S)))
if (S. KnowIno( ) ==PINo)
{
S. Purchase (PQty);
//To update the number of Items
Pos = File.tellg ( ) -sizeof (S) ;
__________________;
//Line 1: To place the file
//pointer to the required position
___________________;
//Line 2: To write the object s on to
//the binary file
}i
f (Pos = = 1)
cout<<No updation done as
required Ino not found.. ;
File.close ( ) ;
45. Observe the program segment given below carefully, and answer the question that follows
class candidate
{ long Cid ; // Candidates Id
char CName[20]; // Candidates Name
float Marks ; // Candidates Marks
public ;
void Enter( ) ;
void Display( ) ;
void MarksChange( ) ;
//Function to change marks
long R_Cid( )
{ return Cid;
}
};
void MarksUpdate (long Id)
{
fstream File ;
File.open (CANDIDATE.DAT, ios ::binary|ios::in|ios :: out) ;
Candidate C ;
int Record = 0, Found = 0 ;
while (!Found&&File.read((char*)&C,sizeof(C)))
{
if (Id = =C.R_Cid( ))
{ cout << Enter new Marks ;
C.MarksChange( ) ;
____________ //Statement1
___________ //Statement 2
Found = 1 ;
}
Record++ ;
}
if (Found = = 1)
cout << Record Updated ;
File.close( ) ;
}
Write the Statement to position the File Pointer at the beginning of the Record for which the Candidates Id
matches with the argument passed, and Statement 2 to write the updated Record at that position.
46.
Fill in the blanks marked as Statement 1 and Statement 2 in the program segment given below with
appropriate functions for the required task.
class Club
{
long int Mno ; //Member number
char Mname [20] ; //Member name
char Email [30] ; //Email of member
public:
void Register ( ) ; //Function to register member
void Disp ( ) ; //Function to display details
void ChangeEmail ( ) //Function to change Email
{
cout<< Enter Changed Email:;
}
long int GetMno ( )
{
Return Mno ;
}
};
void ModifyData ( )
{
fstram File ;
File.open (CLUB DAT.ios: :binary ios : : out);
int Modify = 0. Position;
long int ModiMno;
cout<< Mno-whose email required to modified:;
cin>>ModiMno;
Club CL;
while(!Modify&&File.read((char*)&CL.sizeof(CL)))
{
If(CL.GetMno( ) == ModiMno)
{
CL.ChangeEmail ( );
Position = File.tellg( )-sizeof(CL);
//Statement 1: To place file pointer to the required position
;
//Statement 2: To write the object CL onto the binary file
;
Modify++;
}
}
If (Modify)
cout<< Email Changed. . .<<end];
else
cout<< Member not found. . .<<end];
File.close( );
}
47. Observe the program segment given below carefully and answer the questions that follow:
class Stock
{
int Ino,Qty; char Item[20];
public:
void Enter() {cin>>In0;gets(Item); cin>>Qty;}
void Issue(int Q) { Qty+=Q}
void Purchase(int Q) { Qty-=Q}
int GetIno(return Ino;}
};
void Purchaseitem(int Pino, int PQty)
{
fstream file;
File.open(STOCK.DAT,ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while (Success==0 && File.read((char*)&S, sizeof(S)))
{
if (Pino==S.GetIno())
{
S.Purchase(PQty);
_____________________________//Statement 1
_____________________________//statement 2
Success++;
}
}
if (Success==1)
cout<<Purchase Updated<<endl;
else
cout<<Wrong Item No<<endl;
File.close( );
}
(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is
done for the required item.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.
48.
Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2
using fstream functions for performing the required task.
#include <fstream.h>
class Library
{
long Ano; //Ano - Accession Number of the Book
char Title[20]; //Title - Title of the Book
int Qty; //Qty - Number of Books in Library
public:
void Enter (int); //Function to enter the content
void Display(); //Function to display the content
void Buy(int Tqty)
{
Qty+=Tqty;
} //Function to increment in Qty
long GetAno( )
{
return Ano;
}
};
void BuyBook(long BANo,int BQty) //BANo -> Ano of the book purchased
//BQty -> Number of books purchased
{ fstream File;
File.open(STOCK.DAT ,ios::binary|ios::in|ios::out);
int position=-l;
Library L;
while(Position==-l &&File.read((char*)&L,sizeof(L)))
if (L.GetAno()==BANo)
{
L.Buy(BQty);
//To update the number of Books
Position = File.tellg()-sizeof(L) ;
____________________;
//Line 1: To place the file pointer to the required position
____________________;
//Line 2:To write the object L on to the binary file
} if (Position==-l)
cout<< No updation do:r{e as
required Ano not found..;
File.close( );
}
49. Observe the program segment given below carefully,and answer the question that follows:
class Labrecord
{ int Expno;
char Experiment[20] ;
char Checked ;
int Marks ;
public :
void EnterExp( ) ;
//function to enter Experiment details
viod ShowExp( ) ;
//function to display Experiment details
char RChecked( )
//function to return Expno
{
return Checked;
}
void Assignmarks (int M)
//function to assign Marks
{
Marks = M;
}
};
void ModifyMarks( )
{
fstream File ;
File.open (Marks.Dat, ios :: binary lios :: in l 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 function ModifyMarks ( ) is supposed to modify marks for the records in the file MARKS.DAT based on
their status of the member Checked (containg value either Y 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.
50. Observe the program segment given below carefully , and answer the question that follows :
class Member
{
int Member_no ;
char Member_name[20] ;
public :
void enterdetails ( ) ; //function to enter Member details
void showdetails ( ) ; //function to display Member details
int RMember_no( )
{
return Member_no;
} //function to 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.
2 Marks Questions
37. What is copy constructor? Give an example in C++ to illustrate copy constructor.
41. How are binary files different from text files in C++?
42. What is a stream? Name the streams generally used for file I/O.
46. Differentiate between Protected and Private members of a class in context of inheritance using C++.
47. Define Multilevel and Multiple inheritance in context of Object Oriented Programming. Give suitable
example to illustrate the same.
48. Differentiate between public and protected visibility in context of Object Oriented Programming
giving suitableexamples for each.
49. How does the invocation of constructor differ in derivation of class and nesting of classes?
50. What is the difference between the constructor and normal function?
51. Observe the following C++ code very carefully and rewrite it after removing any/all
syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
#Define float Max=70.0
Void main()
{
int Speed
char Stop=N
cin>>Speed
if Speed>Max
Stop=Y
cout<<Stop<<end
}
52.
Observe the following C++ code very carefully and rewrite it after removing any/all syntactical
errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
const Max=70.0
void main[]
{
int Speed;
char Stop=N
cin<<Speed
if (Speed>Max)
Stop=Y
cout<<Stop<<endline
}
53.
Rewrite the following program after removing the syntactical error(s) if any. Underline each correction.
#include<iostream.h>
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<<N1>>N2;
}
54.
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 Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];
}
55.
Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}M;
gets(movie_name);
gets(movie_type);
}
56.
Rewrite the following program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int X[]={60, 50, 30, 40},Y;Count=4;
cin>>Y;
for(I=Count-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout<<Y*X[I]<<endl;break;
case1:
case 3:cout>>Y+X[I];
}}
57.
Rewrite thefollowing program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int P[]={90, 10, 24, 15},Q;Number=4;
Q=9;
for(int I=Number-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout>>P[I]*Q<<endl;
break;
case 1:
case 3:cout<<P[I]+Q;
}
58.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each
correction.
#include<iostream.h>
void main(){
Present=25,Past=35;
Assign(Present;Past);
Assign(Past);
}
void Assign(int Default1,Default2=30)
{
Default1=Default1+Default2;
cout<<Default1>>Default2;
}
59.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
void main(){
One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2=20)
{
Arg1=Arg1+Arg2
cout<<Arg1>>Arg2;
}
60.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each
correction.
#include<iostream.h>
typedef char[80];
void main(){
String S="Peace";
int L=strlen(S);
cout<<S<<'has'<<L<<'characters'<<endl;
}
61.
What are programming paradigms? Give names of some popular programming paradigms.
62. Reusability of classes is one of the major properties of OOP. How is it implemented in C++?
64.
Rewrite the following program after removing the syntactical errors (if any).Underline each correction.
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<<'characters'<<end1;
}
65. Observe the following C++ code very carefully and rewrite it after removing any/all
syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
66.
Study the following program and select the possible output(s)from the option (i) to (iv) following
it. Also write the maximum and the minimum values that can be assigned to the variable NUM.
Note: Assume all required header files are already being included in the program.
random(n) function generates an integer between 0 and n1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]="ABCDEFGHIJK";
for (int I=1;I<=NUM; I++)
{
for (int J=NUM;J<=7;J++)
cout<<TEXT[J];
cout<<endl;
}
}
(i)FGHI (ii) BCDEFGH (iii) EFGH (iv) CDEFGH
FGHI BCDEFGH EFGH CDEFGH
FGHI EFGH
FGHI EFGH
67.
Go through the C++ code shown below, and find out the possible output or outputs from the
suggested Output Options (i) to (iv). Also, write the least value and highest value, which can be
assigned to the variable Guess.
#include<iostream.h>
#include<stdlib.h>
void main ( )
{
randomize ( ) ;int Guess, High=4;Guess=random(High)+ 50 ;
for(int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;}
i) 50 # 51 # 52 # 53 # 54 # 55 # (ii) 52 # 53 # 54 # 55
(iii) 53 # 54 # (iv) 51 # 52 # 53 # 54 # 55
68. Go through the C++ code shown below, and find out the possible output or outputs from
the suggested Output Options (i) to (iv). Also find out the minimum and maximum value that can
be assigned to Guess at the time when value of Turn is 3.
#include<iostream.h>
#include<stdlib.h>
void main()
{
char Result[][10]={"GOLD","SILVER","BRONZE"};
int Gt=9,Guess;
for(int Turn=1;Turn<4;Turn++)
{
Guess=random(Turn);
cout<<(Gt-Guess)<<Result[Guess]<<"*";
}
}
(i) 9GOLD*9GOLD*8SILVER*
(ii) 9GOLD*7BRONZE*8GOLD*
(iii) 9GOLD*8SILVER*9GOLD*
(iv) 9GOLD*8SILVER*8GOLD*
69. Observe the code carefully and find which output(s) will be expected from the program?
and justify your answer:
#include <iostream.h>
#include <stdlib.h>
const int K=2;
void main()
{ randomize();
int A;
A=random(K)+2;
for(int i=A;i<3;i++)
cout<<i<<",";
cout<<endl;
}
(i) 1,2, (ii) 0,1,2 (iii) 2, (iv) 0,1,2,
70.
Observe the code carefully and find which output(s) will be expected from the program?
Justify your answer:
#include <iostream.h>
#include <stdlib.h>
void main()
{ randomize(); int A; A=2+random(3);
for(int i=A;i<5;i++)
cout<<'#'<<i;
}
#1#2#3 (ii) #2#3#4 (iii) #4#3#2 (iv) None of these
71.
Observe the code carefully and find which output(s) will not be expected from the program?
Justify your answer:
#include <iostream.h>
#include <stdlib.h>
const int K=4;
void main()
{ randomize();
int A;
A=2+random(K);
for(int i=0;i<A;i++)
cout<<i<<",";
}
(i) 0,1, (ii) 0,1,2, (iii) 0,2,4, (iv) 0,1,2,3,4,5,
72.
Observe the code carefully and select most possible answer from the choices given below and justify your
answer:
#include <iostream.h>
#include <stdlib.h>
#define K 4
void main()
{ randomize();
int A;
A=20+random(K);
for(int i=A;i>=20;i--)
cout<<i<<"^";
cout<<endl;
}
(i) 22^21^20^19^ (ii) 24^23^22^21^20^
(iii) 20^21^22^ (iv) 20^
73.
Observe the following code carefully, if the value of num entered by user is 4, choose the correct
possible output(s) from the options from (i) to (iv) and justify your option.
#include<iostream.h>
#include "stdlib.h"
void main()
{ randomize();
int num, rn;
cin>>num;
rn=random(num)+5;
for(int n=1;n<=rn;n++)
cout<<n<<" ";
}
Output options: (i) 1 2 3 (ii) 5 4 3 2 1
(iii) 1 2 3 4 5 6 (iv) 1 2 3 4
74.
Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are the
expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to the
variable Start used in the code :
#include<iostream.h>
#include <stdlib.h>
void main ()
{
int guess[4]={200,150,20,250};
int Start=random(2)+2;
for(int C1=Start; C1<4; C1++)
cout<<guess[C1]<<'#';
}
75
Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are the
expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to
the variable Taker used in the code :
#include<iostream.h>
#include <stdlib.h>
void main()
{ int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
cout<<GuessMe[Chance]<<"#"; }
(i) 100#
(ii) 50#200#
(iii) 100#50#200#
(iv) 100#50
76.
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .
void Position (int &C1, int C2=3)
{
C1+=2
C2+=Y
}
void main()
{
int P1=20, P2=4
Position(P1)
cout<<P1<<,<<P2<<endl
Position(P2,P1)
cout<<P1<<,<<P2<<endl
}
79.
Obtain the output from the following C++ program as expected to appear on the screen after its
execution.
Important Note : - All the desired header files are already included in the code, which are required to
run the code.
void main()
{ char *Text=AJANTA;
int *P, Num[]={1,5,7,9}; P=Num;
cout<<*P<<Text<<endl; Text++;
P++;
cout<<*P<<Text<<endl;
}
80.Obtain the output from the following C++ program as expected to appear on the screen after its
execution.
#include<iostream.h>
void SwitchOver(int A[],int N,int split)
{for(int K=0;K<N;K++)
if(K<split)
A[K]+=K; else A[K]*=K;
}
void Display(int A[],int N)
{ for(int K=0;K<N;K++)
(K%2==0)?cout<<A[K]<<"%":cout<<A[K]<<endl;
}
void main(){int H[]={30,40,50,20,10,5};
SwitchOver(H,6,3);
Display(H,6);
}
81.
Find the output of the following program :
#include <iostream.h>
#include <ctype.h>
void ChangeIt(char Text[ ], char C)
{ for (int K=0;Text[K]!='\0';K++)
{ if (Text[K]>='F' && Text[K]<='L')
Text[K]=tolower (Text[K]);
else
if (Text[K]=='E' || Text[K]=='e')
Text[K]=C;
else
if (K%2==0)
Text[K]=toupper(Text[K]);
else
Text[K]=Text[K-1];
}
}
void main ( )
{
char OldText[ ]="pOwERALone";
ChangeIt(OldText,'%');
cout<<"New TEXT:"<<OldText<<endl;
}
82.
Find. the output of the following program:
#include <iostream.h>
#include <ctype.h>
void MyCode (char Msg [], char CH)
{ for (int Cnt=0;Msg[Cnt]!='\0';Cnt++)
{ if (Msg[Cnt]>='B' && Msg[Cnt]<='G')
Msg[Cnt]=tolower(Msg[Cnt]);
else if (Msg[Cnt]=='A'|| Msg[Cnt]=='a')
Msg[Cnt]=CH;
else if (Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt-1];
}
}
void main ()
{ char MyText [] ="ApEACeDriVE";
MyCode(MyText,'@');
cout<<"NEW TEXT:"<<MyText<<endl;}
83. Find the output of the code segment given below:
#include<iostream.h>
void main( )
{ int A=5,B=10;
for(int I=1;I<=2;I++)
{ cout<<"Line1"<<A++<<"&"<<B-2 <<endl;
cout<<"Line2"<<++B<<"&"<<A+3 <<endl;
}
}
84. Find the putput.
#include<iostream.h>
void main( )
{ long int NUM=1234543;
int F=0,S=0;
do
{ int R=NUM % 10;
if (R %2!= 0)
F+= R;
else
S+= R;
NUM/= 10;
} while (NUM>0);
cout<<F-S;
}
85.Find the output of the following program:
#include<iostream.h>
void main( )
{ int var1=5,var2=10;
for(int i=1;i<=2;i++)
{ cout<<var1++<<'\t'<<--var2<<endl;
cout<<var2--<<'\t'<<++var1<<endl;
}
}
86.
What will be the result of following code in C++?
#include<iostream.h>
void main()
{ int a=4,b=2,c=6,d=1;
cout<<(a+6>=9+b || d*b<=10 && a+b+c/d)<<endl;
cout<<(a--+2*b+++a/d);
}
87.
Find the output of code given below:
#include <iostream.h>
int main() { int i=0,a=0,b=0,c=0;
while(i<=4)
{ switch(i++)
{ case 1: ++a;break;
case 2:
case 3: ++b;
case 4: ++c;
default: break; } }
cout<<"a="<<a<<"b="<<b<<endl; cout<<"c="<<c;
return 0;}
88.
What will be the output of the following code fragment?
#include<iostream.h>
int x=10;
void test( int a,int &b,int c=5)
{ a+=x+c; b=x*c; c=x/c;
cout<<a<<","<<b<<","<<c<<endl; }
void main( )
{ int x=10,y=20;
test(x,y,::x);
cout<<x<<","<<y<<","<<::x<<endl;
test(::x,x,y); cout<<::x<<endl; }
89.
Find the output of the following program:2
#include <iostream.h>
#include <ctype.h>
void Encode (char Info [ ], int N) ;
void main ( )
{ char Memo[ ]= "Justnow" ;
Encode (Memo,2) ;
cout<<Memo<<endl ;
}
void Encode (char Info [ ], int N)
{ for (int I = 0;Info[I] !='\0';I++)
if (I%2==0)
Info[I] = Info[I] -N ;
else if (islower(Info[I]))
Info[I] = toupper(Info[I]) ;
else
Info[I] = Info[I] +N ;
}
90.
Find the output of the following program:2
#include <iostream.h>
#include <ctype.h>
void Secret (char Mig[ ], int N);
void main ( )
{ char SMS[ ] = rEPorTmE ;
Secret{SMS,2);
cout<<SMS<<end1;
}
void Secret(char Msg[ ], int N)
{ for (int C=0; Msg[C] != \0' ;C++)
if (C%2==0)
Msg[C] = Msg[C]+N;
else if (isupper(Msg[C]))
Msg[C] = tolower(Msg[C]);
else
Msg[C] = Msg[C]-N;
}
91.
Obtain the output from the following c++ program as expected to appear on the screen after its execution.
knponant Note :
- All the desired header files are already included in the code, which are required to run the code.
#include <iostream.h>
void main ( )
{
char *String="SARGAM";
int *Ptr, A[]={1,5,7,9};
Ptr=A;
cout <<*Ptr<<String<<endl;
String++;
Ptr+=3;
cout<<*Ptr<<String<<endl ;
}
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
typedef char str80[80];
void main()
{
char *notes;
str80 str="vR.zGooD";
int L=6;
notes=str;
while(L>=3)
{
str[L]=isupper(str[L])?tolower(str[L]):toupper(str[L]);
cout<<notes<<endl;
L--;
notes++;
}
getch();
}
}
99. Find the output of following program:
#include<iostream.h>
void main( )
{
int Array[ ]={4,6,10,12};
int *pointer=Array;
for(int I=1;I<=2;I++)
{
cout<<*pointer<<"#";
pointer++;
}
cout<<endl;
for(I=1;I<=3;I++)
{ (*pointer)*=3;
--pointer;
}
for(I=1;I<3;I++)
cout<<Array[I-1]<<"@";
cout<<endl;
}
100. Find the output of following program:
#include<iostream.h>
void main( )
{ char *p="Difficult";
char c;
c=*p++;
cout<<c<<endl;
cout<<*p;
}
101. Observe the following C++ code and answer the questions (i) and (ii) :
class Traveller
{
long PNR
char TName[20]
public :
Traveller() //Function 1
{cout<<"Ready"<<endl}
void Book(long P,char N[]) //Function 2
{PNR = P strcpy(TName, N)}
void Print() //Function 3
{cout<<PNR << TName <<endl}
~Traveller() //Function 4
{cout<<"Booking cancelled!"<<endl}
}
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3 respectively
in the following code:
void main{)
{
Traveller T
_____________ //Line 1
_____________ //Line 2
}//Stops here
(ii) Which function will be executed at }//Stops here? What is this function referred as ?
102. Observe the following C++ code and answer the questions (i) and (ii) :
class Passenger
{
long PNR
char Name [20]
public:
Passenger() //Function 1
{ cout<<"Ready"<<endl }
void Book(long P,char N[]) //Function 2
{ PNR = P strcpy(Name, N) }
void Print() //Function 3
{ coutPNR << Name <<endl }
~Passenger() //Function 4
{ cout<<"Booking cancelled!"<<endl }
}
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3
respectively in the following code:
void main()
{
Passenger P
___________ //Line 1
___________ //Line 2
}//Ends here
(ii) Which function will be executed at }//Ends here? What is this function referred as?
103. Answer the questions (i) and (ii) after going through the following class :
class Health
{
int PId, DId;
public:
HeaIth (int PPId) ; // Function 1
Health ( ) ; // Function 2
Health (Health &H); //Function 3
void Entry ( ) ; // Function 4
void Display( ) ; // Function 5
};
void main ( )
t
Health H (20) ; //statement 1
}
(i) Which of the function out of Function 1,2,3, 4 or 5 will get executedwhen the Statement I is
executed in the above code ?
(ii) Write a statement to declare a new object G with reference to alreadyexisting object H using
Function 3.
104.
Answer the questions (i) and (ii) after going through the following class:
class TEST
{
int Regno, Max, Min, Score;
public:
TEST() //Function 1
{
Regno= 101;
Max=100;
Min=40;
Score=75;
}
TEST(int Pregno,int Pscore) //Function 2
{
Regno=Pregno;
Max=100;
Min=40;
Score=Pscore;
}
~TEST() //Function 3
{
cout<<TEST Over<<endl;
}
void Display() //Function 4
{
cout<<Regno<<:<<Max<<:<<Min<<endl;
cout<<[Score]<<Score<<endl;
}};
(i) As per Object Oriented Programming, which.concept is illustrated by Function 1 and
Function 2 together?
(i) What is Function 3 specifically referred as? When do you think, Function 3 will
beinvoked/called?
105.
Answer the questions (i) and (ii) after going through the following class:
class Race
{ int CarNo, Track;
public:
Race(); // Function 1
Race(int CN); // Function 2
Race(Race &R); // Function 3
void Register(); // Function 4
void Drive(); // Function 5
};
void main()
{ Race R;
}
(i) Out of the following, which of the option is correct for calling Function 2?
Option 1- Race T(30);
Option 2- Race U(R);
(ii) Name the feature of Object Oriented Programming, which is illustrated by Function 1, Function
2 and Function 3 combined together.
106. Answer the questions after going through the following class.
class Exam
{ char Subject[20] ;
int Marks ;
public :
Exam() // Function 1
{ strcpy(Subject, Computer ) ; Marks = 0 ;}
Exam(char P[ ]) // Function 2
{
strcpy(Subject, P) ;
Marks=0 ;
}
Exam(int M) // Function 3
{
strcpy(Subject, Computer) ; Marks = M ;
}
Exam(char P[ ], int M) // Function 4
{ strcpy(Subject, P) ; Marks = M ; }};
(i) Which feature of the Object Oriented Programming is demonstrated using Function 1, Function2,
Function 3 and Function 4 in the above class Exam?
(ii) Write statements in C++ that would execute Function 3 and Function 4 of class Exam.
107. Answer the questions (i) and (ii) after going through the following class:
class Exam
{
int Rno,MaxMarks,MinMarks,Marks;
public:
Exam ( ) //Module 1
{
Rno=101;
MaxMarks=l00;
MinMarks=40;
Marks=75;
}
Exam (int Prno, int Pmarks) //Module 2
{ Rno=Prno;
MaxMarks=l00;
MinMarks=40;
Marks=Pmarks;
}
~Exam () //Module 3
{
cout<<Exam Over<<endl;
}
void Show () //Module 4
{
cout<<Rno<<:<<MaxMarks<<:<<MinMarks<<endl
;
cout<<[Marks Got]<<Marks<<endl;
}
};
(i) As per Object Oriented Programming, which concept is illustrated byModule 1 and Module2
together?
(ii) What is Module 3 referred as ? When doyou think, Module 3 will be invoked/called?
108.
Consider the following declaration:
class welcome
{
public:
welcome (int x, char ch); // constructor with parameter
welcome(); // constructor without parameter
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);
109.
Answer the questions (i) and (ii) after going through the following program:
class TestMeOut
{ public:
~TestMeOut( ) //Function 1
{
cout<<Leaving the examination hall<<endl;
}
TestMeOut( ) //Function 2
{
cout<<Appearing for examination<<endl;
}
void MyWork( )
{
cout<<Attempting Questions<<endl;
}
};
(i) In Object Oriented programming what is Function 1 referred as and when does it get invoked/called?
(ii) In Object Oriented Programming,what is Function 2 referred as and when does it get invoked/called?
110.
Answer the following questions (i) and (ii) after going through the following class.
class Test
{ char Paper[20];
int Marks
public:
Test() //Function 1
{ strcpy(Paper, Computer);
Marks=0;
}
//Function 2
Test(char P[])
{ strcpy(Paper,P);
Marks=0;
}
//Function 3
Test(int M)
{ strcpy(Paper,Computer);
Marks=M;
}
Test(char P[],int M)
//Function 4
{ strcpy(Paper,P);
Marks=M;
}
};
(i)Which feature Object Oriented programming is demonstrated using Function 1, Function 2, Function 3
and Function 4 in the above class text?
(ii)Write statements in C++ that would execute Function 2 and Function 4 of class Text.
111.
Write function definition for SUCCESS () in C++ to read the content of a
text file STORY.TXT count the presence of word STORY and display the
number of occurrence of this word.
Note : The word STORY should be an independent word.
Ignore type cases (i.e. lower/upper case)
112.
Write function definition for TOWER() in C++ to read the contentof a
text file WRITEUP.TXT, count the presence of word TOWERand display the
number of occurrences of this word.
Note : The word TOWER should be an independent word
Ignore type cases (i.e. lower/upper case)
Example:
If the content of the file WRITEUP.TXT is as follows:
Tower of hanoi is an interesting problem.Mobile phone tower is away from
here. Viewsfrom EIFFEL TOWER are amazing.
The function TOWER () should display the following:3
113.
Write a function EUCount()in C++, which should read each character of a
textfile IMP.TXT, should count and display the occurrence of alphabets E
and U(including small cases e and u too).
Example :
If the file content is as follows:
Updated informationis simplified by official websites.
The EUCount() function should display the output as:
E:4
U:1
114.
Write a function AECount() in C++, which should read each character of a text file NOTES.TXT, should
count and display the occurrence of alphabets A and E (including small cases a and e too).
Example :
If the file content is as follows :
CBSE enhanced its
CCE guidelines further.
The AECount() function should display the output as
A:1
E:7
115.
Write a function CountYouMe() in C++ which reads the contents of a text
file story.txt and counts the wordsYou and Me (not case sensitive).
For example, if the file contains:
You are my best friend.
You and me make a good team.
The function should display the output as
Count for You: 2
Count for Me: 1
116.
Write a function TotalDigits() in C++ , which reads the contents of the
Text File child.txt and display the number of digits in it.
If the file contains:
All in all, I would like to be 500 note
and my elders would be 1000 note.
Then the output should be: 7
117.
Assuming the class WORKER as declared below, write a function in c++ to
read the objects of WORKER from binary file name WORKER.DAT and
display those records of workers whose wage is less than 300.
class WORKER
{ int WNO;char WName[50]; float Wage;
public :
void enter() { cin>>WNO; gets(WName); cin>>Wage;}
void display() { cout<<WNO<<*<<WName<<*<<Wage<<endl;}
float GetWage() { return Wage;}
};
118.
Write a function in a C++ to read the content of a text file UNO.TXT
and display all those lines on screen, which are either starting with
D or starting with M.
119.
Write a function in C++ to count the wordsthis and these present in
a text fileARTICLE.TXT.
[Note that the words this and these arecomplete words]
120.
Write a function in C++ to count the wordsto and the present in a
text filePOEM.TXT.
[Note that the words to and the arecomplete words]
121.
Write a function in a C++ to count the number of lowercase alphabets
present in a text file BOOK.txt.
122.
Assume a text file coordinate.txt is already created. Using this file
create a C++ function to count the number of words having first
character capital.
123.
Write a function to count the number ofblanks present in a text file
namedPR.TXT .
3 Mark Questions
class Calc
{
char Grade;
int Bonus;
public:
Calc(){Grade='E' ; Bonus=0;}
void Down(int G)
{ Grade= G; }
void Up(int G)
{ Grade+=G; Bonus++; }
void Show()
{ cout<<Grade<<"#"<<Bonus<<endl; }
};
void main()
{
Calc c;
C.Down(97); C.Show();
C.Up(3); C.Show();
C.Up(-32); C.Show();
}
2. Write the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
class Eval
{ char Level;
int Point;
public:
Eval() {Level='E';Point=0;}
void Sink(int L)
{ Level-= L; }
void Float(int L)
{ Level+= L; Point++; }
void Show()
{ cout<<Level<<"#"<<Point<<endl;
}};
void main()
{ Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
3. Obtain the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
class Player
{
int Score,Level;char Game;
public :
Player(char GGame='A')
{Score=0;Level=1;Game=GGame;}
void Start(int SC) ;
void Next();
void Disp()
{ cout<<Game<<"@"<<Level<<endl;
cout<<Score<<endl;
}};
void main()
{ Player P,Q('B');
P.Disp();
Q.Start(75);
Q.Next();
P.Start(120);
Q.Disp();
P.Disp();
}
void Player::Next()
{ Game=((Game=='A')?'B':'A'); }
void Player::Start(int SC)
{ Score+=SC;
if (Score >=100 )
Level=3;
else if (Score>=50 )
Level=2;
else
Level=1;
}
4.
Obtain the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
void in(int x,int y,int &z)
{ x+=y; y--; z*=(x-y); }
void out(int z,int y, int &x)
{ x*=y; y++;z/=(x+y); }
void main()
{ int a=20, b=30, c=10;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl;
in(b,c,a);
cout<<a<<"@"<<b<<"@"<<c<<"@"<<endl;
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}
5. Obtain the output of the following C++ program code:
#include<iostream.h>
class TQ
{
int r; float s;
public:
TQ(){ r=1;s=5;}
TQ(TQ &Q)
{ r=Q.r++; s=Q.s+=5; }
void Bonus(float B=5)
{ s+=B; }
void Res() { cout<<r<<','<<s<<endl;}
};
void main()
{ TQ A;
A.Res();
A.Bonus(10);
A.Res();
TQ B(A);
B.Bonus();
B.Res();
}
#include <iostream.h>
struct PLAY
{ int Score, Bonus;};
void Calculate(PLAY &P, int N=10)
{
P.Score++;P.Bonus+=N;
}
void main()
{
PLAY PL={10,15};
Calculate(PL,5);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
Calculate(PL);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
Calculate(PL,15);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
}
10. Obtain the output of the following C++ program code:
#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 P1={10,20,30},P2,P3;
++P1.Height;
Occupies(P1);
P3=P1;
++P3.Length;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Height+=50;
P2.Length--;
Occupies(P2);
}
11. Obtain the output of the following C++ program code:
#include<iostream.h>
void Indirect(int Temp=25)
{ for(int I=15;I<=Temp;I+=5)
cout<<I<<' ';
cout<<endl;
}
void Direct(int &Num)
{ Num+=10;
Indirect(Num);
}
void main( )
{ int Number=10;
Direct(Number);
Indirect( );
cout<<"Number ="<<Number<<endl;
}
12. Obtain the output of the following C++ program code:
#include<iostream.h>
#include<ctype.h>
void main( )
{ char STR[]="WhatOutPut!";
for(int I=0; STR[I]!='\0';I++)
{ if(!isalpha(STR[I]))
STR[I]='*';
else if(isupper(STR[I]))
STR[I]=STR[I]+1;
else
STR[I] =STR[I+1];
}
cout<<STR;}
18.
Assuming the class TOYS as declared below, write a functions in C++ to
readthe objects of TOYS from binary file TOYS.DAT and display the
detailsof those TOYS, which are meant for children of Age Range 5to 8".
class TOYS
{
int ToyCode;
char ToyName [10] ;
char *AgeRange;
public :
void Enter ()
{
cin>>ToyCode;
gets (ToyName);
gets (AgeRange);}
void Display()
{
cout <<Toycode<<:<<ToyName<<endl;
cout<<AgeRange<<endl ;
)
Char *WhatAge () {return AgeRange; }
};
19.
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 gamename isBasket Ball.
20.
class book
{
int book_no;
char book_name[20];
float price;
public:
void enter_book_Details( )
{
cin>> book_no>> price; gets(book_name);}
void show_book_Details( );
int checkbookno(int bookno)
{
If(book_no==bookno)
Return(0);
Else
Return (1);
};
Write a function deleteBook() in C++ that deletes the required book
record from the binary file BOOKS.DAT based on book_no.
class mobile
{
char number[10]; int calls;
public:
void Enter() { gets(number);cin>>calls;}
void Billing(){cout<<number<<#<<calls<<endl;
24. Write a function in C++ to search for a tablet from a binary file
tablet.dat containing objects of class tablet (defined below). The
user should enter the ModelNo and function should search and display the
detail of tablet.
class tablet
{
long ModelNo; float RAM, HD;
char Details[20];
public:
void Enter(){ cin>>ModelNo>>RAM>>HD; gets(Details);}
void Disp(){ cout<<ModelNo<<RAM<<HD<<Details<<endl;}
long Model(){ return ModelNo;}
};
25. Write a function in C++ to read and display the detail of all the
members whose membership type is L or M from a binary file
CLUB.DAT. Assume the binary file CLUB.DAT contains objects of class
CLUB, which is defined as follows:
class CLUB
{
int Mno; //Member Number
char Mname [20]; //Member Name
char Type; //Member Type: L Life Member M Monthly Member
public:
void Register (); //Function to enter the content
void Display (); // Function to display all data members
char WhatType () {return Type;).
};
26.
Write a function in C++ to search anddisplay details of all flights,
whose destinationis Mumbai from a binary fileFLIGHT.DAT. Assuming
the binary file iscontaining the objects of the following class.
class FLIGHT
{ int Fno; //Flight Number
char From[20]; //Flight Starting Point
char To[20]; //Flight Destination
public:
void Enter( )
{
cin>>Fno;
gets(From);
gets(To);
}
char* GetFrom( )
{return From;}
char* GetTo( )
{return To;}
void Display( )
{
cout<<Fno<<:<<From<<:<<To<<endl;
}
};
class TRAIN
{ int Tno; // Train Number
charFrom[20]; // Train Starting Point
charTo [20]; // Train Destination
public:
char* GetFrom( )
{return From;}
char* GetTo( )
{return To;}
void Input( )
{cin>>Tno;gets(From);gets(To);
}
void Show( )
{
cout<<Tno<<:<<From<<:<<To<<endl;
}
};
4 Marks Questions
Public Members
Enter()// A function to allow user to enter valuesPno,category and call
//FixLocation() function
SeeAll()// A function to display all the data members
For Material other than COTTON the above mentioned Price gets reduced
by 25%.
Public Members:
A constructor to assign initial values of Code, Type and Material with
the word NOT ASSIGNED and Size and Price with 0.
A function Enter () to input the values of the data members Code, Type,
Size and Material and invoke the CalcPrice() function.
A function Show () which displays the content of all the data members
for a Clothing.
12. 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
A function AssignFare( ) which calculates and assigns the value of the
data member TotalFare as follows :
For each Adult
Fare (Rs) 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 * 150i.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.
13.
Define a class Candidate in C++ with following description:
Private Members
_ A data member RNo (Registration Number) of type long
_ A data member Name of type string
_ A data member Score of type float
_ A data member Remarks of type string
A member function AssignRem( ) to assign Remarks as per the Score
obtained by a candidate. Score range and the respective Remarks are
shown as follows:
Score Remarks
>=50 Selected
less than 50 Not selected
Public Members
_ A function ENTER ( ) to allow user to enter values for RNo, Name,
Score & call function AssignRem( ) to assign the remarks.
_ A function DISPLAY ( ) to allow user to view the content of all the
datamembers.
15.
Define a class Applicant in C++ with following description:
Private Members
A data member ANo ( Admission Number) of type long
A data member Name of type string
A data member Agg(Aggregate Marks) of type float
A data member Grade of type char
A member function GradeMe( ) to find the Grade as per the Aggregate Marks obtained by a
student. Equivalent Aggregate marks range and the respective Grades are shown as follows
Aggregate Marks Grade
> = 80 A
Less than 80 and > = 65 B
Less than 65 and > = 50 C
Less than 50 D
Public Members
o A function Enter( ) to allow user to enter values for ANo, Name, Agg & call function GradeMe( )
to find the Grade
o A function Result ( ) to allow user to view the content of all the data members.
16.
Define a class ORDER in C++ with following description:
Private Members
ICode of type integer (Item Code)
Item of type string (Item Name)
Price of type float (Price of each item)
Qty of type integer (Quantity in stock)
Discount of type float (Discount percentage on the item)
A member function FindDisc() to calculate discount percentage as per the following rule:
If Qty < =50 Discount is 0
If 50 < Qty < =100 Discount is 5
If Qty > 100 Discount is 10
Public Members
A function Buy () to allow user to enter values for ICode, Item, Price, Qty and call function
FindDisc() to calculate Discount.
A Function ShowAll() to allow user to view the content of all the data members.
19.
Define a class named Tour in C++ with following description?
Private members:
tcode integer (Ranges 6 - 10)
adults, children, distance integer
totalfare float
AssignFare( ) A function which calculates and assign the value to data member
totalfare as follows:-
- For adults Fare Distance
Rs. 500 >=1500
And fare get reduced by 25% if distance is < 1500.
- For Children
For every child a fixed Rs. 50 is charged as fare.
Public members:
A constructor which initialized initialize all data members with 0
Function EnterTour() to input the values of the data members tcode, adults, children and call to
AssignFare function.
Function ShowTour() to print all the details of object of Travel type.
20.
Define a class named Admission in C++ with following description? 4
Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
A constructor which initialized admno with 10, name with NULL, cls with 0 & fees with 0
Function getdata() to read the object of Admission type.
Function putdata() to print the details of object of admission type.
Function draw_nos() to generate the admission no. randomly to match with admno and display the detail of object.
21. Answer the question (i) to (iv) based on the following:
class Exterior
{
int OrderId
char Address[20]
protected:
float Advance
public:
Exterior()
void Book()
void View()
}
class Paint:public Exterior
{
int WallArea,ColorCode
protected:
char Type
public:
Paint()
void PBook()
void PView()
}
class Bill:public Paint
{
float Charges
void Calculate()
public:
Bill()
void Billing()
void Print()
}
(i) Which type of Inheritance out of the following is illustrated
in the above example?
Single Level Inheritance
Multi Level Inheritance
Multiple Inheritance
(ii) Write the names of all the data members, which are directly
accessible from the member functions of class Paint.
(iii) Write the names of all the member functions, whichare directly
accessible from an object of class Bill.
iv) What will be the order of execution of the constructors, whenan
object of class Bill is declared?
22. Answer the questions (i) to (iv) based on the following:
class Interior { int OrderId; char Address[20];
protected: float Advance;
public: Interior(); void Book(); void View();
};
class Painting:public Interior
{ int WallArea,ColorCode;
protected:
char Type; public:
Painting();
void PBook();
void PView(); };
class Billing : public Painting
{ float Charges;
void Calculate();
public:
Billing();
void Bill();
void BillPrint(); };
(i) Which type of Inheritance out of the following is illustrated in the above example ?
Single Level Inheritance
Multi Level Inheritance
Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions
of class Painting.
(iii) Write the names of all the member functions, which are directly accessible from an object of class
Billing.
(iv) What will be the order of execution of the constructors, when an object of class Billing is declared ?
23. Consider the following C++ code and answer the questions from (i) to (iv) :
class University { long Id; char City[20];
protected: char Country[20]; public: University(); void Register( ); void
Display( ); };
class Department: private University { long DCode[10];char HOD[20];
protected:
double Budget; public: Department();
void Enter();
void Show(); };
class Student: public Department { long RollNo; char Name[20];
public:
Student();
void Enroll();
void View(); };
(i) Which type of Inheritance is shown in the above example ?
(ii) Write the names of those member functions, which are directly accessed from the objects of class
Student.
(iii) Write the names of those data members, which can be directly accessible from the member
functions of class Student.
(iv) Is it possible to directly call function Display( ) of class University from an object of class
Department ? (Answer as Yes or No).
24. Consider the following C++ code and answer the questions from (i)
to (iv):
class Campus
{
long Id;
char City[20];
protected:
char Country [2O] ;
public :
Campus();
void Register();
void Display() ;
);
char Section;
protected :
char SName[20];
public:
Student() ;
void Stentry();
void Stdisplay();
};
class Score: private Student
{
float Marks[S];
protected:
char Grade[S];
public:
Score();
voidSentry();
voidSdisplay();
};
classReport:publicScore
{ floatTotal,Avg;
public:
charOverallGrade, Remarks[20];
Report();
voidREvaluate();
voidRPrint();
};
(ii) Write the names ofthose data members, which can be directly accessed
fromtheobjects ofclassReport.
(iii) Write the names of those member functions, which can be directly
accessed fromtheobjectsofclassReport.
(iv) Write the names of those data members, which can bedirectly accessed
fromtheSentryt()function ofclassScore.
26. Consider the following c++ code and answer the questions from (i) to (iv):
class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal();
void pentry();
void Pdisplay();
};
class Marks: private Personal
{ float M[5];
protected:
char Grade[5];
public:
Marks(); void Mentry (); void Mdisplay();
};
class Result: public Marks
{ float Total, Agg;
public:
char FinalGrade, Comments[20];
Result();
void Rcalculate();
void Rdisplay();
};
(ii) Write the names ofthose data members, which can be directly accessed fromtheobjects
ofclassResult.
(iii) Write the names of those member functions, which can be directly accessed
fromtheobjectsofclassResult.
(iv) Write the names of those data members, which can bedirectly accessed fromtheMentryt()
function ofclassMarks.
27. Answer the questions (i) to (iv)based onthe following: .
classCOMPANY
{ charLocation[20];
double Budget,Income;
protected:
voidAccounts();
public: COMPANY();
voidRegister();
voidShow();
};
classFACTORY: public COMPANY
{ charLocation[20) ;
intWorkers;
protected:
double Salary;
voidComputer();
public:
FACTORY();
voidEnter();
voidShow();
};
classSHOP:private COMPANY
{ charLocation[20]; floatArea; double Sale;
public: SHOP();
voidInput();
voidOutput();
};
32. Answer the questions (i) to (iv) based on the following code:
class Dolls
{ char DCode[5];
protected:
float Price ;
void CalcPrice(float);
public:
Dolls( );
void DInput( );
void DShow( );
};
class SoftDolls: public Dolls
{ char SDName[20];
float Weight;
public:
SoftDolls( );
void SDInput( );
void SDShow( );
};
class ElectronicDolls: public Dolls
{ char EDName[20];
char BatteryType[10];
int Battieries;
public:
ElectronicDolls ( );
void EDInput( );
void EDShow( );
};
(i) Which type of Inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class
ElectronicDolls?
(iii) Write name of all the data members accessible from member
functions of the class SoftDolls.
(iv) Write name of all the member functions accessible by an object.
33. consider the following class declaration and answer the question
below :
class university
{ int noc;
protected;
char uname[25];
public:
university();
char state[25];
void enterdata();
void displaydata();
};
class college : public university
{ int nod;
char cname[25];
protected:
void affiliation();
public:
college();
void enrol(int ,int);
void show();
};
class department : public college
{ char dname[25];
int nof;
public:
department();
void display();
void input();
};
(i) Which classs constructor will be called first at the time of
declaration of an object of class department?
(ii) How many bytes does an object belonging to class department
require?
(iii)Name the member function(s), which are accessed from the object of
class department.
(iv) Name the data member, which are accessible from the object of class
college.
34. Answer the questions(i) to (iv) based on the following :
class cloth
{ char category[5];
char description[25];
protected:
float price;
public:
void Entercloth( );
void dispcloth( );
};
36. Consider the following declarations and answer the questions given
below :
class living_being
{ char name[20];
protected:
int jaws;
public:
void inputdata(char, int);
void outputdata();
}
class animal : protected living_being
{ int tail;
protected:
int legs;
public:
void readdata(int, int);
void writedata();
};
class cow : private animal
{ char horn_size;
public:
void fetchdata(char);
void displaydata();
};
(i) Name the base class and derived class of the class animal.
(ii) Name the data member(s) that can be accessed from function displaydata.
(iii) Name the data member(s) that can be accessed by an object of cow class.
(iv) Is the member function outputdata accessible to the objects of animal class.
37. Consider the following and answer the questions given below:
class MNC
{
char Cname[25]; // Company name
protected :
char Hoffice[25]; // Head office
public :
MNC( );
char Country[25];
void EnterDate( );
void DisplayData( );
};
class Branch : public MNC
{
long NOE; // Number of employees
char Ctry[25]; // Country
protected:
void Association( );
public :
Branch( );
void Add( );
void Show( );
};
class Outlet : public Branch
{
char State[25];
public :
Outlet();
void Enter();
void Output();
};
(i) Which classs constructor will be called first at the time of
declaration of an object of class Outlet?
(ii) How many bytes an object belonging to class Outlet require ?
(iii) Name the member function(s), which are accessed from the
object(s) of class Outlet.
(iv) Name the data member(s), which are accessible from the object(s) of
class Branch.
SOLUTION: OBJECT ORIENTED PROGRAMMING IN C++
45. Statement 1
File.seekp(File.tellp( )-sizeof(C));
Or
File.seekp(Record*sizeof(C));
Statement 2
File.write((char*)&C,sizeof(C));
Or
File.write((char*)&C,sizeof(Candidate));
46. Statement 1
File.seekp(Position)
Statement 2
File.write((char*)&CL.sizeof(CL)
47. Statement 1 - File.seekp(Success);
Statement 2 - File.write((char*) &S, sizeof(S)
48. Statement 1
File.seekp(Position);
OR
File. seekp (-sizeof (L), ios::cur);
Statement 2
File.write((char*)&L, sizeof(L));
OR
File.write((char*)&L,sizeof(Library));
49. Statement 1
File.seekp(File.tellp( )-sizeof(L));
or
File.seekp(Rec*sizeof(L));
Statement 2
File.write((char*)&L,sizeof(L));
or
File.write((char*)&L,sizeof(Labrecord));
50. File.seekp((Recordsread-1)*sizeof(OM));
OR
File.seekp(Recordsread*sizeof(OM));
OR
File.seekp(-l*sizeof(OM),ios::curr);
OR
File.seekp(file.tellg()-sizeof(OM));
Answers to 2 Mark Questions
1. x is a character constant and its size is 1 character whereas x is a string constant and its size is 2
character because compiler automatically assign a null character (\0) at the end of a string constant i.e.
\0.
2. A reference variable is an alias name for a previously defined variable. The usage of it is that the
same data object can be referred to by two names and these names can be usually interchangeably.
3. 50
4. The break statement provides immediate termination of the entire loop body whereas continue
statement terminates forces the next iteration of the loop to take place, skipping any code following
continue statement in the loop body.
5. The default statement gets executed when no match is found again the values specified in the
switch-case statement.
6. In the getche() function, it directly reads a character from the console as soon as it is typed without
waiting for the enter key to be pressed, whereas getch() reads a character from keyboard exactly in the
same manner but does not show it on the screen.
7. Provided that function parameter is a const reference, compilers generates temporary variable in
following 2 ways:
(a) The actual argument is the correct type, but isnt Lvalue
double Cube(const double & num) {
num = num * num * num;
return num;
}
double temp = 2.0;
double value = cube(3.0 + temp); //argument is an expression and not a Lvalue;
(b) The actual argument is of the wrong type, but of a type that can be converted to the correct type
long temp = 3L;
Double value = cuberoot (temp); //long to double conversion
8. As we know the last character of the string is NULL. The puts() convert NULL value into the newline
character while cout does not do so. For example, If the input is Rahul Sharma.
#include<iostream.h>
main() {
char name[20];
gets(name);
cout << The name is;
cout <<name;
cout<< End of the output;
getch(); }
The output is :
The name is Rahul Sharma End of the output
Now consider the program using puts()
#include<iostream.h>
main() {
char name[20]; gets(name);
cout<< The name is; puts(name);
cout<< End of the output;}
The output is:
The name is Rahul Sharma
End of the output
9. Difference between Type Casting and Automatic type conversion
Type Casting Automatic Type Conversion
It is an explicit process of conversion of a data It is an implicit process of conversion of a data fro
from one type to another. one data type to another. It is performed by the
(It is performed by the programmer.) compiler. It is also called as type promotion.
For example For example:
int A=1, B=2; int N = 65;
float C = (float)A/B; //Type Casting char C = N; // Automatic type conversion
cout<<C; cout<<C;
Output: Output:
0.5 A
10. Local Variables: Local variables are those variables which are declared within a function or a
compound statement and these variables can only be used within that function/scope.
Global Variables: Global variables are those variables which are not declared within any function or scope.
So, these variables can be accessed by any function of the program.
Example:
#include<iostream.h>
#include<conio.h.>
int G; // Global variable declared
void Fun ( )
{i
nt L=25;// Local variable of function Fun ( ) assigned value 25
G=5; // Global Variable is accessed and assigned value 5
cout<<G<<endl; //Value of global variable is displayed as 5
cout<<L<<endl; // Value of local variable is displayed as 25
}
void main ( )
{
Fun ( ) ; // Function call
G = G + 5; // Global variable is incremented by 5
cout<<G<<endl; // Global variable is displayed as 10
}
11. C++ allows you to define explicitly new data type names by using the keyword typedef. Using
typedef does not actually create a new data class, rather it defines a new name for an existing type.
The syntax of the typedef statement is :
typedef type name;
Where type is any C++ data type and name is the new name for this type. This defines another name for
the standard type of C++. For example, you could create a new name for float values by using the following
statement:
typedef float amount;
amount x=10.5; // amount is alternative name to float
12. #define preprocessor directive is used to define a macro with some value/expression, which is
substituted during compilation of program. Unlike variable, it does not occupy memory.
e.g.
#define Max 10
void main( )
{
Int arr[Max];
}
constIt is used in declaration of a variable, it occupy memory to store a constant value, which once
initialized cannot be changed.
e.g.
cons tint x = 10;
13.
Actual Parameter Formal Parameter
Parameters provided at the time of function Parameters provided at the time of function
calling are called actual parameters. definition are called formal parameters.
These parameters are contain actual values. These parameters are simple variable declarations,i.e.
they do not contain actual values.
e.g.
#include <iostream.h>
void Calc(int T) //T is formal parameter
{
cout<<5*T;
}
void main()
{ int A=45;
Calc(A);//A is actual parameter
}
14. Call by value: The formal parameter makes a copy of actual parameter. It does not make the
changes In actual parameter If the changes are done In formal parameters.
Call by reference: The formal parameter is an alias of actual parameter. The changes made In the formal
parameter are reflected In actual parameter. It is preceded by &.void Calculator (int A,int & B )
{
A++;
a+=A;
}
Here A is called by value and B is called by reference.
15. A default parameter is a function parameter that has a default value provided to it. If the user does
notsupply a value for this parameter, the default value will be used. If the user supply a value for the default
parameter, the user supplied value is used.
Consider the following program:
void PrintValues ( int nValue1,
int nValue2=10)
{
cout<< 1st value:<<nValue1<<endl;
cout<< 2st value:<<nValue2<<endl;
}
int main ( )
{
PrintValues(1);//nValue2 will use default parameter of 10
PrintValues(1);//nValue(3,4);//override default value for nValue2
return 0;}
16. The function prototype serve to ensure that calls to the function are made with proper number and
types of arguments. In the case of function overloading, the different prototype serve to distinguish which
version of the function to call. The computer will complain with an error, if no function prototype is found for
any particular call to function.
e.g.
#include <iostream.h>
int square (int);//function prototype
int main( )
{
for( int x = 1;x<=10;x++)
cout<<square( x )<< ;
cout<<endl;
return 0;
}
//Function definition
int square(int y)
{
return y*y;
}
17. The classes are the manufacturing units of the objects of their type, i.e. It is the class that can be
used to create an object. Since encapsulation and also abstraction are done at the class level, it is the class
that can be model the objects from the real world problem.
18. Polymorphism means processing of data or messages in more than one form. C++ implements
polymorphism through overloaded functions and overloaded operators.
e.g.
float computer(float a)
{
return a*a;
}
float computer(float a, float b)
{
return (a*b);
}
19. The wrapping up of data and function into a single unit is called data encapsulation. That single unit
is known as class.
e.g.
class person
{
char name[ 30 ];
int age;
public:
void getdata(void);
void display(void);
};
The above program implements data hiding as data cant be accessed directly from outside.
20. Data hiding is a property, where internal data structure of an object is hidden from the outside
world. Data hiding helps to secure the data. It is implemented with private and protected keywords.
e.g.
class item
{
private:
int item_no:
float item_cost;
public;
void getdata( );
void putdata( );
}:
21. The wrapping up of data and function into a single unit is called data encapsulation. That single unit
is known as class.
e.g.
class person
{
char name[ 30 ];
int age;
public:
void getdata(void);
void display(void);
};
The above program implements data hiding as data cant be accessed directly from outside.
22. Abstraction refers to the representation of only the essential features of the real world object in the
program object. This process does not include the background details and explanations. This concept of
abstraction is used in classes, whereas data encapsulation is the most significant characteristic of the class.
By this term, we mean the wrapping up of data and function which operate on the data, into a single unit
called the class. This encapsulation prevents free access to the data within an object.
23. In the event driven programming, the user indicates the order of program execution not the
programmer. Instead of, the program driving the user drives the program. Programming, the code that
responds to the event is called event driven programming.
24. When several functions have same name but performing different tasks, then it is known as
function overloading. The definitions of these functions are differentiable by the number or types of their
arguments.
e.g.
float compute(float radius)
{
return(3.14*radius*radius);
}
float compute(float l, float b)
{
return(l*b);
}
float compute(int b, float h)
{
return(0.5*b*h);
}
25. The process of making an operator to exhibit or show different behavior in different situations is
called as operator overloading.
e.g. consider the operation of (+) operator, Operation is sum, if operands are integer type and the
operation is concatenation if operands are strings.
26. Object oriented programming focus on objects. It gives the benefits of security of data, reusability
of previously created functions. It is based on the principle of data hiding, abstraction, inheritance and
polymorphism. But procedural programming emphasizes on doing things. It revolves around functions and
execution of these functions.
27.
Object Oriented Programming Procedural Programming
Emphasis on data Emphasis on doing things (function)
Follow bottom up approach in program Follow top-down approach in program design
design.
Concept of Data hiding prevents accidental Due to presence of global variables, there is a
change in the data. possibility of accidental change in data.
28.
Syntax error - The errors which are traced by the compiler during compilation, due to wrong grammar for
the language used in the program, are called syntax errors.
For example, cin<<a; // instead of extraction operator insertion operator is used.
Run time Error - The errors encountered during execution of the program, due to unexpected input or
output are called run-time error.
For example - a=n/0; // division by zero
Logical Error - These errors are encountered when the program does not give the desired output, due to
wrong logic of the program.
For example : remainder = a+b // instead of using % operator + operator is used.
29. While is an Entry Controlled Loop, the body of the loop may not execute even once if the test
expression evaluates to be false the first time, whereas in do..while, the loop is executed at least once
whether the condition holds true the first time or not.
30. A class binds together data and its associated function under one unit thereby enforcing
encapsulation. The private and protected member remain hidden from outside world. Thus a class enforces
data hiding. The outside world is given only the essential information through public members, thereby
enforcing abstraction.
31. These characters are interpreted at run time.Represented by backslash(\) followed by a
character.Two characters together in a escape sequence are treated as single character.
e.g. \n Newline
\t Horizontal tab
32. In C++ basic data types (except void ) can be modified according our needs using certain keyword
known as type modifiers.e.g. signed, unsigned and long etc.
33. Abstract Class: A class with no instances (no objects) is known as abstract class.
Concrete class: A class having objects is known as concrete class.
34. It is a member function having same name as its class and which is used to initialize the objects of that
class type with a legal initial value. Constructor is automatically called when object is created.
class Exam
{ int Marks; char Subject[20];
public: Exam () //constructor for class Exam
{ Marks = 0;
strcpy (Subject,Computer); }
};
35. Default Constructor-: A constructor that accepts no parameters is known as default constructor. If
no constructor is defined then the compiler supplies a default constructor.
student :: student()
{ rollno=0; }
Parameterized Constructor -: A constructor that receives arguments/parameters, is called parameterized
constructor.
student :: student(int r)
{ rollno=r; }
36.
Constructor Destructor
Its name is same as the class name Its name is same as the class name preceded
by the tilde(~) sign.
Called automatically whenever object is Called automatically whenever object goes
created. out of scope.
e.g. class Flight
{ public: Flight(); // constructor for class Flight
~ Fight(); // Destructor for class Flight
};
37. Copy Constructor-: A constructor that initializes an object using values of another object passed to it as
parameter, is called copy constructor. It creates the copy of the passed object.
class Sample
{int i,j;
public:
Sample (int a, int b) //Constructor
{i = a;j = b;}
Sample (Sample &s) //Copy Constructor
{i=s.i;j=s.j;
cout<<Copy constructorWorking\n;
}
void print( )
{
cout<<i<<\t<<j<<\n;
}
};
void main( )
{
Sample S1(4,9); //S1 initialized first constructor used
Sample S2(S1); //S1 copied to S2. Copy constructor called.
Sample S3=S1; //S1 coped to S3. Copy constructor called again.
-----
-----
}
38.
a. Constructor functions are invoked automatically when the objects are created.
b. No return type (not even void) can be specified for a constructor.
c. They cannot be inherited, though a derived class can call the base class constructor.
d. A constructor may not be static.
e. It is not possible to take the address of a constructor.
39.
a. Destructor functions are invoked automatically when the objects are destroyed.
b. No argument can be provided to a destructor, neither does it return any value.
c. They cannot be inherited.
d. A destructor may not be static.
e. It is not possible to take the address of a destructor.
40.
Constructor Overloading:
The constructor of a class may also be overloaded so that even with different numberand types of initial
values, an object may still be initialized.
Default Arguments Versus Overloading:
Using default arguments gives the appearance of overloading, because the function may be
called with an optional number of arguments.
e.g:
Prototype :
float amount (float principal, int time=2, float rate=0.08);
Can be called as
Amount(2000.0,4,0.10);
Amount(3520.5,3);
Amount(5500.0);
41. A text file store information in ASCII characters. In text files, each line of text is terminated, with a
special character known as EOL character.
A binary file store information in the same format in which the information is held in memory. In binary
file, there is no delimeter for a line.
42. A stream is a sequence of byte.
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.
43. get() does not extract the delimiter newline character from input stream.
On the other hand getline() does extract the delimiter newline character from the input stream so
that the stream is empty after getline() is over.
44. The ios::out is the default mode of ofstream. With the mode of the file does not exist, it gets
created but if the file exists then its existing contents get deleted.
The ios::app is output mode of ofstream. With the mode of the file does not exist, it gets created but if the
file exists then its existing contents are retained and new information is appended to it.
45.
Pointer is an address of a memory location. A variable, which holds an address of a memory location, is
known as a Pointer variable (or Simply Pointer). For example int *P;
46. Protected members will be inherited into the derived class (they are accessible from the derived
class). But Private members cannot be accessed from the derived class.
e.g. class S { private : int x;
protected : int y;
public :
void show() { cout<<x<<y;}
};
class S1 : public S
{
private: int z;
public :
void display() { cout<<x <<y<<z;}
// here y and z can be accessed but x cannot be as it is private member of S
};
(Remember that the memory will be reserved for private as well as protected members for the derived class
object)
47. Multilevel Inheritance: When a subclass inherits from a class that itself inherits from another class,
it is known as multilevel inheritance.
e.g: (for Multi Level Inheritance)
class X
{ ------ }
class Y:public class X
{ ----- }
class Z:protected Y
{
-----
-----
}
Multiple Inheritance: When a sub class inherits from multiple base classes, it is known as multiple
inheritance.
eg: (for Multiple Inheritance)
class X
{
-----
------
}
class Y
{
-----
-----
}
class Z:public X, protected Y
{
-----
-----
}
48.
Public visibility Protected visibility
The public derivation means that the derived class can The protected derivation means that the derived
access the public and protected members of the base class can access the public and private members
class but not the private members of the base class. of the baseclass protectedly.
With publicly derived class, the public members of the With protectedly derived class, the public and
base class become the public members of the derived protected members of the base class become
class, and the protected members of the base class protected members of the derived class.
become the protected members of the derived class.
Example: Example:
class super class super
{ private: { private:
int x; void get(); int x; void get();
public: public:
int y; void put(); int y; void put();
protected: protected:
int z; void disp(); int z; void disp();
}; };
class sub:public super class sub:protected super
{ private: { private:
int a; void init(); int a; void init();
public: public:
int b; void readit(); int b; void readit();
protected: protected:
int c; void writeit(); int c; void writeit();
}; };
49. In derivation of class first the base class constructor is invoked, followed by the derived class constructor,
whereas in nested classes constructors of all the member objects are called before the constructors of the object
enclosing other objects.
50.
Constructor Normal Function
1. Constructor has same name as class name. 1. A normal function can have any legal name but
not class name.
2. Constructor cannot have any return type value 2. A function should have any return type value.
not even void.
3. Constructor is automatically called. 3. A function is explicitly called.
4. Constructor cannot be static. 4. A Function can be static.
51.
#defineMax70.0 //Error 1,2,3
void main() //Error 4
{
int Speed //Error 5
char Stop=N
cin>>Speed
if (Speed>Max) //Error 6
Stop=Y
cout<<Stop<<endl //Error 7
}
52.
const float Max=70.0; //error1
void main() // error2
{
int Speed;
char Stop='N';
cin>>Speed; // error3
if (Speed>Max)
Stop='Y';
cout<<Stop<<endl; // error4
}
53.
#include<iostream.h>
void main( )
{ void Jumpto(int, int x=20); // prototype missing with default value
int First = 10, Second = 20; //data type missing
Jumpto(First, Second); //comma instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2) // dafault value redeclared
{ N1=N1+N2;
cout<<N1<<N2; // cout and << operator required
}
54.
#include<iostream.h>
const int Max=10; // constant must be initialized
void main()
{ int Numbers[Max]= {20,50,10,30,40}; // expression syntax error
for(int Loc=Max-1;Loc>=10;Loc--) // Loc to be declared
cout<<Numbers[Loc]; // << operator required instead of >>
}
55.
#include<iostream.h>
#include<stdio.h> // error1
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost; // error2
}M;
gets(M.movie_name); // error3
cin>>(M.movie_type); // error4
}
56.
#include<iostream.h>
void main()
{
int X[]={60, 50, 30, 40},Y,Count=4; // error 1
cin>>Y;
for(int I=Count-1;I>=0;I--) // error 2,3
switch(I)
{ case 0:
case 2:cout<<Y*X[I]<<endl;break;
case 1: // error 4
case 3:cout<<(Y+X[I]);break; // error 5
}
}
57.
#include<iostream.h>
void main(){
int P[]={90, 10, 24, 15},Q,Number=4; //error 1
Q=9;
for(int I=Number-1;I>=0;I--) // error 2
switch(I)
{ case 0:
case 1 : // error 3
case 2:cout<<P[I]*Q<<endl; // error 4
break;
case 3:cout<<(P[I]+Q);
}
} //error 5
58.
#include<iostream.h>
void Assign(int Default1,int Default2=30);
void main()
{
int Present=25,Past=35;
Assign(Present,Past);
Assign(Past);
}
void Assign(int Default1,int Default2)
{
Default1=Default1+Default2;
cout<<Default1<<Default2;
}
59.
#include<iostream.h>
void Callme (int Arg1,int Arg2=20);
void main(){
intOne=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme( intArg1,int Arg2)
{
Arg1=Arg1+Arg2;
cout<<Arg1<<Arg2;
}
60.
#include<iostream.h>
#include<string.h>
typedef charString[80];
void main(){
String S="Peace";
int L=strlen(S);
cout<<S<<"has"<<L<<"characters"<<endl;
}
61.
Programming Paradigm: A Programming Paradigm defines the methodology of
designing and implementing programs using the key features and building
blocks of a programming language.
Following are the different programming paradigms:
(i) Procedural Programming
(ii) Object Based Programming
(iii) Object Oriented Programming
62.
Reusability of classes is implemented through inheritance in C++.
Inheritance is implemented by specifying the name
of the (base) class from which the class being defined (the derived
class) has to inherit from.
It is donewith the following syntax:
class<derived class name> : <base class name>
{
<- derived class own features.
}
63.
OOP stands for Object Oriented Programming. In, Object-Oriented
Programming (OOP), the program is organizedaround the data being
operated upon rather than the operations performed. The basic idea
behindOOP is tocombine both, data and its functions that operate on the
data into a single unit called object.
Following are the basicOOP concepts:
1. Data Abstraction 2. Data Encapsulation 3. Modularity
4. Inheritance 5. Polymorphism
64.
#include<iostream.h>
#include<string.h>
typedef char Text [80];
void main ( )
{
Text T= "Indian";
int Count=str1en(T);
cout<<T<<"has"<<Count<<"cbaracters"<<end1;
}
65.
typedef char STRING[50]; // error 1
void main()
{
STRING City; // error 2
gets(City);
cout<<City[0]<<'\t'<<City[2]; // error 3
cout<<City<<endl; // error 4
}
66.
(iii) and (iv) Minimum value of NUM = 2 and Maximum value of NUM = 4
67.
(i) 50 # 51 # 52 # 53 # 54 # 55 #
Least value 50
Highest value 53
68.
Correct answer is 9GOLD*9GOLD*8SILVER*
Minimum value of Guess is 0 and Maximum is 2
69
(iii) 2,
Minimum value of A is 2 and Maximum is 3
70
(ii) #2#3#4 because Minimum value of A=2 and Maximum is 4 and i is increasing (i++)
71.
(iii) 0,2,4, because minimum value of A=2 and Maximum value is 5
72.
(iv) 20^ because Minimum value of A=20 and Maximum value is 23
73.
(iii) 1 2 3 4 5 6 because minimum value of rn is 5 and maximum is 8
74.
(iv) 20#250# because Start has minimum value as 2 and maxim as 3
75
(iii) 100#50#200# because minimum value of Tanker is 2 and Maximum value is 3
76.
Error: Undefined symbol y in function definition, if Y is declared with
some value then output will be:
22,4
22,6
77.
10, 8
20, 8
78.
New Text:I@PPT@RRW
79.
1AJANTA
5JANTA
80.
30%41
52%60
40%25
81.
New Text : PPW%RRllN%
82.
NEW TEXT :@@e@ccddIIe
83.
Line15&8
Line211&9
Line16&9
Line212&10
84.
Output: 2
85.
Output:
5 9
9 7
7 7
7 9
86.
1
12
87.
a=1b=2
c=3
88.
30,100,1
10,100,10
120,1000,0
10
89.
HuqTlOu
90. teRmttoe
91.
1SARGAM
9ARGAM
92.
vR.zGoOD
R.zGOOD
.zgOOD
ZgOOD
93.
30
34.5
64.5
94.
90Bhakti
70akti
95.
130,b
96.
Banka
Bank
Ban
Ba
B
97.
2@4@
4#8#16#10#
98.
Queen@11
Now@55
99.
4#6#
12@18@
100.
D
i
101.
(i) T.Book(1234567,Ravi) //Line 1
T.Print() //Line 2
(ii)
Function 4
OR
~Traveller()
It is a Destructor function.
102.
(i) P.Book(1234567,Ravi) //Line 1
P.Print() //Line 2
(ii) Function 4
OR
~Passenger()
It is a Destructor function.
103.
(i) Function1 will be executed.
(ii) Health G(H)
104.
(i) Polymorphism (OR) Function Overloading (OR) Constructor Overloading
(ii) Destructor, invoked or called when Object goes out of a scope.
105.
(i) Option 1- Race T(30); is correct
(ii) Constructor overloading.
106.
(i) Function Overloading (Constructor overloading)
(ii) Exam A(10) and Exam B(Comp, 10)
107.
(i) Polymorphism (OR) Constructor Overloading (OR) Function Overloading.
(ii) Destructor. It is invoked as soon as the scope of the object gets over.
108.
Valid and invalid statements are
welcome obj (33, a9); valid
welcome obj1(50, 9); valid
welcome obj3(); invalid
obj1= welcome (45, T); valid
109.
(i) Function 1 is called as Destructor, It will automatically executed at the time of destruction of the
object of class TestMeOut.
(ii) Function 2 is called as constructor (Non-parameterized or default constructor) ,it will automatically
executed at the time of creation of the object of class TestMeOut.
110.
(i) Function overloading (here it is constructor overloading).
(ii) (let char name[20]; int X=30; strcpy(name, SCIENCE); are declared in the program)
Test A(name); //Will execute Funciton 2
Test B(name,X); //Will execute Function 4
111.
void SUCCESS()
{
int count=0
ifstream f("STORY.TXT")
char s[20]
while (!f.eof())
{
f>>s
if(strcmpi(s,STORY)==0)
count++
}
cout<<count
f.close()
}
112.
void TOWER()
{
int count=0
ifstream f("WRITEUP.TXT")
char s[20]
while (!f.eof())
{
f>>s
if (strcmpi(s,TOWER)==0)
count++
}
cout<<count
f.close()
}
113.
void EUCount()
{
ifstream fi("IMP.TXT")
char ch;
int CountE=0,CountU=0;
while(fi)
{
fi.get(ch);
if(ch=='e'||ch=='E') CountE++;
else if(ch=='u'||ch=='U') CountU++;
}
cout<<"E:"<<CountE<<endl;
cout<<"U:"<<CountU;
fi.close();
}
114.
void AECount()
{
ifstream fi("NOTES.TXT")
char ch;
int CountA=0,CountE=0;
while(fi)
{
fi.get(ch);
if(ch=='A'||ch=='a') CountA++;
else if(ch=='E'||ch=='E') CountE++;
}
cout<<"A:"<<CountA<<endl;
cout<<"E:"<<CountE;
fi.close();
}
115.
void CountYouMe()
{
ifstream Fil;
Fil.open("STORY.TXT",ios::in);
char Word [80];
int C1=0, C2=0;
while (!Fil.eof())
{
Fil>>Word;
if(strcmp(Word,"You")==0)
C1++;
else if (strcmp(Word,"Me") ==0)
C2++;
}
cout<<"Count for You:"<<C1<<endl;
cout<<"Count for Me:"<<C2<<endl;
fil.close();
}
116.
void TotalDigits()
{
ifstream chi(child.txt);
int c1=0;
char ch;
while(chi)
{ chi.get(ch);
if(ch>=0 && ch<=9) c1++;
}
cout<< no of total digits in file:=<<c1;
chi.close();
}
117.
void show()
{ ifstream fin(WORKER.DAT,ios::in|ios::binary);
WORKER W;
while(fin)
{ fin.read((char*)&W,sizeof(W));
if( W.GetWage()<300)
{ W.display();}
}
Fin.close();
}
118.
void SHOW()
{
ifstream File(UNO.TXT)
char str[80];
File.getline(str,80);
while(File)
{
if(str[0] = =D || str[0] = =M)
{ cout<<str<<endl; }
File.getline(str,80);
}
File.close(); //Ignore
}
119.
void COUNT ( )
{ifstream Fil; // ifstreamFil(ARTICLE.TXT");
Fil.open(ARTICLE.TXT);
char Word[80] ,Ch;
int Cl =0, C2 = 0, I=O;
while(Fil.get(Ch))
{ if (Ch! = ' ')
Word[I++] = Ch;
else
{
Word[I] = \0;
if (strcmp(Word,this)==0)
Cl++;
else if (strcmp(Word,these)==0)
C2++;
I=0;
}
} cout<<Count of -this- in file:"<<Cl;
cout<<Count of -these- in file:"<<C2;
Fil.close( );
}
120.
void WCount ()
{
Ifstream fil(POEM.TXT)
char word[80];
int WC=0;
while( !fil.eof())
{
if( (strcmp(word, to)==0 )|| (strcmp(word, the)==0))
WC++;
}
cout<< WC;
fil.close();
}
121.
int countalpha()
{ ifstream Fin(BOOK.txt);
char ch;
int count=0;
while(!Fin.eof())
{
Fin.get(ch);
if (islower(ch))
count++;
}
Fin.close();
return count;
}
122.
int countword()
{ ifstream Fin(BOOK.txt);
char ch[25];
int count=0;
while(!Fin.eof())
{
Fin>>ch;
if (isupper(ch[0]))
count++;
}
Fin.close();
return count;
}
123.
void BlanksCount( )
{
ifstream fin("PR.TXT",ios::in);
char ch;
int B=0;
if(!fin)
{ cout<<No words at all in the file.
So no blank spaces;
exit(0);
}
while(fin)
{
fin.get(ch);
if(ch= = )
B++;
}
cout<<"\nTotal number of Blank
Spaces in the file = "<<B;
Fin.close();
}
Answers to 3 Mark Questions
1.
Undefined symbol C in function main()
If error is removed then output will be:
a#0
d#0
D#0
2.
B#0
I#1
G#1
3.
A@1
0
A@2
75
A@3
120
4.
20#300#10#
6020@300@10@
6020$300$3000$
5.
1,5
1,15
1,25
6.
B++50&100%
B++50&105%
B++55&115%
7.
10,240
250,260,240
260,240
8.
7,17
7,17
6
9.
11:20
12:30
13:45
10.
Error: length is not member of Package in function main().
If length replaced with Length then output will be:
10x20x31
11x21x31
10x21x81
11.
15 20
15 20 25
Number=20
12.
XatOPtPQt!*
13.
16 24 6
6 34 16
18 22 28
14.
30%41
52%60
40%25
15.
void Economic()
{ ITEMS I
ifstream fin(ITEMS.DAT,ios::binary)
while (fin.read((char *)&I,sizeof(I)))
{
if(I.GetCost()<2500)
I.See()
}
fin.close() }
16.
void COSTLY()
{ GIFTS G
ifstream fin(GIFTS.DAT,ios::binary)
while (fin.read((char *)&G,sizeof(G)))
{
if(G.GetPrice()>2000)
G.View()
}
fin.close()
}
17.
void READGAMES()
{ GAMES obj;
ifstream infile("GAMES.DAT");
while(infile)
{
infile.read((char*)&obj,sizeof(obj));
if(strcmp(obj.AgeR(),"8 to 13")==0)
obj.Display();
}
infile.close();
}
18.
void READTOYS()
{ TOYS obj;
ifstream infile("TOYS.DAT");
while(infile)
{
infile.read((char*)&obj,sizeof(obj));
if(strcmp(obj.WhatAge(),"5 to 8")==0)
obj.Display();
}
infile.close();
}
19.
void CopyBasket( )
{ Game G;
ifstream fin;
fin.open(GAME.DAT,ios::binary);
ofstream fout;
fout.open(BASKET.DAT,ios::binary);
while(fin.read((char *)&G, Sizeof(G)))
{ if(strcmp(G.GameName,Basket Ball)= =0)
fout.write((char *)&G, sizeof(G));
}
20
void deleteBook(int bookNoToDelete)
{
ifstream fin;
ofstream fout;
book ob;
fin.open("BOOKS.DAT",ios::in|ios::bianry);
fout.open("temp.dat",ios::out|ios:binary);
if(!fin||!fout)
{
cout<<"File not opened.";
getch();
return;
}
while(fin.read((char*)&ob,sizeof(ob)))
{
if(ob.checkbookno(bookNoToDelete)==1)
fout.write((char*)&ob,sizeof(ob));
}
fin.close();
fout.close();
remove("BOOKS.DAT");
rename("temp.dat","BOOKS.DAT");
}
21.
void show()
{ ifstream fcin(VINTAGE.DAT,ios::in|ios::binary);
VINTAGE V;
float prc;
while ( fcin)
{ fcin.read((char*)&V, sizeof(V));
prc=V.ReturnPrice();
if( prc>=20000 & prc<=250000)
V.VIEW();
}fcin.close();
}
22.
void show()
{ ifstream fcin(NETBOOK.DAT,ios::in|ios::binary);
NETBOOK N;
float prc;
while ( fcin)
{ fcin.read((char*)&N, sizeof(N));
prc=N.ReturnPrice();
if( prc>=25000 & prc<=55000)
N.VIEW();
}fcin.close();
}
23.
void display()
{ mobile M;
ifstream fin(mobile.dat,ios::in|ios::binary);
fin.read((char*)&M, sizeof(M));
while(fin)
{ if(M.GetCalls()>1000) M.Billing();
fin.read((char*)&M, sizeof(M));
}fin.close();
}
24.
void Search()
{ tablet t;
long modeln; ifstream fin;
cout<<enter the model no. of tablet : ;
cin>>modeln;
fin.open(tablet.dat,ios::binary);
while(fin.read((char*)&t,sizeof(t))
{ if(t.Model()==modeln)
t.Disp();
}
fin.close();
}
25.
void DisplayDemo ()
{
CLUB CBJ;
ifstream fin;
fin.open (CLUB.DAT, ios::binary);
while ( fin.read (char*) &CBJ, sizeof(CBJ) )
{
if(CBJ.WhatType()==L || M )
CBJ.Display();
}
fin.close();
}
26.
void Read ( )
{
FLIGHT F;
ifstream fin;
fin.open(FLIGHT.DAT,ios::binary);
//OR ifstream fin (FLIGHT. DAT, ios: :binary) ;
while(fin.read((char*)&F,sizeof(F)))
{
if (strcmp(F. GetTo(),Mumbai))
F.Display( ) ;
} fin.close(); //
}
27.
void Read ( )
{
TRAIN T;
ifstream fin;
fin.open(TRAIN.DAT,ios::binary);
//OR ifstream fin (TRAIN.DAT, ios::binary);
while(fin.read((char*)&T, sizeof(T)))
{
if(strcmp(T.GetTo(),Delhi)==O)
T.Show( ) ;
} fin.close( );
}
Answers to 4 Mark Questions
1. class PIC
{int Pnochar Category[20]char Location[20]
void FixLocation()
public:
void Enter()
void SeeAll()
}
void PIC::FixLocation()
{
if(strcmpi(Category,Classic)==0)
strcpy(Location,Amina)
else if(strcmpi(Category,Modern)==0)
strcpy(Location, Jim Plaq )
else if strcmpi(Category,Antique)==0)
strcpy(Location, Ustad Khan )
}
void PIC::Enter()
{
cin>>Pnogets(Category)
FixLocation()
}
void PIC:: SeeAll()
{
cout<<Pno<<Category<<Location<<endl
}
2.
class Photo
{ int Pno char Category[20] char Exhibit[20]
void FixExhibit()
public:
void Register()
void ViewAll()
}
void Photo::FixExhibit()
{
if(strcmpi(Category,Antique)==0)
strcpy(Exhibit,Zaveri)
else if(strcmpi(Category,Modern)==0)
strcpy(Exhibit,Johnsen)
else if strcmpi(Category,Classic)==0)
strcpy(Exhibit,Terenida)
}
void Photo::Register()
{ cin>>Pnogets(Category)
FixExhibit()
}
void Photo:: ViewAll()
{
cout<<Pno<<Category<<Exhibit<<endl
}
3. class CONTEST
{ int Eventno; char Description[30]; int Score; char qualified;
public:
CONTEST(){ Eventno=11; strcpy(Description,School level);
Score=100; qualified=N; }
void Input()
{ cin>>Eventno; gets(Description);cin>>score; }
void Award( int Cutoffscore)
{
if(Score>Cutoffscore)
qualified=Y;
else
qualified=N;
}
void Displaydata()
{cout<<Event Number is<<Eventno<endl;
cout<<description is<<Description<<endl;
cout<<Score is<<Score<,endl;
cout<<Qualified is<<qualified;
}
};
4.
class Tourist
{ int CNo; char CType; int PerKM; int Distance;
public :
Tourist() { CNo=0000; CType=A; }
void CityCharges()
{ if (CType=A) PerKM=20;
else if (CType==B) PerKM=18;
else if ( CType==C)PerKM=15;
}
void Register (abc)
{ cout<<enter cab no. ; cin>>CNo;
cout<<enter cab type; cin>>CType;
CityCharges();
}
void Display()
{ cout<<enter distance;cin>>Distance;
cout<<cab no is<<CNo<<endl;
cout<<cab type is<<CType<<endl;
cout<<PerKm<<PerKM<<endl;
cout<<Amount is<<PerKM*Distance<<endl;
}
};
5.
class ITEM
{
int Code;char Iname[20];float Price;int Qty;
float Offer;
void GetOffer() ;
public:
void GetStock ()
{cin>>Code;gets (Iname) ;
cin>>Price>>Qty;
GetOffer() ;
}
void ShowItern ( )
{
cout<<Code<<Iname<<Price<<Qty<<Offer;
};
void ITEM: : GetOffer ()
{
if (Qty<=50)
Offer = 0;
else if (Qty <=100)
Offer = 5;
else
Offer = 10;
}
6.
class STOCK
{ int ICode,Qty;char Item[20];float Price,Discount;
void FindDisc();
public:
void Buy();
void ShowAll();
} ;
void STOCK::Buy()
{ cin>>ICode;
gets(Item);
cin>>Price;
cinQty;
FindDisc();
}
void STOCK::FindDisc()
{ if (Qty<=50)
Discount=0;
else if (Qty<=100)
Discount=5;
Else
Discount=10;
}
void STOCK::ShowAll()
{ cout<<ICode<<\t<<Item<<\t<<Price<<\t<<Qty
<<\t<<Discount<<endl;
}
7.
class RESORT
{ int Rno;
char Name [20];
float Charges;
int Days;
float COMPUTE();
public:
void Getinfo() ;
void Dispinfo();
};
void RESORT::Getinfo()
{ cin>>Rno;
gets (Name);
cin>>Charges;
cin>>Days;
}
void RESORT::Dispinfo()
{ cout<<Rno<< <<Name<< <<Charges<<
<<Days<< COMPUTE()<<endl;
} float RESORT::COMPUTE(}
{
float Amount = Charges*Days;
if (Amount>11000)
Amount = 1.02*Days*Charges;
return Amount;
}
8.
class HOTEL
{ int Rno;char Name[20];float Tariff;int NOD;
float CALC() ;
public:
void Checkin() ;
void Checkout() ;
} ;
float HOTEL::CALC()
{ float Amount = Tariff*NOD;
if (Amount>10000)
Amount = 1.05*NOD*Tariff;
return Amount;
}
void HOTEL::Checkin()
{
cin>>Rno;
gets (Name);
cin>>Tariff;
cin>>NOD;
}
void HOTEL::Checkout()
{
cout<<Rno<< <<Name<< <<Tariff<<
<<NOD<<CALC ()<<endl;
}
9.. class TEST
{ int TestCode;char Description[20];
int NoCandidate,CenterReqd;
void CALCNTR();
public:
void SCHEDULE();
void DISPTEST();
};
void TEST::CALCNTR()
{ CenterReqd=(NoCandidate/100 + 1);
}
void TEST::SCHEDULE()
{ cout<<"Test Code :";cin>>TestCode;
cout<<"Description :";gets(Description);
cout<<"Number :";cin>>NoCandidate;
CALCNTR();
}
void TEST::DISPTEST()
{ cout<<"Test Code :"<<TestCode<<endl;
cout<<"Description :"<<Description<<endl;
cout<<"Number :"<<NoCandidate<<endl;;
cout<<"Centres :"<<CenterReqd<<endl;;
}
Clothing::Clothing()
{ strcpy(Code,NOT ASSIGNED);
strcpy(Type,NOT ASSIGNED);
Size=0;
strcpy(Material,NOT ASSIGNED);
Price=0;
}
void Clothing::Calc_Price() or void Clothing::CalcPrice()
{if(strcmp(Type,TROUSER) = = 0 && strcmp(Material,COTTON) = = 0)
Price=1500;
else if (strcmp(Type,SHIRT) = = 0 && strcmp(Material,COTTON) = = 0)
Price=1200;
else if (strcmp(Type,TROUSER)==0 && strcmp(Material,COTTON)!=0)
Price=1500*0.75;
else if (strcmp(Type,SHIRT)==0)&& strcmp(Material,COTTON)!=0 )
Price=1200*0.75;
}
void Clothing::Enter()
{ gets(Code); // or cin >> Code;
gets(Type); // or cin >> Type;
cin>>Size;
gets(Material); // or cin >> Material;
Calc_Price(); OR CalcPrice();
}
void Clothing::Show()
{ cout<<Code<<Type<<Size<<Material<<Price<<endl;
}
13.
class Candidate
{ long RNo; char Name[20]; float Score; char Remarks[20];
void AssignRem( ) ;
public:
void Enter( );
void Display( );
};
void Candidate: :AssignRem( )
{
if (Score>=50)
strcpy (Remarks,"Selected") ;
else
strcpy(Remarks,"Not Selected") ;
}
void Candidate: : Enter ( )
{
cin>>RNo ;
gets (Name) ; cin>>Score;
AssignRem( ) ;
}
void Candidate: :Display()
{
cout<<RNo<<Name<<Score<<Remarks<<end1;
}
14.
class TAXPAYER
{
char Name[30],PanNo[30]; float Taxabincm; double TotTax;
void CompTax()
{
if(Taxabincm >500000)
TotTax= Taxabincm*0.15;
else if(Taxabincm>300000)
TotTax= Taxabincm*0.1;
else if(Taxabincm>160000)
TotTax= Taxabincm*0.05;
else
TotTax=0.0;
}
public:
TAXPAYER(char nm[ ], char pan[ ], float tax, double tax) //parameterized constructor
{
strcpy(Name,nm);
strcpy(PanNo,pan);
Taxabincm=tax;
TotTax=ttax;
}
void INTAX()
{
gets(Name);
cin>>PanNo>>Taxabincm;
CompTax();
}
void OUTAX()
{ cout<<Name<<\n<<PanNo<<\n<<Taxabincm<<\n<<TotTax<<endl; }
};
15.
class Applicant
{ long ANo; char Name[25]; float Agg; char Grade;
void GradeMe( )
{
if (Agg > = 80)
Grade = A;
else if (Agg >= 65 && Agg < 80 )
Grade = B;
else if (Agg >= 50 && Agg < 65 )
Grade = C;
else
Grade = D;
}
public:
void Enter ( )
{ cout <<\n Enter Admission No. ; cin>>ANo;
cout <<\n Enter Name of the Applicant ; cin.getline(Name,25);
cout <<\n Enter Aggregate Marks obtained by the Candidate :; cin>>Agg;
GradeMe( );
}
void Result( )
{
cout <<\n Admission No. <<ANo;
cout <<\n Name of the Applicant ;<<Name;
cout<<\n Aggregate Marks obtained by the Candidate. << Agg;
cout<<\n Grade Obtained is << Grade ;
}
};
16.
class ORDER
{ int ICode; char Item [ 20 ] ; float Price; int Qty; float Discount;
void FindDisc();
public:
void Buy()
{ cin >> ICode;
gets(Item);
cin >> Price >> Qty;
FindDisc();
}
void ShowAll()
{ cout << ICode << Item << Price<< Qty << Discount; }
};
void STOCK::FindDisc()
{
if (Qty < =50)
Discount=0;
else if (Qty < =100)
Discount=5;
else
Discount=10;
}
17.
class TravelPlan
{
long PlaceCode;
char Place[30];
int Number_of_travellers;
int Number_of_buses;
public:
TravelPlan()
{
PlanCode=1001;
Place="Agra";
Number_of_travellers=5;
Number_of_buses=1;
}
void NewPlan()
{
cout << "Enter Plan Code:";
cin >> PlanCode;
cout << "\n Enter Place:";
gets(Place);
cout << "\n Enter Plan:";
cin >> Plan;
cout << "\n Enter the number of travellers:";
cin >> Number_of_travellers;
if(Number_of_travellers >= 40)
Number_of_buses=3;
else if(Number_of_travellers >=20)
Number_of_buses=2;
else
Number_of_buses=1;
}
void ShowPlan()
{
cout << "\n Plan Code: " << PlanCode << endl;
cout << "\n Place Name: " << Place << endl;
cout << "\n Number_of_travellers:" << Number_of_travellers << endl;
cout << "\n Number_of_buses: " << Number_of_buses;
}
};
18.
#include < iostream.h>
#include < ctype.h>
class DH{int seat;
char name[20];
static int taken;
public:
void getdata(){
taken++;
cout<<"\nSeat Number = "<< taken;
cout<<"\nName = ";
cin.getline(name,20);
seat=taken;
}
static void status(){
cout<<"\nTotal Seats = 50";
cout<<"\nSeats Taken = "<< taken;
cout<<"\n Available = "<< 50-taken;
}
void disp( ){
cout<<"\nSeat No. = "<< seat;
cout<<"\nName = "<< name;
}
};
DH ob[50];
int DH::taken;
void main()
{
int i,s;
char mo='Y',c;
for(i=0;mo=='Y' && i<50;i++){
ob[i].getdata();
DH::status();
cout<<"\nMore? (Y/N) ";
cin>>mo;
mo=toupper(mo);
c=cin.get();
}
cout<<"Enter Seat No. to display";
cin>>s;
ob[s-1].disp();
}
19.
class tour
{ int tcode,adults,children,distance;float totalfare;
void assignfare()
{ float cfare=50, afare=1500;
if(distance<1500)
afare=afare-(afare*25/100);
totalfare=(children*cfare)+(adults*afare);
}
public:
travel()
{ tcode=adults=children=distance=totalfare=0; }
void entertour()
{
do
{ cout<<"Enter tcode between 6-10 ";
cin>>tcode;
if (tcode<6 || tcode>10)
cout<<"Invalid tcode "<<endl;
}while(tcode<6 || tcode>10);
cout<<"Enter children, adults, distance";
cin>>children>>adults>>distance;
assignfare();
}
void showtour()
{ cout<<"tcode:"<<tcode<<endl;
cout<<"children:"<<children<<endl;
cout<<"adults :"<<adults<<endl;
cout<<"distance:"<<distance<<endl;
cout<<"total fare:"<<totalfare<<endl;
}};
20.
class admission
{ int admno;
char name[20];
int cls;
float fees;
public:
admission()
{ admno=10;
strcpy(name,"NULL");
cls=0;
fees=0;
}
void getdata()
{
do
{ cout<<"Enter admno between 10-1500 ";
cin>>admn
if (admno<10 || admno>1500)
cout<<"Invalid admission no !"<<endl;
}while(admno<10 ||admno>1500);
cout<<"Enter name ";
gets(name);
cout<<"Enter class and fees ";
cin>>cls>>fees;
}
void putdata()
{ cout<<"Admno :"<<admno<<endl;
cout<<"Name :"<<name<<endl;
cout<<"Class :"<<cls<<endl;
cout<<"Fees :"<<fees<<endl;
}
void draw_nos()
{ int num;
randomize();
num=random(1491)+10;
if (num==admno)
putdata();
}
};
21.
Ans.
(i) Multi Level Inheritance
(ii) WallArea, ColorCode,Type, Advance
(iii) Billing(), Print(), PBook(), PView(), Book(), View()
(iv) Exterior(), Paint(), Bill()
22.
Ans. (i) Multi Level Inheritance
(ii) WallArea, ColorCode,Type, Advance
(iii) Bill(), BillPrint(), PBook(), PView(), Book(), View()
(iv) Interior, Painting, Billing
23.
Ans. (i) Multi Level Inheritance
(ii) Enroll(), View(),Enter(), Show()
(iii) RollNo, Budget
(iv) No, it is not possible because class Department is inheriting from class University
privately. So all public and protected members of class University will become private and hence
cannot be accessed by objects.
24.
Ans.
(i) Multi Level Inheritance
(ii) Enroll(), View(),Enter(), Show()
(iii) RollNo, Name,Budget
(iv) Yes, it is possible as it is inherited publically.
25.
Ans.
(i) Multi Level Inheritance
(ii) OverallGrade,Remarks[20];
(iii) Revaluate(),RPrint(),Sentry(),Sdisplay();
(iv) Marks[5],Grade[5],SName[20];
26.
Ans.
(i) Multi Level Inheritance
(ii) FinalGrade,Comments[20];
(iii) Rcalculate(),Rdisplay(),Mentry(),Mdisplay();
(iv) M[5],Grade[5],Name[20];
27.
Ans.
(i) Hierarchical Inheritance
(ii) location, area, sale
(iii) Enter(),Show(),Register (),Show();
(iv) No Data Member, but Member functions are: Input(), Output()
28.
Ans.
(i) Multiple Inheritance
(ii) None
(iii) Enter(), Display(), Input(), output()
(iv) Input(), output(), Profile, Dname, DID
29.
Ans.
(i) Multilevel Inheritance
(ii) None
(iii) Enter(), Display()
(iv) FID, Address, NOE, Description, Input(), Output(), Assign(), Show(), Allocate()
30.
Ans.
(i) Multiple Inheritance
(ii) Register( ), Siteln( ), SiteOut( ),Input( ), Output( )
(iii) Register( ), Show( ), Input( ), Output( )
(iv) No, function Output( ) is not accessible inside the function
SiteOut( ), because Output( ) is a member of class
FaceToFace and SiteOut( ) is a member of class Online and
the classes FaceToFace and Online are two independent
classes.
31.
Ans.
(i) None of data members are accessible from objects belonging to
class AUTHOR.
(ii) Haveit(), Giveit()
(iii) Data members : Employees, Acode, Aname, Amount
Member function: Register(),Enter(),Display(),Haveit(), Giveit(),
Start(), Show(),
(iv) 70
32.
Ans.
(i) Hierarchical Inheritance OR Single Level Inheritance
(ii) 41 bytes
(iii) SDName, Weight, Price
(iv) EDInput(), EDShow(),DInput(), DShow()
33.
Ans.
(i) Constructor of University Class ( Top most Base class)
(ii) 106 bytes
(iii)display(),input(),enrol(int,int),show(),enterdata(),displaydata()
(iv) state
34.
(i) None of the data members
(ii) void Enterdesign( ), void dispdesign( )
(iii) price, cost_of_cloth, design_code, designfee, stiching, costprice,
sellprice;
(iv) 61 bytes
35.
(i) Multiple Inheritance
(ii) InCourse( ), InDistance( ), OutDistance( ), InRegular( ),
OutRegular( )
(iii) InCourse( ), OutCourse( ), InRegular( ), OutRegular( )
(iv) Yes, It can be accessed by using the object because it is a public
member.
36.
(i) Base class : living_being Derived class : cow
(ii) horn_size, legs, jaws
(iii) etchdata() and displaydata()
(iv) No
37.
(i) class MNC
(ii) 129
(iii) void Enter(), void Output(), void Add(), void Show(), void
EnterData(), void DisplayData().
(iv) char country[25]
Data Structure
2/3 Marks Questions
1. Write the definition of a function Alter(int A[], int N) in C++,
whichshould change all the multiples of 5 in the array to 5 and rest of
the elements as 0. For example, if an array of 10 integers is as
follows:
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9]
55 43 20 16 39 90 83 40 48 25
After executing the function, the array content should be changed
as follow:
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9]
5 0 5 0 0 5 0 5 0 5
5. Write a code in C++ for a function void Convert ( int T[], int N) , which repositions all the elements of
array by shifting each of them one to one position before and by shifting the fast element to last.
e.g. if the content of array is
0 1 2 3
22 25 14 30
The changed array content will be:
0 1 2 3
25 14 30 22
6. Write a for a function void ChangeOver ( int P[], int N) in C++ , which repositions all the elements of
array by shifting each of them to next position and shifting last element to first position.
e.g. if the content of array is
0 1 2 3
10 14 11 21
The changed array content will be:
0 1 2 3
21 10 14 11
7.
Write a function SWAP2BEST (intARR[], intSize) in C++ to
modify the content ofthe array in such a way that the elements,
which are multiples of10swap with the value present inthe very
next positionin the array.
For example :
ifthe content ofarray ARRis
90, 56, 45, 20, 34, 54
The contentofarray ARRshould become
56, 90, 45, 34, 20, 54
8. Write a Get1From2( ) function in C++ to transfer the content from
twoarrays FIRST[ ] and SECOND[ ] to array ALL[ ]. The even places(0,2,
4,...) of array ALL[ ] should get the content from the array FIRST[ ]
and oddplaces (1, 3, 5, ) of the array ALL[] should get the content from
the arraySECOND[ ].
Example:
If the FIRST[ ] array contains
30, 60, 90
And the SECOND[ ] array contains
10, 50, 80
The ALL[ ] array should contain
30, 10, 60, 50, 90, 80
11. Write a function REASSIGNO in C++, which accepts an array of integers and its size as parameters and divide
all those array elements by 5 which are divisible by 5 and multiply other array elements by 2.
Sample Input Data of the array
12. Write a function in C++, whichaccepts an integer array and its size
asarguments and swap the elements of everyeven location with its
following oddlocation.
Example :
If an array of nine elements initially
contains the elements as
2,4,1,6,5,7,9,23,10
then the function should rearrange the
array as 4,2,6,1,7,5,23,9,10
13. Write a function in C++, which acceptsan integer array and its size
as parametersand rearranges the array in reverse.
Example:
If an array of nine elements initially
contains the elements as 4, 2, 5, 1,6, 7, 8, 12, 10
Then the function should rearrange thearray as
10,12, 8, 7, 6, 1, 5, 2, 4
14. Write function in C++ which accepts an integer array and 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 elements as 3, 4, 5, 16, 9
The function should rearrange the content of the array as 9, 8, 75,
32,27
15. Write a function in C++ which accepts an integer array and its size
as arguments and exchanges the values of first half side elements with
the second half side elements of the array.
Example :
If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10
The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6
16. Write a Function to Search for an element from Array A by Linear Search.
17. Write a Function to Search for an element from Array A by Binary Search.
18. Write a function to Sort the array A by Bubble Sort.
19. Write a function to Sort the array A by Selection Sort.
20. Write a function to Sort the array A by Insertion Sort.
21. What will be the status of the following list after fourth pass ofbubble sort and fourth pass of selection sort used
for arrangingthe following elements in descending order?
14, 10, -12,9, 15, 35
22. A two dimensional array P[20] [50] is stored in the memory along
the row with each of its element occupying 4 bytes, find theaddress of
the element P[10] [30],if the element P[5] [5] is storedat the memory
location 15000.
24. An array T [25][20] is stored along the row in the memory with each
elementrequiring 2 bytes of storage. If the base address of array T is
42000, find out thelocation of T[l0][15]. Also, find the total number of
elements present in this array.
25. An array A[20][30] is stored along the row in the memory with each
element requiring 4 bytes of storage. If the base address of array A is
32000, find out the location of A[15][10]. Also, find the total number
of elements present in this array.
26. Given an array A[10][12] whose base address is 10000. Calculate the
memory location of A[2][5] if each element occupies 4 bytes and array is
stored column-wise.
27. An array P[15][10] is stored along the column in the memory with
each elementrequiring 4 bytes of storage. If the base address of array
P is 14000, find out thelocation of P[8][5].
28. An array T[15][10] is stored along the row in the memory with each
element requiring 8 bytes of storage. Ifthe base address of array T is
14000, find out the location of T[10][7].
29. An array T[20][10] is stored in the memory along the column with
each of the element occupying 2 bytes, findout the memory location of
T[10][5], if an element T[2][9] is stored at location 7600.
30. An array P[20] [50] is stored in the memory along the column with
each of itselement occupying 4 bytes, find out the 1ocation of
P[15][10], if P[0][0] isstored at 5200.
31. An array G[50] [20] is stored in the memory along the row with each
of itselement occupying 8 bytes, find out the 1ocation of G[10][15], if
P[0][0] is stored at 4200.
32. An array P[50] [60] is stored in thememory along the column with
each of theelement occupying 2 bytes, find out thememory location for
the element P[10][20],if the Base Address of the array is 6800.
35. An array Arr[50][10] is store in thememory along the row with each
elementoccupying 2 bytes. Find out the Baseaddress of the location
Arr[20][50], if thelocation Arr[10][25] is stored at the address
10000.
38. An array S[40][30] is stored in the memoryalong the row with each of
the elementoccupying 2 bytes, find out the memory locationfor the
element S[20][10], if an element S[15][5] is stored at the memory
location 5500.
44. Write a user defined function display (intA[][4], intN,int M) in C++ to find and display all numbers,
which are divisible by 10.
e.g. if the content of array is : 45 50 60
10 3 15
Then output should be 50 60 10
47. Write a ROWSUM( ) function in C++ to find sum of each row of a rxc
Matrix.
48. Write a DSUM function in C++ to find the sum of diagonal element of
an*n matrix.
50. Write a user defined function in C++ to display the sum of row
elements of two dimensional array A[5][6]containing integers.
51. Write a function in C++ to print the product of each column of a
two dimensional integer array passed as theargument of the function.
Explain: if the two dimensional array contains
1 2 4
3 5 6
4 3 2
2 1 5
Then the output should appear as:
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 = 240
54. Write a function int ALTERSUM (int B[ ][5], int N, int M in C++ to
find and returnthe sum of elements from all alternateelements of a two-
dimensional arraystarting from B[0][0].
60. Write the equivalent infix expression for a, b, AND, a, c, AND, OR.
63. Give postfix form expression for: NOT A OR NOT B AND NOT C
78. Write the definition of a member function Pop() in C++, to delete a book from a dynamic
stack of TEXTBOOKS considering the following code is already included in the program.
struct TEXTBOOKS
{
char ISBN[20] char TITLE[80]
TEXTBOOKS *Link
}
class STACK
{
TEXTBOOKS *Top
public:
STACK() {Top=NULL}
void Push()
void Pop()
~STACK()
}
79. Write the definition of a member function PUSH() in C++, to add a new book in a dynamic
stack of BOOKS considering the following code is already included in the program:
struct BOOKS
{
char ISBN[20], TITLE[80]
BOOKS *Link
}
class STACK
{
BOOKS *Top
public:
STACK()
{Top=NULL}
void PUSH()
void POP()
~STACK()
}
};
Data Structure
Answers to 2/3 marks Question
1. void Alter(int A[ ],int N)
{
for (inti=0i<Ni++)
if(A[i]%5==0)
A[i]=5
else
A[i]=0
}
2. void Alter(int A[ ],int N)
{
for (inti=0i<Ni++)
if(A[i]%2==0)
A[i]=0
else
A[i]=1
}
3. voidoddEven(int S[ ],int N)
{
for (inti=0i<Ni++)
{ if(S[i]%2==0)
S[i]+=10
else
S[i]+=5
}
}
4.
void TWOTOONE(int X[], int Y[], int m, int n)
{ int Z[30], i,k=0;
for(i=0;i<=m-1,i++)
{ Z[k]=X[i];
k=k+2;
}
k=1;
for(i=0;i<=n-1;i++)
{ Z[k]=Y[i];
k+=2;
}
cout<<"the resultant array is ";
for(k=0;k<=m+n-1; k++)
cout<<Z[k];
}
34.
Loc(S[I][J]) = Base(S)+W(I+J*N)
Loc(S[15][10]) =Base(S)+4(15+10*40)
Base(S) = 7200-4*415
Base(S) = 7200-1660
Base(S) = 5540
Loc(S[20][15]) =Base(S)+4(20+15*40)
Loc(S[20][15])= 5540 + 4(20+15*40)
= 5540 + 4(20+600)
= 5540 + 4*620
= 5540 + 2480
= 8020
35.
Assuming LBR=LBC=0S=2 bytes
Number of Rows (N)=50
Number of Columns (M)=10
LOC (Arr [I] [J]) = B + (I*M+J)*S
LOC (Arr [10] [25]) = B +(10*10+25)*2
10000 = B +(100+25)*2
B = 10000-250
B = 9750
LOC (Arr [20] [50])= 9750+(20*10+50)*2
= 9750 + (250*2)
= 9750+500
= 10250
39.
void REVCOL(int P[][5],intN,int M)
{
for(int I=N1I>=
0I)
{
for(int J=0J<MJ++)
cout<<P[I][J]
cout<<endl
}
}
int s1=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if((i+j==n-1))
s1+=a[i][j];
cout<<"sum of lower diagonal="<<s1;
56.
64. P = ABCDE/^*F/+
2,3,2,7,2
2,3,2->7/2->3
2,3,2,3
2,3->2^3->8
2,3,8
2->3*8->24
2,24,2
2->24/2->12
2,12
2+12
Result of evaluation = 14
68. 5, 2, *, 50, 5, /, 5, , +
Scanned Element Stack Status
5 5
2 5.2
* 10
50 10, 50
5 10, 50, 5
/ 10, 10
5 10, 10, 5
10, 5
+ 15
69. 60, 6, /, 5, 2, *, 5, , +
Scanned Element Stack Status
60 60
6 60, 6
/ 10
5 10, 5
2 10, 5, 2
* 10, 10
5 10, 10, 5
10, 5
+ 15
70. 5, 3, 2, *, 4, 2, /, , *
Scanned Element Stack Status
5 5
3 5, 3
2 5, 3, 2
* 5, 6
4 5, 6, 4
2 5, 6, 4, 2
/ 5, 6, 2
5, 4
* 20
void DELETE()
{ Node *temp;
if(front==NULL) // No element in the queue
{ cout<<UNDERFLOW..;
}
else
{ temp=front;
front=front->Link;// Making the second node as the first one
temp->Link = NULL;
delete temp; // deleting the previous first node.
}
}
91.
93.
Algorithm for user choice:
1. ch=0 // Initialize a variable for user choice
2. Read ch //Enter, user choice 1 for push and 2 for pop
3. If(ch == 1) then /* if top is at end of Array-Queue */
4. call insert function
5. Else
6. call delete function
7. End
95.
Let Q be a Queue having size N. DATA be the element to be inserted. F
and R denote front and rear positions in the queue.
1. If (R=N-1) then R=0
else
R=R+1
2. If (F=R)
{ write (Queue overflow)
Goto step 5
}
3. Q[R]=DATA
4. If (F=-1)then
F=F+1
5. End
96.
Let Q be a Queue having size N. DATA be the temporary variable which
stores the deleted element (if possible). F and R denote front and rear
positions in the queue.
1. If (F<0) then
{
write(Queue Underflow)
goto step 4
}
2. DATA=Q[F]
3. If(F=R) then
{ F=R=-1 }
else
{
if(F=N-1)
F=0
else
F=F+1
}
4. End
6 MARKS QUESTIONS
1. Note: Write SQL commands for (b) to (e) and write the outputs for (f) on the basis of table GRADUATE.
Table: GRADUATE
(a) List the names of those students who have obtained DIV 1 sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJEZCT and amount of stipend received in a year
assuming that the STIPEND is paid every month.
(c) To count the number of students who are either PHYSICS or COMPUTER SC graduates.
(d) To insert a new row in the GRADUATE table:
11, KAJOL, 300, COMPUTER SC, 75, 1
(e) Give the output of following SQL statement based on table GRADUATE:
(I) Select MIN(AVERAGE) from GRADUATE where SUBJECT= PHYSICS;
(II) Select SUM(STIPEND) from GRADUATE where DIV=2;
(III) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
(IV) Select COUNT(distinct SUBJECT) from GRADUATE;
(f) Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
2. Write SQL commands for (a) to (d) and write the outputs for (f) on the basis of table CLUB.
Table: CLUB
(a) To show all information about the swimming coaches in the club.
(b) To list names of all coaches with their date of appointment (DATOFAPP) in descending order.
(c) To display a report, showing coachname, pay, age and bonus (15% of pay) for all the coaches.
(d) To insert in a new row in the CLUB table with the following data:
11, PRAKASH, 37, SQUASH, {25/02/98}, 2500, M
(e) Give the output of following SQL statements:
(i) Select COUNT(distinct SPORTS) from CLUB:
(ii) Select MIN(AGE) from CLUB where SEX = F;
(iii) Select AVG(PAY) from CLUB where SPORTS = KARATE;
(iv) Select SUM(PAY) from CLUB where DATOFAPP > {31/01/98};
(f) Assume that there is one more table COACHES in the database as shown below:
Table: COACHES
SPORTS SEX COACH_NO
PERSON
AJAY M 1
SEEMA F 2
VINOD M 1
TANEJA F 3
3. (a) Write SQL commands for (i) to (vii) on the basis of the table SPORTS
Table: SPORTS
Student No. Class Name Game1 Grade Game2 Grade
10 7 Sammer Cricket B Swimming A
11 8 Sujit Tennis A Skating C
12 7 Kamal Swimming B Football B
13 7 Venna Tennis C Tennis A
14 9 Archana Basketball A Athletic C
(i) Display the names of the students who have grade C in either Game1 or Game2 or both.
(ii) Display the number of students getting grade A in Cricket.
(iii) Display the names of the students who have same game for both Game1 and Game2.
(iv) Display the games taken up by the students, whose name starts with A.
(v) Add a new column named Marks.
(vi) Assign a value 200 Marks for all those who are getting grade B or grade A in both Game1 and
Game2.
(vii) Arrange the whole table in the alphabetical order of Name.
(b) Explain Cartesian product of two relations.
4. Given the following Teacher relation: Write SQL commands for question (a) to (f)
Table: NEWONES
NO. ITEMNAME TYPE DATEOFSTOCKS PRICE DISCOUNT
11 White wood Double bed 23/03/03 20000 20
12 James 007 Sofa 20/02/03 15000 15
13 Tom look Baby cot 21/02/13 7000 10
(a) To show all information about the sofas from the INTERIORS table.
(b) To list the ITEMNAME which are priced at more than 10,000 from the INTERIORStable.
(c) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from
the INTERIERS table in the descending order of ITEMNAME.
(d) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount percentage is
more than 15 from INTERIORS table.
(e) To count the number of items, whose type is Double Bed from INTERIORtable.
(f) To insert a new row in the NEWONES table with the following data:
14, True Indian, Office Table,{28/03/03}, 15000,20
(g) Give the output of following SQL statement:
Note: outputs of the below mentioned queries should be based in original data given in both the tables i.e.,
without considering the insertion done in (f) part of this question.
(i) Select COUNT(distinct TYPE) from INTERIORS;
(ii) Select AVG(DISCOUNT) from INTERIORS, where TYPE = Baby cot,
(iii) Select SUM(Price) from INTERIORS where DATEOFSTOCK < {12/02/02}.
Table: ARRIVALS
NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
11 Wood Comfort Double Bed 23/03/03 25000 25
12 Old Fox Sofa 20/02/03 17000 20
13 Micky Baby cot 21/02/02 7500 15
(a) To show all information about the baby cots from the FURNITURE table.
(b) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.
(c) To list ITEMNAME AND TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from
the FURNITURE table in descending order of ITEMNAME.
(d) To display ITEMNAME and DATEOFSTOCK of those items, in which the DISCOUNT percentage
is more than 25 from FURNITURE table.
(e) To count the number of items, whose TYPE is Sofa from FURNITURE table.
(f) To insert a new row in the ARRIVALS table with the following data:
14, Velvet touch, Double bed, {25/03/03}, 25000, 30
(g) Give the output of following SQL statement:
Note:outputs of the below mentioned queries should be based on original data given in both the tables
i.e., without considering the insertion done in (g) part of this question.
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE,ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE = Baby cot;
(iv) Select SUM(PRICE) from FURNITURE where DATEOFSTOCK < {12/02/02}.
Table: Issued
Book_Id Quantity Issued
F0001 3
T0001 1
C0001 5
8. Write SQL commands for (a) to (f) and write output for (g) on the basis of Teacher relation given below:
relation Teacher
No. Name Age Department Date of join Salary Sex
1. Jugal 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Maths 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Maths 05/09/97 25000 M
6. Shyam 50 History 27/06/98 30000 M
7. Shiv Om 44 Computer 25/02/97 21000 M
8. Shalakha 33 Maths 31/07/97 20000 F
TABLE ITEM
INo IName Price SNo
T01 Mother Board 12000 S01
T02 Hard Disk 5000 S01
T03 Keyboard 500 S02
T04 Mouse 300 S01
T05 Mother Board 13000 S02
T06 Keyboard 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard Disk 4500 S03
11. Answer the questions (a) and (b) on the basis of the following tables SHOPPE and ACCESSORIES.
TABLE SHOP
ID SName Area
S0001 ABC Computeronics CP
S0002 All Infotech Media GK II
S0003 Tech Shoppe CP
S0004 Greeks Techno Soft Nehru Place
S0005 Hitech Tech Store Nehru Place
TABLE ACCESSORIES
No Name Price ID
A01 Mother Board 12000 S01
A02 Hard Disk 5000 S01
A03 Keyboard 500 S02
A04 Mouse 300 S01
A05 Mother Board 13000 S02
A06 Keyboard 400 S03
A07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard Disk 4500 S03
TABLE SUPPLIERS
SUPCODE SNAME CITY
S01 GET ALL INC KOLKATA
S03 EASY MARKET CORP DELHI
S02 DIGI BUSY GROUP CHENNAI
(a) To display the details of all the products in ascending order of product names (i.e. PNAME).
(b) To display product name and price of all those products, whose price is in the range of 10000 and
15000 (both values inclusive).
(c) To display the number of products which are supplied by each supplier i.e. the expected output
should be
S01 2
S02 2
S03 1
(d) To display the price, product name (i.e. PName) and quantity (i.e. QTY) of those which have quantity
more than 100.
(e) To display the names of those suppliers, who are either from DELHI or from CHENNAI.
(f) To display the name of the companies and the name of the products in descending order of company
names.
(g) Obtain the outputs of the following SQL queries based on the data given in tables PRODUCTS and
SUPPLIERS.
(g1) SELECT DISTINCT SUPCODE FROM PRODUCTS;
(g2) SELECT MAX(PRICE), MIN (PRICE) FROM PRODUCTS;
(g3) SELECT PRICE * QTY AMOUNT FROM PRODUCTS WHERE PID = 104;
(g4) SELECT PNAME, SNAME FROM PRODUCTS P, SUPPLIERS S
WHERE P. SUPCODE = S. SUPCODE AND QTY>100;
13. Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown in (g1) to (g4) parts
on the basis of tables ITEMS and TRADERS.
TABLE ITEMS
CODE INAME QTY PRICE COMPANY TCODE
1001 DIGITAL PAD12i 120 11000 XENITA T01
1006 LED SCREEN 40 70 38000 SANTORA T02
1004 CAR GPS SYSTEM 50 21500 GEOKNOW T01
1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02
1005 PEN DRIVE 32 GB 600 1200 STOREHOME T03
TABLE TRADERS
TCODE TNAME CITY
T01 ELECTRONIC SALES MUMBAI
T03 BUSY STORE CORP DELHI
T02 DISP HOUSE INC CHENNAI
(a) To display the details of all the items in ascending order of item names (i.e. INAME).
(b) To display item name and price of all those items, whose price is in the range of 10000 and 22000
(both values inclusive).
(c) To display the number of items, which are traded by each trader. The expected output of this query
should be
T01 2
T02 2
T03 1
(d) To display the price, item name (i.e. INAME) and quantity (i.e. QTY) of those items which have
quantity more than 150.
(e) To display the names of those traders, who are either from DELHI or from MUMBAI.
(f) To display the name of the companies and the bane of the items in descending order of company
names.
(g) Obtain the outputs of the following SQL queries based on the data given in tables ITEMS and
TRADERS.
(g1) SELECT MAX (PRICE), MIN (PRICE) FROM ITEMS;
(g2) SELECT PRICE * QTY AMOUNT FROM ITEMS WHERE CODE = 1004;
(g3) SELE CT DISTINCT TCODE FROM ITEMS;
(g4) SELECT INAME, TNAME FROM ITEMS I, TRASERS T
WHERE I, TCODE AND QTY<100;
14. Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown in (g1) to (g4) parts
on the basis of tables APPLICANTS and COURSES.
TABLE APPLICANTS
NO NAME FEE GENDER C_ID JOINYEAR
1012 Amandeep 30000 M A01 2012
1102 Avisha 25000 F A02 2009
1103 Ekant 30000 M A02 2011
1049 Arun 30000 M A03 2009
1025 Amber 40000 M A02 2011
1106 Ela 40000 F A05 2010
1017 Nikita 35000 F A03 2012
1108 Arleena 30000 F A03 2012
2109 Shakti 35000 M A04 2011
1101 Kirat 25000 M A01 2012
TABLE COURSES
C_ID COURSE
A01 FASHION DESIGN
A02 NETWORKING
A03 HOTEL MANAGEMENT
A04 EVENT MANAGEMENT
A05 OFFICE MANAGEMENT
(a) To display name, fee, gender, joinyear about the applicants, who have joined before 2010.
(b) To display the names of applicants, who are paying fee more than 30000.
(c) To display name of all applicants in ascending order of their joinyear.
(d) To display the year and the total number of applicants joined in each YEAR from the table
APPLICANTS.
(e) To display the C_ID (i.e. Course ID) and the number of applicants registered in the course from the
APPLICANTS table.
(f) To display the applicants name with their respective courses name from the tables APPLICANTS
and COURSES.
(g) Give the output of following SQL statements:
(g1) SELECT NAME, JOIN YEAR FROM APPLICANTS WHERE GENDER= F AND C_ID=
02;
(g2) SELECT MIN(JOINYEAR) FROM APPLICANTS WHERE Gender= M;
(g3) SELE CT AVG(FEE) FROM APPLICANTS WHERE C_ID= A01 OR C_ID= A05;
(g4) SELECT SUM (FEE), C_ID FROM APPLICATIONS GROUP BY C_ID HAVING COUNT
(*)=2;
15. Consider the following tables CABHUB and CUSTOMER and answer (a) and (b) parts of this question:
TABLE CABHUB
Vcode VehicleName Make Color Capacity Charges
100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C-Class Mercedes RED RED 4 35
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVER 3 12
TABLE CUSTOMER
Code CName VCode
1 HemantSahu 101
2 Raj Lal 108
3 Feroza Shah 105
4 Ketan Dhal 104
TABLE SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000
TABLE PAYLEVEL
PLEVEL PAY ALLOWANCE
P001 26000 12000
P002 22000 10000
P003 12000 6000
TABLE SUPPLIERS
Scode Sname
21 Premium Stationers
23 Soft Plastics
22 Tetra Supply
20. Consider the following table GARMENT and FABRIC, Write SQL commands for the statements (i) to (iv) and give
outputs for the SQL queries (v) to (viii).
TABLE GARMENT
GCODE DESCRIPTION PRICE FCODE READYDATE
10023 PENCIL SKIRT 1150 F 03 19-DEC-08
10001 FORMAL SHIRT 1250 F 01 12-JAN-08
10012 INFORMAL SHIRT 1550 F 02 06-JUN-08
10024 BABY TOP 750 F 03 07-APR-07
10090 TULIP SKIRT 850 F 02 31-MAR-07
10019 EVENING GOWN 850 F 03 06-JUN-08
10009 INFORMAL PANT 1500 F 02 20-OCT-08
10007 FORMAL PANT 1350 F 01 09-MAR-08
10020 FROCK 850 F 04 09-SEP-07
10089 SLACKS 750 F 03 20-OCT-08
TABLE FABRIC
FCODE TYPE
F 04 POLYSTER
F 02 COTTON
F 03 SILK
F01 TERELENE
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENT, which have READYDATE in between 08-DEC-07 and
16-JUN-08 (inclusive if both the dates).
(iii) To display the average PRICE of all the GARMENT, which are made up of fabric with FCODE as
F03.
(iv) To display fabric wise highest and lowest price of GARMENT from GARMENT table. (Display
FCODE of each GARMENT along with highest and lowest Price).
(v) SELECT SUM (PRICE) FROM GARMENT WHERE FCODE = F01;
(vi) SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC
WHERE GARMENT, FCODE = FABRIC.FCODE AND GARMENT.PRICE >=1260;
(vii) SELECT MAX (FCODE) FROM FABRIC;
(viii) SELECT COUNT (DISTINCT PRICE) FROM GARMENT;
21.
Consider the following DEPT and WORKER tables. Write SQL queries for (i) to
(iv) and find outputs for SQL queries (v) to (viii) :
(i) To display Wno, Name, Gender from the table WORKER in descending
order of Wno.
(ii) To display the Name of all the FEMALE workers from the table WORKER.
(iii) To display the Wno and Name of those workers from the table WORKER
who are born between 1987-01-01 and 1991-12-01.
(iv) To count and display MALE workers who have joined after 1986-01-01.
(v) SELECT COUNT(*), DCODE FROM WORKER
GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT, CITY FROM WORKER W,DEPT D WHERE
W.DCODE=D.DCODE AND WNO<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM WORKER;
DATABASE MANAGEMENT SYSTEM & SQL
2 MARK QUESTIONS
1. A relation is table having atomic values, unique rows and unordered rows and columns.
A row in a relation is known as tuple whereas a column of a table is known as an attribute.
2. A Primary Key is a set of one or more attributes that can be uniquely identify tuples within the
relation.
3. Duplication of data is data redundancy. It leads to the problems like wastage of space and data
inconsistency.
4. (i) Degree: The numbers of attributes (columns) in a relation determine the degree of a relation.
(ii) Cardinality: The number of tuples (rows) in a relation is called the cardinality of the relation.
5. A relation R is in first normal form (INF) if and only if all underlying domains of the relation contain
atomic (indivisible) values.
A relation R is in second normal form (2NF) if and only if it is in 1 NF and every nonkey attribute is
fully dependent on the primary key.
A relation R is said to be in third normal form (3NF) if only and if it is in 2 NF and every nonkey
attribute is non-transitively dependent upon the primary key.
6. A view is a virtual table that does not really exist in its own right but it instead derived from one and
more underlying base table(s). The view is kind of table whose contents are taken upon other tables
depending upon a given query condition. No stored file is created to store contents of a view rather its
definition is stored only.
The usefulness of views lies in the fact that they provide an excellent way to give people access to
some but not all of the information in a table.
7. Candidate Key. A candidate key is the one that is capable of becoming primary key. i.e., a field or
attribute that has unique value for each row in the relation.
Primary Key is a designed attribute or a group of attributes whose values can uniquely identify the
tuples in the relation.
8. Candidate Key. A candidate key is the one that is capable of becoming primary key i.e., a field or
attribute that has unique value for each row in the relation.
A candidate key that is not a primary key is called an Alternate key.
9. Primary Key. It is the set of one or more attributes that can uniquely identify tuples within a relation.
Alternate Key. It is a candidate key which is not primary key.
10. A candidate key is the one that is capable of becoming primary key i., a field or attribute that has
unique value for each row in the relation.
Example Table: ITEM
Ino Item Quantity
101 Pen 560
102 Pencil 340
104 CD 540
10 DVD 200
110 Floppy 400
{Candidate Keys}
11. The SQL DDL provides commands for defining relation schemas, deleting relationship, creating
indexes and modifying schemas.
The SQL DML includes a query language to insert, delete and modify tuples in the database.
Data Manipulation Language (DML) is used to put values and manipulate them in tables and other
database objects and Data Definition language (DDL) is used to create tables and other database
objects.
12. The HAVING clause places conditions on groups in contrast to WHERE clause, which places
conditions ` on individual rows.
13. CREATE TABLE Employee
( EmpNo CHAR(4) NOT NULL PRIMARY KEY,
Name CHAR(20) NOT NULL,
Skill CHAR(1),
PayRate REAL);
14. CREATE TABLE Emp
( EmpNo Number(4) NOT NULL PRIMARY KEY
DeptNo Number(2),
EmpName Char(10),
Job Char(10),
Manager Number(4),
Hiredate Date,
Salary Number(7,2);
Commission Number(7,2) );
15. CREATE TABLE Dept
( DeptNo NUMBER(2) NOT NULL PRIMARY KEY,
DeptName CHAR(12),
Location CHAR(12);
16. CREATE TABLE Project
( ProjId Number(4) NOT NULL PRIMARY KEY,
ProjDesig Char (20) NOT NULL,
ProjStartDT Date,
ProjEndDT DATE,
BudgetAmount Number(7,2)
MaxNoStaff Number(2) );
17. CREATE TABLE Salgrade
( LowSal NUMBER(7,2),
HighSal NUMBER(7,2),
Grade NUMBER(2) );
18. Date ( ) function gives the system date.
INSERT INTO Emp
VALUES (3008, 18, XAVIER, Manager, Date( ), 3250, NULL);
19. The two table GABS1 and GABS are as follows:
GAB 1 GAB 2
ROLL NO NAME MARKS SROLL NO AGE
1 ABC 90 1 19
2 GABS 92 3 17
Cartesian Product
RollNo Name Marks SRollNo Age
1 ABC 90 1 19
1 ABC 92 3 17
2 GABS 90 1 19
2 GABS 92 3 17
20. A key is used to identify a tuple uniquely with in the relation. The value of key is unique. No rows in
the relation can have same value.
e.g.In an Employee relation EmpCode is a key using EmpCode one can obtain the information of a
particular employee.
21. The UNION operator is used to combine the result-set of two or more tables, without returning any
duplicate rows.
e.g.
Table CUSTOMERS
ID SNAME CITY
1 A London
2 B Berlin
3 C Mexico
Table SUPPLIER
ID SNAME CITY
3 D Mexico
4 E London
5 F UK
6 G Germany
6 MARKS QUESTIONS
(g2) AMOUNT
1075000
(g3) TCODE
T01
T02
T03
(g3) AVG(FEE)
31666.666
(iii) This query will execute but count (*) will result one row and Make will give more than one
row so both are not compatible together. But on removing Make from select clause it will
give compatible result:
COUNT(*)
5
(iv)
CarName
SX4
C-Class
(iv) MAX(Lastbuy)
24-FEB-10
(vi)Department
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
(viii)
MAX(DOJ) MIN(DOB)
2014-06-09 1984-10-19
BOOLEAN ALGEBRA
1 MARK QUESTIONS
1. Write the Sum of Product form of the function F (P,Q,R) for the following truth table representation of F:
P Q R F
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
2. Write the Product of Sum form of the function F(X,Y,Z) for the following truth table representation of F:
X Y Z F
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
3. Write the Product of Sum of the function G(U,V,W) for the following truth table representation of G:
U V W G
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
4. Write the Product of Sum form of the function G (U, V, W) for the following truth table representation of G:
U V W G(U, V, W)
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 0
5. Write the Sum of Product form of the function F(A, B, C) for the following truth table representation of F:
A B C F
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
6. Write the POS form of boolean function G, which is represented in a truth table as follows:
A B C G
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
7. Write the SOP form of Boolean function F, which is represented in a truth table as follows:
X Y Z F
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
8. Write the POS form of a boolean function F, which is represented in truth table as follows:
A B C F
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
9. Write the SOP form of a boolean function F, which is represented in a truth table as follows:
A B C F
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
10. Write the SOP form of a boolean function F, which is represented in a truth table as follows:
X Y Z F(X,Y, Z)
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
11. Write the POS form of boolean function H, which is represented in a truth table as follows:
X Y Z H
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
12. Write the SOP form of boolean function G, which is represented in truth table as follows:
P Q R G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
13. Write the POS form of boolean function H, which is represented in a truth table as follows:
A B C H
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
14. Write the POS form a boolean function G, which is represented in a truth table as follows:
u v w G
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1
15. Draw a logic circuit diagram for the boolean expression: X.(Y + Z)
16. Draw a logic circuit diagram for the boolean expression: A.(B+C)
17. Draw a logic circuit diagram for the boolean expression: A.(B+C)
21. In the Boolean Algebra, verify using truth table that (X + Y) + XY for each X Y in (0, 1).
2 Marks Questions
1. Name the law shown below and verify it using a truth table.
A + B. C = (A + B) .(A + C)
2. Obtain the Boolean expression for the logic circuit shown below:
Name the law shown below and verify it using a truth table.
X + X. Y = X + Y
3 Obtain the Boolean expression for the logic circuit shown below:
7 State DeMorgans laws. Verify one of the DeMorgans laws using a truth table.
8 Draw a logic circuit for the following boolean expression.
A.B +(C +B) .A
9 Obtain the Boolean expression for the logic circuit shown below:
17.Write the equivalent boolean expression for the following logic circuit:
19. Write the equivalent boolean expression for the following logic circuit:
20. Write the equivalent boolean expression for the following logic circuit:
21. Verify the following algebraically:
X.Y + X . Y = (X + Y) . (X + Y)
23. Write the equivalent boolean expression for the following logic circuit:
24. Write the equivalent boolean expression for the following logic circuit:
26. Write the equivalent boolean expression for the following logic circuit:
29. Convert the following boolean expression into its equivalent canonical Sum of Product (SOP) form:
(X+Y + Z).(X+Y + Z).(X+Y+Z).(X+Y+Z)
30. Convert the following boolean expression into the equivalent canonical product of Sum (POS) form.
A. B .C + A .B.C + A.B.C
32. Convert the following boolean expression into its equivalent canonical Sum of Product (SOP):
(u + v + w).(u + v + w).(u + v + w)
33. Given the following truth table, write the sum of products from of the function F (x, y, z):
x y z F
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
34. Prove the algebraically x y z + x y z + x yz +xyz + xyz + xyz = x + y.
35. Convert X + Y to minterms
36. Convert the following three input F denoted by the expression F= (0, 1, 2, 5) into its canonical Sum-
of-Products form.
37. Simplify ABCD + ABCD + ABCD + ABCD.
38. Provide that X. (X + Y) = X by algebraic method.
39.Verify X . Y + Y .Z = X. Y .Z + X .Y .Z + X .Y .Z algebraically.
40. Perform the following:
(a) State and prove the De Morgans Theorem (Any One) Algebraically.
41. State and prove the absorption algebraically.
42. Given the following truth table, derive a Sum of Product (SOP) and Product of Sum (POS) form
of Boolean expression from it:
X Y Z G (X, Y ,Z)
0 0 0 0
0 0 1 1
0 1 0 1
0 1 0 1
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
43. Given the following truth table, derive a sum of product (SOP) and Product of Sum (POS) form of
Boolean expression from it.
A B C F (A, B ,C)
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 1
1 1 1 0
44. Represent the Boolean expression X. Y + Z with the help of NOR gates only.
45. Represent the Boolean expression (X + Y) .Z with the help of NAND gates only.
3 Marks Questions
1. Obtain the minimal form for the following boolean expression using Karnaughs Map:
F(A, B, C, D) = (1, 4, 5, 9, 11, 12, 13, 15)
2. Obtain the minimal form for the following boolean expression using Karnaughs Map:
F(A, B, C, D) = (1, 3, 4, 5, 6, 7, 12, 13)
3. Obtain a simplified form for the following boolean expression using Karnaughs Map:
F(P, Q, R, S) = (0, 2, 4, 5, 6, 7, 8, 10, 13, 15)
4. Obtain the minimal form for the following boolean expression using Karnaughs Map:
H(P, Q, R, S) = (0, 1, 2, 3, 5, 7, 8, 9, 10, 14, 15)
5. Obtain the minimal form for the following boolean expression using Karnaughs Map:
F(U, V, W, Z) = (0, 1, 2, 3, 6, 7, 8, 9, 10, 13, 15)
18. If F(a, b, c, d) = (0, 2, 4, 5, 7, 8, 10, 12, 13, 15), obtain the simplified form using K-Map.
19. What is the simplified Boolean equation for the following K-map.
BOOLEAN ALGEBRA-SOLUTION
1 MARK QUESTIONS
1. P Q R F Minterm
0 0 0 1 PQR
0 0 1 0 PQR
0 1 0 0 PQ R
0 1 1 1 PQ R
1 0 0 0 P QR
1 0 1 0 P QR
1 1 0 1 P O R
1 1 1 1 PQR
2. X Y Z F Maxterm
0 0 0 1 X+Y+Z
0 0 1 0 X + Y + Z
0 1 0 0 X + Y+ Z
0 1 1 1 X + Y+ Z
1 0 0 0 X + Y + Z
1 0 1 0 X + Y+ Z
1 1 0 1 X + Y+ Z
1 1 1 1 X + Y+ Z
3. U V W G Maxterm
0 0 0 1 U + V +W
0 0 1 0 U + V + W
0 1 0 1 U + V+ W
0 1 1 0 U + V+ W
1 0 0 1 U + V + W
1 0 1 0 U + V+ W
1 1 0 0 U + V+ W
1 1 1 1 U + V+ W
To get the Product of Sum form, we need to product maxterms for all those input combinations that
product output as 0. Thus, G(U, V, W) = (U + V + W). (U + V + W).
(U + V + W). (U + V + W)
4. U V W G Maxterm
0 0 0 0 U + V +W
0 0 1 1 U + V + W
0 1 0 0 U + V+ W
0 1 1 1 U + V+ W
1 0 0 1 U + V + W
1 0 1 0 U + V+ W
1 1 0 1 U + V+ W
1 1 1 0 U + V+ W
To get the Product of Sum (POS) form, we need to product 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)
5. A B C F Minterm
0 0 0 0 ABC
0 0 1 0 ABC
0 1 0 1 ABC
0 1 1 1 ABC
1 0 0 1 ABC
1 0 1 0 ABC
1 1 0 0 ABC
1 1 1 1 ABC
To get the SOP form, we need to sum minterms for all those input combinations that produce output
as 1. Thus,
F(A,B,C) = ABC+ABC + ABC+ABC
6. A B C G Maxterm
0 0 0 0 A+B+C
0 0 1 1 A+B+C
0 1 0 1 A+B+C
0 1 1 0 A+B+C
1 0 0 0 A+B+C
1 0 1 0 A+B+C
1 1 0 1 A+B+C
1 1 1 1 A+B+C
To get the Product of Sum (POS) form, we need to product maxterms for all those input
combinations that produce output as 0. Thus,
G (A,B,C) = (A + B + C). (A + B + C)
.(A + B + C).(A + B + C)
7. X Y Z F Minterm
0 0 0 1 X+Y+Z
0 0 1 0 X+Y+Z
0 1 0 1 X + Y+ Z
0 1 1 0 X+Y+Z
1 0 0 1 X+Y+Z
1 0 1 0 X + Y+ Z
1 1 0 0 X + Y+ Z
1 1 1 1 X + Y+ Z
To get the SOP form, we need to sum minterms for all those input combinations that produce
outputs as 1. Thus,
F(X, Y, Z) = (X. Y. Z) + (X. Y. Z) + (X. YZ) + (X. Y. Z)
8.
A B C F Maxterm
0 0 0 0 A+B+C
0 0 1 1 A+B+C
0 1 0 1 A+B+C
0 1 1 0 A+B+C
1 0 0 1 A+B+C
1 0 1 0 A+B+C
1 1 0 0 A+B+C
1 1 1 1 A+B+C
To get the POS form, we need to product maxterms for all those input combinations that produce
output as 0. Thus,
F(A, B, C) = (A + B + C). (A + B + C).(A + B + C). (A + B + C)
9. A B C F Minterm
0 0 0 1 A .B .C
0 0 1 0 A .B .C
0 1 0 0 A .B .C
0 1 1 1 A .B .C
1 0 0 0 A .B .C
1 0 1 0 A .B .C
1 1 0 1 A .B .C
1 1 1 1 A .B .C
To get the SOP form, we need to sum minterms for all those input combinations that produce
output as 1. Thus,
F(A, B, C) = (A .B . C) + (A . B. C)+ (A .B . C) + (A .B . C)
10.
X Y Z F(X, Y,Z) Minterm
0 0 0 1 X+Y+Z
0 0 1 1 X+Y+Z
0 1 0 0 X + Y+ Z
0 1 1 1 X+Y+Z
1 0 0 1 X+Y+Z
1 0 1 0 X + Y+ Z
1 1 0 0 X + Y+ Z
1 1 1 1 X + Y+ Z
To get the SOP form, we need to sum minterms for all those input combinations that produce
output as 1. Thus,
F(X, Y, Z) = (X. Y. Z) + (X. Y. Z) + (X. Y. Z)+ (X. Y Z) + (X. Y. Z)
11. X Y Z H Maxterm
0 0 0 1 X+Y+Z
0 0 1 0 X+Y+Z
0 1 0 1 X + Y+ Z
0 1 1 1 X+Y+Z
1 0 0 1 X+Y+Z
1 0 1 0 X + Y+ Z
1 1 0 0 X + Y+ Z
1 1 1 1 X + Y+ Z
To get the POS form, we need to maxterms for all those input combinations that produce output as
0. Thus,
H(X, Y, Z) = (X + Y + Z) .(X + Y + Z).(X + Y + Z)
12. P Q R GMinterm
0 0 0 0 P .Q . R
0 0 1 0 P .Q . R
0 1 0 1 P .Q . R
0 1 1 1 P .Q . R
1 0 0 1 P .Q . R
1 0 1 0 P .Q . R
1 1 0 1 P .Q . R
1 1 1 1 P .Q . R
To get the SOP form, we need to sum minterms for all those combinations that produce output as 1. Thus,
G(P, Q, R) = (P .Q .R) + (P .Q.R)+ (P .Q . R) + (P .Q. R)+ (P .Q. R)
13.
A B C H Maxterm
0 0 0 0 A+B+C
0 0 1 1 A+B+C
0 1 0 1 A+B+C
0 1 1 1 A+B+C
1 0 0 1 A+B+C
1 0 1 0 A+B+C
1 1 0 0 A+B+C
1 1 1 1 A+B+C
To get the POS from, we need to product maxterms for all those input combinations that produce
output as 0. Thus,
14. u v w GMaxterm
0 0 0 1 u + v +w
0 0 1 1 u+v+w
0 1 0 0 u + v+ w
0 1 1 0 u + v+ w
1 0 0 1 u+v+w
1 0 1 1 u + v+ w
1 1 0 0 u + v+ w
1 1 1 1 u + v+ w
To get the POS form, we need to product maxterms for all those input combinations that produce output as
0. Thus,
16.
17.
18.
X Y X+Y X. (X + Y)
0 0 0 0
0 1 1 0
1 0 1 1
1 1 1 1
From the above table it is obvious that X . (X + Y) = X because both the columns are identical.
X Y X+Y X. (X + Y)
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1
Comparing the columns X + XY and X, we find, contents of both the columns are identical, hence
verified.
21. As it is a 2 variable expression, truth table will be as follows:
X Y X+Y (X + Y) X Y XY
0 0 0 1 1 1 1
0 1 1 0 1 0 0
1 0 1 0 0 1 0
1 1 1 0 0 0 0
Comparing the columns (X + Y)and XY, both of the columns are identical, hence verified.
22. Using duality principle, dual of X . X = 0 is X + X = 1 (By changing (.) to (+) and viceversa and by
replacing 1s by 0s and vice versa).
23. (a) A Minterm is a product of all the literals (with or without the bar) within the logic system.
(b) A Maxterm is a sum of all the literals (with or without the bar) within the logic system.
(c) Aboolean expression composed entirely either of minterms or Maxterms is referred to as
canonical expression.
24. F = AB + CD
30. NAND and NOR gates are less expensive and easier to design. Also, other switching functions and
(AND, OR) can easily be implemented using NAND/NOR gates. Thus, these (NAND/NOR) gates are
also referred to as Universal Gates.
2 Marks Questions
1. A + B.C =(A+B).(A+C)
The above stated law is called distributive law.
A B C B.C A+B.C A+B A+C(A+B).(A+C)
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1
Since, the column 5 and column 8 are equal. Hence, the given law A+B.C = (A + B).(A + C) is verified.
2.
5. A + C = A + A.C + B.C
RHS = A + A .C + B.C
= (A + A). (A + C) + B.C (by using distributive law)
= 1.(A + C) + B.C (by using A + A = 1)
= A + C + B. C
= A + C. (1+B)
=A+C (by using absorption law)
= LHS Hence proved
6.
7. DeMorgans Laws:
It states that
(i) (A + B) = A.B (ii) (A. B) = A + B
Truth table for A + B = A .B
9.
11.
14. u .(u+ v) =u +v
u v u u+ v u + v u.(u + v)
0 0 1 1 0 0
0 1 1 1 1 0
1 0 0 0 1 0
1 1 0 1 1 1
As u.(u + v) and u + v columns are not equal. Hence, terms on RHS and LHS are not equal.
Hence, u .(u + v) # u + v
15.
X Y Z YZ X + YZ X + Y X + Z (X + Y).(X + Z)
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1
As columns X + Y .Z and (X + Y). (X + Z) are equal. So, X + Y.Z = (X +Y). (X +Z).Hence proved.
17.
XY = X + Y . Hence approved
(ii) X+ Y = X .Y
This theorem states, that the complement of sum of equal to product of complements, i.e.
complement of two or more variables used in OR gate is the same as the AND gate of the
complements of each individual variables.
Truth Table
X Y X+Y X Y X+Y X.Y
0 0 0 1 1 1 1
0 1 1 1 0 0 0
1 0 1 0 1 0 0
1 1 1 0 0 0 0
19.
22. (A + B) .(A + B) = AB + AB
LHS (A + B) .(A + B)
=A.A + AB + BA + BB
= 0 + AB + BA + 0 [as A.A = 0]
= AB + AB [as A.B = B.A]
= RHS Hence proved
23.
X Y X YXY XY XY XY + XY + XY X + Y
0 0 1 1 0 0 1 1 1
0 1 1 0 1 0 0 1 1
1 0 0 1 0 1 0 1 1
1 1 1 0 0 0 0 0 0
X Y Z Y + Z X.(Y + Z) XY XZ XY + XZ
0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1
38. L.H.S = X . (X + Y)
=X.X+X.Y
= X + X .Y (X . X = X)
= X . (1 + Y)
= X .1 = X = R.H.S (1 + Y = 1)
= X .1 = X = R.H.S
45 . (X + Y) . Z =X . Z + Y . Z
3 Marks Questions
1. F(A, B, C, D) = (1, 4, 5, 9, 11, 12, 13, 15)
1. XcelenciaEdu Services Ltd. is an educational organization. It is planning to set up its India campus at
Hyderabad with its head office at Delhi. The Hyderabad campus has 4 main buildings - ADMIN, SCIENCE,
BUSINESS and ARTS. You as a network expert have to suggest the best network related solutions for
their problems raised in (i) to (iv), keeping in mind the distances between the buildings and other given
parameters.
(i) Suggest the most appropriate location of the server inside the HYDERABAD campus (out of the 4
buildings), to get the best connectivity for maximum number of computers. Justify your answer.
(ii) Suggest and draw the cable layout to efficiently connect various buildings within the HYDERABAD
campus for connecting the computers.
(iii) Which hardware device will you suggest to be procured by the company to be installed to protect
and control the internet uses within the campus ?
(iv) Which of the following will you suggest to establish the online face-to-face communication
between the people in the Admin Office of HYDERABAD campus and DELHI Head Office ?
a) E-mail
b) Text Chat
c) Video Conferencing
d) Cable TV
2. Trine Tech Corporation (TTC) is a professional consultancy company. The company is planning to set up their
new offices in India with its hub Hyderabad. As a network advisor, you have to understand their requirement
and suggest them the best available solutions. Their queries are mentioned as (i) to (iv) below.
Physical locations of the blocks of TTC
Human Resource
Conference Block
Block
Finance Block
3. Tech up Corporation (TUC) is a professional consultancy company. The company is planning to set up their
new offices in India with its hub at Hyderabad. As a network advisor, you have to understand their
requirement and suggest to them the best available solutions. There queries are mentioned as (i) and (iv)
below you have to understand their requirement and suggest to them the best available solutions. Their
queries are mentioned as (i) and (iv) below.
Physical locations of the blocks of TUC
Conference Human
Block Resource
Block
Finance Block
Human
Resources
Delhi Head
Office
Administration Academics
Finance
Building
Faridabad Campus
Building
RAVI Head Office
KOLKATA
Building
JAMUNA
Building
GANGA
7. Work a lot consultants are setting up a secured network for their office campus of Gurgaon for their day-to-
Day office and web based activities. They are planning to have connectivity between three buildings and
the Head office situated in Mumbai. Answer the questions (i) to (iv) after going through the building
positions in the campus and other details, which are given below:
Faridabad Campus
Building
Head Office GREEN
MUMBAI
Building
RED
Building
Blue
Number of computers
Building GREEN 32
Building RED 150
Building BLUE 45
Head Office 10
(i) Suggest the most suitable place (i.e. building) to house the server of this organization. Also, given a
reason to justify your suggested location.
(ii) Suggest a cable layout of connections between the buildings inside the campus.
(iii) Suggest the placement of the following
8. Quick learn university is setting up its academic blocks at Prayag Nagar and planning to set up a network.
The university has three academic blocks and one human resource Centre as shown in diagram below:
Business Technology
Block Block
HR
Law Centre
Block
9. Great Studies University is setting up its academic schools at Sunder Nagar and planning to set up a
network. The university has three academic schools and one administration center as shown in the
diagram:
Business Technology
School School
Admin
Law Centre
School
10. Learn Together is an educational NGO. It is setting up its new campus at Jabalpur for its web based
activities. The campus has four compounds as shown in the diagram below:
Resource Main
Compound Compound
Training Finance
Compound Compound
Centre to centre distance between various compounds as per architectural drawing (in m.) is as follows:
Main Compound to Resource Compound 110 m
Main Compound to Training Compound 115 m
Main Compound to Finance Compound 35 m
Resource Compound to Training Compound 25 m
Resource Compound to Finance Compound 135 m
Training Compound to Finance Compound 100 m
Expected numbers of computers in compound is as follows:
Main Compound 5
Resource Compound 15
Training Compound 150
Finance Compound 20
11. Vidya for All is an educational NGO. It is setting up its new campus at Jaipur for its web-based activities. The
campus has four building as shown in the diagram below:
Main Resource
Building Building
Training Accounts
Building Building
Centre to centre distance between various buildings as per architectural drawing (in m) is as follows:
Main Building to Resource Building 120 m
Main Building to Training Building 40 m
Main Building to Accounts Building 135 m
Resource Building to Training Building 125 m
Resource Building to Accounts Building 45 m
Training Building to Accounts Building 110 m
Expected number of computers in each building is as follows:
Main Building 15
Resource Building 25
Training Building 250
Accounts Building 10
(i) Suggest a cable layout of connections between the buildings.
(ii) Suggest the most suitable place (i.e. building) to house the server for this NGO. Also, provide a
suitablereason for your suggestion.
(iii) Suggest the placement of the following devices with justification
(a) Repeater (b) Hub/Switch.
(iv) The NGO is Planning to connect its international office situated in Delhi. Which out of the following
wired communication links, will you suggest for a very high speed connectivity?
(a) Telephone analog line (b) Optical fibre
(c) Ethernet cable
12. Freshminds University of India is starting its first campus in Ana Nagar of South India with its centre
admission office in Kolkata. The University has three major blocks comprising of Office block, Science blockand
Commerce is in 5 km area campus.
As a network expert, you need to suggest the network plan as per (i) to (iv) to the authorities keeping in
mind the distance and other given parameters.
Freshminds
Kolkata University Commerce Block
Admission Ana Nagar RAVI
Office Campus
Office Block
Science Block
13. Eduminds University of India is starting its campus in a small town Parampur of Central India with its centre
admission office in Delhi. The University has three major buildings comprising of admin building academicbuildings
and research building in 5 km area campus.
As a network expert, you need to suggest the network plan as per (i) to (iv) to the authorities keeping in
mind the distances and other given parameters.
Eduminds
Delhi University Research Building
Admission Parampur RAVI
Office Campus
Academic Building
Admin Building
14. Institute of Distance Learning is located in Pune and is planning to go in four networking in four wings for
better interaction. The details are shown below:
Student Lib
Wing Wing
Admission Admin
Wing Wing
The distance between various wings
Student Wing to Admin Wing 150 m
Student Wing to Admission Wing 100 m
Student Wing to Lib Wing 325 m
Admission Wing to Admin Wing 100 m
Admission Wing to Lib Wing 125 m
Admin Wing to Lib Wing 90 m
Number of computers
Student Wing 225
Admission Wing 50
Admin Wing 10
Lib Wing 25
(i) Suggest the type of networking (LAN, MAN, WAN) for connecting Lib Wing to Admin Wing justify your
answer.
(ii) Suggest the most suitable place (i.e. wing) to house the server, with a suitable reason.
(iii) Suggest and placement of the following devices with reasons
(a) Repeater (b) Switch
(iv) The institute is planning to link its study centre situated in Delhi. Suggest an economic way to connectit
with reasonably high speed justify your answer.
Comp1
Comp3
Server
Comp2
Comp4
Comp5
57. URL http://www.Gabsclassees.com/aboutus
Domain name www.Gabsclasses.com
Comp1
Comp3
Server
Comp2
Comp4
1.
(i) ADMIN (due to maximum number of computers)
OR
ARTS (due to shorter distance from the other buildings)
2. (i) TTC should install its server in finance block as it is having maximum number of computers.
(ii)
Finance Block
The above layout is based on minimum cable length required which is 120 m in the above case. (iii)
Satellite Link.
(iv) Switch.
3. (i) TUC should install its server in Human Resource Block as it is having maximum number of
computers.
(ii)
Conference
Human
Block
Resource
Block
Finance Block
The above layout is based on the minimum length of cable required, i.e. 140 m.
(iii) Satellite (iv) Switch
4. (i) Human Resources, because it has maximum number of computer.
(ii)
Human
Resources
Administration Academics
(iii) Hub/Switch
(iv) Satellite
5. (i) EPG should install the server in the faculty studio building as it is having maximum number of
computers.
(ii)
Finance Building
6. (i) The most suitable place to house the server in JAMUNA because it has maximum
number of computer.
(ii) Faridabad Campus
Building
RAVIrr3rBUi
Building
JAMUNA
Building
GANGA
(iii) Switchesare needed in every building as they help share bandwidth in every building.
Repeatersmay be skipped as per above layout(because distance is less than 100m) however
if building RAVI and building JAMUNA are directly connected, we can place a repeater there
as a distance between these two building is more than 100 m.
(iv) Coaxial cable.
7. (i) Building RED is the suitable place to house this because it has maximum number of
computers.
(ii) Gurgaon Campus
Building
GREEN
Building
RED
Building
BLUE
(iii) Switches are needed in every building as they help share bandwidth in every building.
Repeaters may be skipped as per above layout (because distance is less than 100m) however if building
Green and building Red are directly connected, we can place a repeater there as the distance between
these two buildings is more than 100 m.
(iv) Coaxial cable
8. (i) The most suitable place to install the server is HR Centre as it has a maximum number of
computers.
(ii)
Business
Block
Technology
Block
Law
Block HR
Centre
(iii) Switch
(iv) WAN as it is another city.
9. (i) The most suitable place to install the server is Admin Centre as it has a maximum number of
computers.
(ii)
Business
School
Technology
School
Law
School Admin
Centre
(iii) Switch device
(iv) WAN as it is outside city.
10. (i)
Finance
Main Compound
Compound
Resource
Training
Compound
Compound
(ii) The most suitable place to house the server is Training Compound as it has a maximum number of
computers.
(iii) Repeater As per one layout (shown in (i)0, the repeater can be avoided as all distances between
the compounds are < =100m.
Hub/SwitchTraining Compound as it is hosting the server.
(iv) Opticalfibre.
11. (i)
Resource
Main Building
Building
Training
Accounts
Building
Building
(ii) The most suitable place to house the server for this NGO is Training Building because it has the
maximum number of computers.
(iii)
Repeater
Resource
Main
Building
Building
Repeater
Switch Switch
Training Accounts
Building Building
Switch
Switch
(iv) Opticalfibre
12. (i)
Commerce Block
Office
Block Science Block
(ii) The most suitable place to house the server is Science Block as it has maximum number of
computers. Thus, reducing the cabling cost and increase efficiency of network.
(iii) Switch is the device to be installed in each of the block to connect all the computers.
(iv) SatelliteCoonection.
13. (i)
Research Building
Academic
Block
Admin Block
(ii) The most suitable place to house the server is Academic Building as it has maximum
number of computers. Thus, it decreases the cabling cost and increase efficiency of
network.
(iii) Switch is to be installed in each of building to connect all the computers.
(iv) Satellite connection.
14. (i) Since, the distance between Lib Wing and Admin Wing is small, so type of networking is small
i.e. LAN.
(ii) Since, maximum numbers of computers are in student Wing, so suitable place to house the
server is Student Wing.
(iii) Repeater should be installed between Student Wing and Admin Wing as distance is more than60
m. Switch should be installed in each Wing to connect several computers.
Repeater
Lib
Student
Wing
Wing
Repeater
Switch Switch
Re
pe
at
er
Admission Admin
Wing Wing
Switch
Switch