Cs
Cs
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 :<<160strlen (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?
25.
26.
27.
28.
void main ( )
{
char Text[ ]=SomeThing;
cout<< Remaining SMS Chars:<< 160strlen (STRING) <<endl;
}
(Note Do not include any header file, which is /are not required).
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;
}
}
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;
}
}
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;
}
Name the header files that shall be needed for the following code
29.
void main ( )
{
char Text[ ]= computers;
cout<<setw(15)<<Text;
}
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.
34.
35.
36.
37.
38.
39.
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
{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
___________________;
//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
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
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
17.
What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code
to illustrate both.
11.
What is the purpose of using a typedef command in C++?Explain with suitable example.
12.
What is the difference between #define and const? Explain with suitable example.
13.
What is the difference between Actual Parameter and Formal Parameters? Also, give a
suitable C++ code to illustrate both.
14
What is the difference between call by reference and call by value with respect to memory
allocation? Give a suitable example to illustrate C++ code.
15.
What is benefit of using default parameter/argument in a function? Give a suitable example to `
illustrate it using C++ code.
16.
What is the benefit of using function prototype for a function? Give a suitable example to illustrate it
using a C++ code.
What is the significance of classes in OOPs?
18. What do you understand by polymorphism? Give an example illustrating its use in a C++ program.
19. Define the term data encapsulation in term of object oriented programming. Give a suitable example
using a C++ code to illustrate the same.
20. Define the term data hiding in the context of object oriented programming give a suitable example
using a C++ code to illustrate the same.
21. Encapsulation is one of the major properties of OOP. How is it implemented in C++?
22. How are abstraction and encapsulation interrelated?
23. What is event driven programming?
24. What do you understand by function overloading? Give an example illustrating its use in a C++
program.
25.
What the operator overloading? Explain with example.
26. What are the advantages of object oriented programming over procedural programming?
27.
What are the major differences between Object Oriented Programming and Procedural Programming?
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
What is a stream? Name the streams generally used for file I/O.
43.
44.
45.
What is pointer?
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.
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
}
51.
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++?
63.
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;
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.
65.
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
FGHI
BCDEFGH
FGHI
FGHI
(iii) EFGH
EFGH
EFGH
EFGH
(iv) CDEFGH
CDEFGH
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 #
(iii) 53 # 54 #
(ii) 52 # 53 # 54 # 55
(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.
(i)
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;
}
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)
(iii)
}
22^21^20^19^
20^21^22^
(ii) 24^23^22^21^20^
(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
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]<<'#';
}
(i) 200#150# (ii) 150#20# (iii) 150#20#250#
(iv) 20#250#
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
}
77.Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
void Location(int &X,int Y=4)
{
Y+=2;
X+=Y;
}
void main()
{
int PX=10,PY=2;
Location(PY) ;
cout<<PX<<" , "<<PY<<endl ;
Location(PX,PY);
cout<<PX<<" , "<<PY<<endl ;
}
78.Write the output of the following C++ program code:
#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]=='N'||Msg[cnt]=='n'||Msg[cnt]==' ')
Msg[cnt]=CH;
else
if(cnt%2==0)
Msg[cnt]=toupper(Msg[cnt]);
else
Msg[cnt]=Msg[cnt-1];
}}
void main()
{ char MyText[]="Input Raw";
Mycode(MyText,'@');
cout<<"NEW TEXT:"<<MyText<<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.
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 ;
}
92. Find the output of following program:
#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();
}
93.
Find the output of following program:
#include<IOSTREAM.H>
void main()
{
float *p,val[]={30,40,30,60,10};
p=val;
cout<<*p<<endl;
p+=2; val[2]+=4.5;
cout<<*p<<endl;
p++;
(*p)+=4.5;
cout<<val[3]<<endl; }
94.
Find the output of following program:
#include<IOSTREAM.H>
void main()
{
char *str="Bhakti";
int *p,val[]={90,115,70,19};
p=val;
cout<<*p<<str<<endl;
str+=2;
p+=2;
cout<<*p<<str;
}
97.
98.
99.
100.
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 1Race T(30);
Option 2Race 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.
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
1.
Write the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
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();
}
6.
Obtain the output of the following C++ program code:
#include<iostream.h>
class env
{
char pl; int humd,temp;
public:
env()
{ pl='B';humd=100;temp=40; }
void hot(int t=5)
{ temp+=t;}
void humid(int h=10)
{ humd+=h;}
void forecast()
{ cout<<pl<<"++"<<temp<<"&"<<humd<<"%"<<endl; }
};
void main()
{
env A;
A.hot(10);
A.forecast();
A.humid(5);
A.forecast();
A.hot(); A.humid();
A.forecast();
}
7.
Obtain the output of the following C++ program code:
#include<iostream.h>
void execute (int &x, int y=200)
{
int temp=x+y; x+=temp;
if(y!=200)
cout<<temp<<','<<x<<','<<y<<endl;
}
void main()
{
int a=10, b=20;
execute(b);
cout<<a<<','<<b<<endl;
execute(a,b);
cout<<a<<','<<b<<endl;
}
8.
Obtain the output of the following C++ program code:
#include<iostream.h>
int a=4;
void func(int x, int &y)
{
y=x+10;
x=x+y;
}
void main( )
{
int a=7;
func(a, ::a);
cout<<a<< ","<<::a<<endl;
func(a, ::a);
cout<<a<< ","<<::a<<endl;
{ int a=6; cout<< - - a; }
}
9.
#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.
#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;}
13. Find the output of the following C++ program code:
#include <iostream.h>
struct POINT
{ int X, Y, Z;
};
void StepIn(POINT & P, int Step=1)
{ P.X+=Step;
P.Y-=Step;
P.Z+=Step;
}
void StepOut(POINT & P, int Step=1)
{ P.X-=Step;
P.Y+=Step;
P.Z-=Step;
}
void main ( )
{ POINT P1={15, 25, 5}, P2={10, 30, 20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<","<<P1.Y<<","<<P1.Z<<endl;
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
}
14.
public :
void Enter ()
{
cin>>GameCode;
gets (GameName);
gets (AgeRange);}
void Display()
{
cout <<Gamecode<<:<<GameName<<endl;
cout<<AgeRange<<endl ;
)
Char*AgeR () {return AgeRange; }
};
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.
21. Assuming the class VINTAGE as declared below, write a function in
C++ to read the objects of VINTAGE from binary file VINTAGE.DAT and
display those vintage vehicles, which are priced between 20000 and
250000.
class VINTAGE
{
int VNO; Char VDesc[10]; float Price;
public:
void GET()
{ cin>>VNO; gets(VDesc);cin>>Price;}
void VIEW()
{
cout<<VNO<<endl;
cout<<VDesc<<endl;
cout<<Price<<endl;}
float ReturnPrice()
{ return Price;}
};
22. Assuming the class NETBOOK as declared below, write a function in
C++ to read the objects of NETBOOK from binary file NETBOOK.DAT and
display those netbooks, which are priced between 25000 and 55000.
class NETBOOK
{
int NBID; Char NBDesc[10]; float Price;
public:
void GET()
{ cin>>NETBID; gets(NBDesc);cin>>Price;}
void VIEW()
{
cout<<NBID<<endl;
cout<<NBDesc<<endl;
cout<<Price<<endl;}
float ReturnPrice()
{ return Price;}
};
23. Write a function in C++ to search for the details (Number& calls)
of those mobile phones, which have more than 1000 calls from a binary
file mobile.dat. Assuming that this binary file contains
records/objects of class mobile, which is defines below:
class mobile
{
char number[10]; int calls;
public:
void Enter() { gets(number);cin>>calls;}
void Billing(){cout<<number<<#<<calls<<endl;
int GetCalls() { return calls;}
};
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;
}
};
27. Write a function in C++ to search and display details of all
trains, whose destination isDelhifrom a binary
fileTRAIN.DAT.Assuming the binary file is containing theobjects of the
following class.
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
1.
Write the definition of a class PIC in C++ with following description:
Private Members
Pno //Data member for Picture Number (an integer)
Category//Data member for Picture Category (a string)
Location//Data member for Exhibition Location (a string)
FixLocation /* A member function to assignExhibition Location as per
categoryas shown in the following table */
Category
Location
Classic
Amina
Modern
Jim Plaq
Antique
Ustad Khan
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
2.
Write the definition of a class Photo in C++ with following description:
Private Members
Pno //Data member for Photo Number (an integer)
Category //Data member for Photo Category (a string)
Exhibit //Data member for Exhibition Gallery (a string)
FixExhibit// A member function to assign Exhibition Gallery as per Category
//as shown in the following table
Category
Exhibit
Antique
Zaveri
Modern
Johnsen
Classic
Terenida
Public Members
Register()// A function to allow user to enter values
//Pno,Category and call FixExhibit()function
ViewAll()// A function to display all the data members
3.
Define a class CONTEST in C++ with the following description:
Private Data Members
Eventno integer
Description char(30)
Score integer
qualified char
Public Member functions
4.
Define a class Tourist in C++ with the following specification:
Data Members
CNo - to store Cab No
CType - to store a character A, B, or C as City Type
PerKM - to store per Kilo Meter charges
Distance - to store Distance travelled (in KM)
Member Functions
A constructor function to initialize CType as A and CNo as 0000
A function CityCharges( ) to assign PerKM as per the following table :
Ctype PerKM
A
20
B
18
C
15
A function RegisterCab() to allow administrator to enter the values
for CNo and CType. Also, this function should call CityCharges() to
assign PerKM Charges.
A function Display() to allow user to enter the value of Distance
and display CNo, CType, PerKM, PerKM*Distance (as Amount) on
screen.
5.
Define a class ITEM in C++ withfollowing description:
Private Members
_ Code of type integer (Item Code)
_ Iname of type string (Item Name)
_ Price of type float (Price of each item)
_ Qty of type integer (Quantity of item in stock)
_ Offer of type float (Offer percentage on the item)
_ A member function GetOffer() to calculate
Offer percentage as per the following rule:
If Qty<=50 Offer is 0
If 50<Qty<=100 Offer is 5
If Qty>100 Offer is 10
Public Members
12.
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.
14.
Define a class TAXPAYER in C++ with following description:
Private members :
Name of type string
PanNo of type string
Taxabincm (Taxable income) of type float
TotTax of type double
A function CompTax( ) to calculate tax according to the following
slab:
Taxable Income
Tax%
Up to 160000
0
>160000 and <=300000
5
>300000 and <=500000
10
>500000
15
Public members :
A parameterized constructor to initialize all the members
A function INTAX( ) to enter data for the tax payer and call
function CompTax( ) to assign TotTax.
A function OUTAX( ) to allow user to view the content of all the data
members.
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 find the Grade
to allow user to enter values for ANo, Name, Agg & call function GradeMe( )
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
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.
17.
Private Members:
Plan Code
of type long
Place
of type character array (string)
Number_of _travellers
of type integer
Number_of_buses
of type integer
Public Members:
A constructor to assign initial values of PlanCode as 1001, Place as Agra, Number_of_travellers as
5, Number_of_buses as 1
A function NewPlan() which allows user to enter PlanCode, Place and Number_of_travellers. Also,
assign the value of Number_of_buses as per the following conditions:
Number_of_travellers
Number_of_buses
Less than 20
1
Equal to or more than 20 and less than 40
2
Equal to 40 or more than 40
3
A function ShowPlan() to display the content of all the data members on screen
18.
A dining hall can accommodate only 50 guests. Define a class to store seat number and name of the
guests who are seated on first come first seated basis. Define functions to display details of any seat
number and to display the current seating situation. Write a program to show the working of this class.
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.
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() ;
);
class Dept : private Campus
{
long DCode [10] ;
char HOD [20] ;
protected :
double Budget;
public:
Dept() ;
void Enter();
void Show();
};
class Applicant: public Dept
{ long RegNo;
char Name [20] ;
public:
Applicant() ;
void Enroll();
void View();
};
(i) Which type of Inheritance is shown in the above example ?
(ii) Write the ruunes of those member functions, which are directly
accessedfrom the objects of class Applicant.
(iii) Write the names of those data manbers, which can be directly
accessiblefrom the member functions of class Applicant.
(iv) Is it possible to dircctly call function Display( ) of class Campus
from anobject of class Dept ? (Answer as Yes or No).
25.
};
classReport:publicScore
{ floatTotal,Avg;
public:
charOverallGrade, Remarks[20];
Report();
voidREvaluate();
voidRPrint();
};
(i)
WhichtypeofInheritance isshownintheaboveexample?
(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();
};
(i)
WhichtypeofInheritance i s shownintheaboveexample?
(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.
double Budget,Income;
protected:
voidAccounts();
public: COMPANY();
voidRegister();
voidShow();
};
classSHOP:private COMPANY
{ charLocation[20]; floatArea; double Sale;
public: SHOP();
voidInput();
voidOutput();
};
(i)
(ii)
28.
Answer the questions (i) to (iv) based onthe following:
class Chairperson
{
long CID; //Chairperson Identification
Number
char CName[20];
protected:
char Description [40];
void Allocate();
public:
Chairperson();
void Assign();
void Show();
};
class Director
{
int DID; //Director ID
char Dname[20];
protected:
char Profile[30];
public:
Director();
void Input();
void output();
};
class Company:private Chairperson, public Director
{
int CID; //Company ID
char City[20], Country[20];
public:
Company();
void Enter();
void Display();
};
(i) Which type of inheritance out of thefollowing is specifically is
illustrated inthe above C++ code?
(a) Single Level Inheritance
(b) Multi Level Inheritance
(c) Multiple Inheritance
(ii) Write the names of data members, which areaccessible by objects of
class type Company.
(iii) Write the names of all member functions,which are accessible by
objects of class typeCompany.
(iv) Write the names of all members, which areaccessible from member
functions of classDirector.
30. Answer the questions (i) to (iv) based onthe following: class
FaceToFace
{
char CenterCode [10] ;
public:
void Input ( ) ;
void Output ( ) ;
} ;
class Online
{
char website [50] ;
public:
void SiteIn ( ) ;
void SiteOut ( ) ;
} ;
class Training: public FaceToFace, private Online
{
long Tcode ;
float charge;
int period;
public:
void Register ( ) ;
void Show ( ) ;
} ;
(i) Which type of Inheritance is shown in theabove example?
ii) Write names of all the member functionsaccessible from Show( )
function of classTraining.
iii) Wr i t e name of all the members accessiblethrough an object of
class Training.
iv) Is the function Output( ) accessible insidethe function SiteOut( )?
Justify your answer.
31.
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( );
};
class Design : protected cloth
{
char design[21];
protected:
float cost_of_cloth;
public:
int design_code;
Design( );
void Enterdesign( );
void dispdesign( );
};
class costing : public cloth
{
float designfee;
float stiching;
float cal_cp( );
protected:
float costprice;
float sellprice;
public:
void Entercost( );
void dispcost( );
costing ( ) { };
};
(i) Write the names of data members which are accessible from objects
belonging to class cloth.
(ii) Write the names of all the members which are accessible from
objects belonging to class Design.
(iii) Write the names of all the data members which are accessible from
member functions of class costing.
(iv) How many bytes will be required by an object belonging to class
Design?
(i)
(ii)
(iii)
(iv)
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++
Answers to 1 Mark Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
(i) stdio.h
(ii) ctype.h
(i) string.h
(ii) stblib.h
(i) math.h
(ii) stdlib.h
(i) stdio.h
(ii) fstream.h
The header files are : stdio.h, string.h
The required header files are : iomanip.h and iostream.h
The multiple uses of input or output operators in one statement are called cascading of I/O
operators.
The default statement gives the switch construct away to take action if the value of the switch
variable does not match any of the case constant.
The void type specifies an empty set of values. It is used as the return type for function that do not
return any value. No object of void type may be declared because it depicts a nil parameter list for a
function.
In switch-case statement, when a match is found, the statement sequence associated with that case
is executed until a break statement or the end of switchstatement is reached. So if break statement
is missing, then the statement sequence is executed until the end of the switch-case statement is
reached.
11
When the size of the code of a function is small that the overhead of the function call becomes
prominent then the function should be declared as inline.
void message() function declare with an empty parentheses, in means that the function does not
pass any parameters.
Encapsulation means wrapping up of data and functions which operate the data into a single unit
and ensures only essential features get represented without representing the detail background.
i.e.., called Abstraction. Therefore, both are inter-related.
inline int bar(float a);
{
..
}
#include<iostream.h>
#include<math.h>
#inlcude<iostream.h>
#include<maths.h>
#inlcude<iostream.h>
#include<maths.h>
#include<ctype.h>
puts ( )<stdio.h
Sin ( )<math.h>
setw ( )<iomanip.h>
Sqrt ( )<math.h>
cout, cin #include<iostream.h>
Tolower( )#include<ctype.h>
cin, cout #include<iostream.h>
toupper( ) #include<ctype.h>
#include<iostream.h>cout
#include<string.h>strlen( )
#include<iostream.h>cout
#include<string.h>strlen( )
#include<iostream.h>cout
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
#include<ctype.h>toupper ( )
#include<ctype.h>toupper( )
#include<iostream.h>cout
#include<iomanip.h>setw( )
#include<iostream.h>cout
#include<iostream.h>cout
#include<iomanip.h>setw( )
iostream.h and ctype.h
While, Float, Amount2, _Counter
For, INT, NeW, name1
iostream.h and math.h
Data_rec asm
7
A preprocessor directive is an instruction to the complier itself. A part of compiler called preprocessor
deals with these directives, before real compilation process. # is used as preprocessor directive in C++.
The memory implementation of char data type is in terms of the number code. Therefore, it is said to be
another integer data type.
Whenever a C++ program is executed, execution of the program starts and ends at main(). The main is
the driver function of the program. If it is not present in a program, no execution can take place.
stdlib.h , conio.h
math.h, stdlib.h
ctype, stdio
Statement 1: File.tellg ( ) ;
Statement 2: File.seekg (-sizeof (PRODUCT), ios::cur));
PRESENT RECORD: 3
Statement 1: F. tellg ( );
Statement 2: F. seekp(Pos-sizeof(C)) ;
OR
F.seekp(-sizeof(C), ios::cur);
Statement 1:
File.seekp(Pos);
OR
File.seekp(-sizeof(A), ios:: cur);
Statement 2:
File.write((char*)&S, sizeof(S));
OR
File.write((char*)&S, sizeof(Stock));
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
47.
48.
File.write((char*)&CL.sizeof(CL)
Statement 1 - File.seekp(Success);
Statement 2 - File.write((char*) &S, sizeof(S)
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));
9.
Output:
Output:
0.5
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
Emphasis on data
Follow bottom up approach in program
design.
Concept of Data hiding prevents accidental
change in the data.
Polymorphism, inheritance, Data
Encapsulation possible.
Procedural Programming
Emphasis on doing things (function)
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; }
36.
Constructor
Its name is same as the class name
Called automatically whenever object is
created.
e.g.
Destructor
Its name is same as the class name preceded
by the tilde(~) sign.
Called automatically whenever object goes
out of scope.
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.
b.
c.
d.
e.
Constructor functions are invoked automatically when the objects are created.
No return type (not even void) can be specified for a constructor.
They cannot be inherited, though a derived class can call the base class constructor.
A constructor may not be static.
It is not possible to take the address of a constructor.
39.
a.
b.
c.
d.
e.
Destructor functions are invoked automatically when the objects are destroyed.
No argument can be provided to a destructor, neither does it return any value.
They cannot be inherited.
A destructor may not be static.
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
The public derivation means that the derived class can
access the public and protected members of the base
class but not the private members of the base class.
With publicly derived class, the public members of the
base class become the public members of the derived
class, and the protected members of the base class
become the protected members of the derived class.
Example:
class super
{ private:
int x; void get();
public:
int y; void put();
protected:
int z; void disp();
};
class sub:public super
{ private:
int a; void init();
public:
int b; void readit();
protected:
int c; void writeit();
};
Protected visibility
The protected derivation means that the derived
class can access the public and private members
of the baseclass protectedly.
With protectedly derived class, the public and
protected members of the base class become
protected members of the derived class.
Example:
class super
{ private:
int x; void get();
public:
int y; void put();
protected:
int z; void disp();
};
class sub:protected super
{ private:
int a; void init();
public:
int b; void readit();
protected:
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
1. Constructor has same name as class name.
2. Constructor cannot have any return type value
not even void.
3. Constructor is automatically called.
4. Constructor cannot be static.
Normal Function
1. A normal function can have any legal name but
not class name.
2. A function should have any return type value.
3. A function is explicitly called.
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;
Q=9;
for(int I=Number-1;I>=0;I--)
switch(I)
{
case 0:
case 1 :
case 2:cout<<P[I]*Q<<endl;
break;
//error 1
// error 2
// error 3
// error 4
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.
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)
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)
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)
(ii)
104.
(i) Polymorphism (OR) Function Overloading (OR) Constructor Overloading
(ii) Destructor, invoked or called when Object goes out of a scope.
105.
(i)
(ii)
106.
(i)
(ii)
107.
(i)
(ii)
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();
}
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( );
}
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()
9..
10.
{
cout<<Rno<< <<Name<< <<Tariff<<
<<NOD<<CALC ()<<endl;
}
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;;
}
class FLIGHT
{
int Fno;char Destination[20];
float Distance, Fuel;
void CALFUEL();
public:
void FEEDINFO();
void FEEDINFO();
void SHOWINFO();
};
void FLIGHT::CALFUEL()
{
if (Distance<=1000)
Fuel=500;
else
if (Distance<=2000)
Fuel=1100;
else
Fuel=2200;
}
void FLIGHT::FEEDINFO()
{
cout<<"Flight No :";cin>>Fno;
cout<<"Destination :";gets(Destination);
cout<<"Distance :";cin>>Distance;
CALFUEL();
}
void FLIGHT::SHOWINFO()
{
cout<<"Flight No :"<<Fno<<endl;
cout<<"Destination :"<<Destination<<endl;
cout<<"Distance :"<<Distance<<endl;;
cout<<"Fuel :"<<Fuel<<endl; }
11.
class Clothing
{
char Code[25], Type[25];
int Size ;char Material[30];
float Price;
public:
Clothing();
void Calc_Price();
void Enter();
void Show();
};
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;
}
12.
class Travel
{
char TCode[5]; //OR char *Tcode;
int No_of_Adults;
int No_of_Children;
int Distance;
float TotalFare;
public:
Travel();
void AssignFare();
void EnterTravel();
void ShowTravel();
};
Travel::Travel() //Constructor
{
strcpy(TCode,NULL);
// OR TCode[0]=\0 OR strcpy(TCode,\0)
// OR TCode=NULL if TCode is declared as char pointer
No_of_Adults = 0;
No_of_Children = 0;
Distance = 0;
TotalFare = 0;
}
void Travel::AssignFare()
{
if(Distance>=1000)
TotalFare = 500*No_of_Adults+250*No_of_Children;
else
if (Distance >= 500)
TotalFare = 300*No_of_Adults+150*No_of_Children;
else
TotalFare = 200*No_of_Adults+100*No_of_Children;
}
void Travel::EnterTravel()
{
gets(TCode); // or cin >> TCode;
cin>>No_of_Adults>>No_of_Children>>Distance;
AssignFare();
}
void Travel::ShowTravel()
{
cout<<TCode<<No_of_Adults<<No_of_Children<<Distance<<TotalFare<<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;
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.
22.
Ans.
(i)
(ii)
(iii)
(iv)
(i)
(ii)
(iii)
(iv)
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)
(ii)
(iii)
(iv)
(i)
(ii)
(iii)
(iv)
(i)
(ii)
(iii)
(iv)
(i)
(ii)
(iii)
(iv)
Hierarchical Inheritance
location, area, sale
Enter(),Show(),Register (),Show();
No Data Member, but Member functions are: Input(), Output()
(i)
(ii)
(iii)
(iv)
Multiple Inheritance
None
Enter(), Display(), Input(), output()
Input(), output(), Profile, Dname, DID
25.
Ans.
26.
Ans.
27.
Ans.
28.
Ans.
29.
Ans.
(i)
(ii)
(iii)
(iv)
Multilevel Inheritance
None
Enter(), Display()
(i)
(ii)
(iii)
(iv)
Multiple Inheritance
Register( ), Siteln( ), SiteOut( ),Input( ), Output( )
Register( ), Show( ), Input( ), Output( )
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.
30.
Ans.
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)
(ii)
(iii)
(iv)
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
2.
Write the definition of a function Alter(int A[], int N) in C++,
whichshould change all the odd numbers in the array to 1 and even
numbers 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]
1
1
0
0
1
0
1
0
0
1
3.
Write code for a function void oddEven (ints[],int N) in C++, to
add 5 inall the odd values and 10 in all the even values of the array S.
e.g. If the original content of the array S is: 50 11 19 24 28.
The modified content will be :60 l6 24 34 38
4.
Write a function in C++ TWOTOONE() which accepts two array X[ ], Y[
] and their size n as argument. Both the arrays X[ ] and Y[ ] have the
same number of elements. Transfer the content from two arrays X[ ], Y[ ]
to array Z[ ]. The even places (0,2,4...) of array Z[ ] should get the
contents from the array X[ ] and odd places (1,3,5...) of array Z[ ]
should get the contents from the array Y[ ].
Example : If the X[ ] array contains 30,60,90 and the Y[ ] array contains 10,20,50. Then Z[ ] should contain
30,10,60,20,90,50.
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
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
10,
The
30,
9.
Write a Get2From1( ) function in C++ to transfer the content from
one arrays ALL[ ] to two arrays Odd[ ]and Even[]. The Even should
contain values from places (0,2,4,) of ALL[] and Odd[] should contain
values from places ( 1,3,5,.).
Example:
If The ALL[ ] array contain
30, 10, 60, 50, 90, 80
Then the Even[ ] array should contains
30, 60, 90
And the ODD[ ] array should contains
10, 50, 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
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
15.
16.
17.
18.
19.
20.
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
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
24.
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
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.
33. An array T[90][100] is stored in thememory along the column with
each of theelements occupying 4 bytes. Find out thememory location for
the element T[10][40],if the Base Address of the array is 7200.
34. An array S[40][30] is stored in thememory along the column with
each of theelement occupying 4 bytes, find out thebase address and
address of element S[20][15], if an element S[15][10] is stored at the
memory location 7200.
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.
36. An array VAL[115][110] is storedin the memory with each element
requiring4 bytes of storage. If the base address ofthe array VAL is
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
60.
61.
62.
63.
74.
4 Marks Questions
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()
}
80. Write a complete program in c++ to implement a dynamically
allocated Stack containing names of Countries.
81. Write a complete program in C++ toimplement a dynamically allocated
Queuecontaining names of Cities.
82. Write a function QUEINS( ) in C++ to insertan element in a
dynamicallyallocated Queue containing nodes of thefollowing given
structure:
struct Node
{intPId ; //Product Id
charPname [20] ;
NODE *Next ;
} ;
91.
Define stackpop( ) to delete nodes, for a linked list implemented
stack having the following structure for each node:
struct Node
{
char name[20];
int age;
Node *Link;
};
class STACK
{
Node * Top;
public:
STACK( ) { TOP=NULL;}
voidstackpush( );
voidstackpop( );
~STACK( );
};
92. Write an algorithm to insert an element from a linked queue
depending upon users choice.
93. Write an algorithm to delete an element from a linked queue
depending upon users choice.
94. Write an algorithm that either pushes or pops an element in a
linked stack, depending upon users choice.
95. Write an algorithm to insert an element in a circular queue
implemented as an array.
96. Write an algorithm to deleting an element from a circular queue
implemented as an array.
Data Structure
Answers to 2/3 marks Question
1.
2.
3.
}
}
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];
}
5.
6.
7.
8.
9.
10.
11.
12.
voidSwapArray(int A[ ], int N)
{
inti,j,temp;
for(i=0;i<N-1;i+=2)
{
temp=A[i];
A[i]=A[i+1];
A[i+1]=temp;
}
13.
{
int temp;
for(i=0,j=size-1;i<size/2;i++,j--)
{
temp=A[i];
A[i]=A[j];
A[j]=temp;
}
}
14.
15.
t=a[i];
a[i]=a[mid+pos+i);
a[mid+pos+i]=t; }
16.
17.
return(-1);
}
18.
{
intI,J,Temp;
for(I=0;I<n-1;I++) //sorting
{
for(J=0;J<(n-1-I);J++)
if(A[J]>A[J+1])
{
Temp=A[J]; //swapping
A[J]=A[J+1];
A[J+1]=Temp;
}
}
}
19.
20.
}
}
Bubble Sort
14,10,-12,9,15,35(Original Content)
i. 14,10,9,15,35,-12
ii. 14,10,15,35,9,-12
iii. 14,15,35,10,9,-12
iv. 15,35,14,10,9,-12(Unsorted statusafter 4th pass)
Selection Sort
14,10,-12,9,15,35(Original Content)
i. 35,10,-12,9,15,14
ii. 35,15,-12,9,10,14
iii. 35,15,14,9,10,-12
iv. 35,15,14,10,9,-12
21.
22.
Loc(P[I][J]) along the row =BaseAddress+W [(ILBR)*C+(JLBC)]
(where C is the number of columns, LBR=LBC=0)
LOC(P[5][5])= BaseAddress + W*[I*C + J]
15000 = BaseAddress + 4*[5*50 + 5]
= BaseAddress + 4*[250 + 5]
= BaseAddress + 4*255
= BaseAddress + 1020
BaseAddress = 15000-1020
= 13980
LOC(P[10][30])= 13980 + 4*[10*50+30]= 13980 + 4*530
= 13980 + 2120
= 16100
23.
Loc(ARR[I][J]) along the row =BaseAddress + W[( I LBR)*C+(J
LBC)]
(where C is the number of columns, LBR = LBC = 0
LOC(ARR[10][5])= BaseAddress + W [ I*C + J]
15000 = BaseAddress + 4[10*20 + 5]
= BaseAddress + 4[200 + 5]
= BaseAddress + 4 x 205
= BaseAddress + 820
BaseAddress = 15000-820
= 14180
LOC(ARR[30][10])= 14180 + 4[30 * 20 + 10]
= 14180 + 4 * 610
= 14180 + 2440
= 16620
OR
LOC(ARR[30][10])= LOC(ARR[10][5])+ W[( I-LBR)*C + (J-LBC)]
= 15000 + 4[(30-10)*20 + (10-5)]
= 15000 + 4[ 20*20 + 5]
= 15000 + 4 *405
= 15000 + 1620
= 16620
24.
25.
26.
27.
Assuminq LBR=LBC=0
B=5200
W=4 bytes
Number of Rows(N)=20
Number of Columns(M)=50
LOC(Arr[I] [J]) = B +(I + J*N)*W
LOC(Arr[15][10]) = 5200+(15+10*20)*4
= 5200 + (215*4)
= 5200 + 860
= 6060
31. Assuminq LBR=LBC=0
B=4200
W=8 bytes
Number of Rows(N)=50
Number of Columns(M)=20
LOC(Arr[I] [J]) = B +(I*M + J)*W
LOC(Arr[10][15]) = 4200+(10*20+15)*8
= 4200 + (215*8)
= 4200 + 1720
= 5920
32. Loc(P[I] [J]) = Base(P)+W(I+J*M)iLoc(P[10][20])
= Base(P)+2(10+20*50)
Loc(P[10] [20])
= 68OO + 2(10+20*50)
= 6800 + 2 (10+1000)
= 6800 + 2*1010
= 6800 + 2020
= 8820
OR
Address of P[i] [j] = BaseAddress+ W((iL1)+(jL2)*M)
Address of P[10] [20]= 6800 +2((10-0)+(20-0)x50)
= 6800 + 2 x 1010
= 6800 + 2020
= 8820
Given Data:
VAL[115][110]
Word Length (W) = 4 Bytes
Base Address of VAL(B) = 1500
VAL[12][9] = ?
C = Total No of Columns=10
R = Total No of Rows=15
Lr = Least Row=1
Lc = Least Column=1
Row Major:
Address of an element (I,J) in row major= B + W ( C (I-Lr) + (J Lc))
VAL [12][9] = 1500 + 4 (10 * (12-1) + (9-1))
= 1500 + 4 (10 * 11+8)
= 1500 + 4 (118)
= 1500 + 472
= 1972.
37.
Given Data:
VAL[115][110]
Word Length (W) = 4 Bytes
Base Address of VAL(B) = 1500
VAL[12][9] = ?
C = Total No of Columns=10
R = Total No of Rows=15
Lr = Least Row=1
Lc = Least Column=1
Column Major:
Address of an element (I,J) in column
major
= B + W ( (I-Lr) + R(J Lc))
VAL [12][9] = 1500 + 4 ((12-1) +15 * (9-1))
= 1500 + 4 (11 + 15 * 8)
= 1500 + 4 ( 11+ 120)
= 1500 + 4 * 131
= 1500 + 524
= 2024.
38. Given,W(Word Length) = 2R(Number of Rows) =40
C(Number of Columns) =30
Lr = Least Row = 0
Lc = Least Column = 0
Loc(S[15][5]) =5500
Address of an element (I,J) in row major = B+ W ( C (I-Lr) + (J Lc))
Loc(S[15][5]= Base(S)+2*(30*(15-0)+(5-0))
5500 = Base(S)+2*(30*15+5)
5500 =Base(S)+2*(450+5)
Base(S) =5500- 910
Base(S) =4590
Loc(S[20][10])=4590+2*(30*(20-0)+(10-0))
=4590+2*(30*20+10)
=4590+2*(600+10)
=4590+1220
= 5810
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
}
}
40.
41.
}
42.
43.
void show( int a[5][5],intr,int c)
{
for(inti=0;i<r;i++)
{ for(int j=0;j<c;j++)
if((i+j==r-1))
cout<<a[i][j];
cout<<endl;
}
}
44.
45.
46.
}
}
47.
48.
49.
voidRowMulti(int A[4][6])
{ intMul[4];
for(inti=0;i<4;i++)
{ Mul[i]=1;
for(int j=0;j<6;j++)
Mul[i]*=A[i][j];
cout<<"Product of row"<<i+1<<"="<<Mul[i]<<endl;
}
}
50.
voidRowSum(int A[5][6])
{ int SUMC[5];
for(inti=0;i<5;i++)
{ SUMC[i]=0;
for(int j=0;j<6;j++)
SUMC[i]+=A[i][j];
cout<<"Sum of row"<<i+1<<"="<< SUMC[i]<<endl;
}
}
51.
voidColProd(int A[4][3],intr,int c)
{ int Prod[C],i,j;
for(j=0;j<c;j++)
{ Prod[j]=1;
for(i=0;i<r;i++)
Prod[j]*=A[i][j];
cout<<"Product of Column" <<j+1<<"="<<Prod[j]<<endl;
}
}
52.
constint n=5;
void Diagonals(int A[n][n], int size)
{
inti,j;
cout<<"Diagonal One:";
for(i=0;i<n;i++)
cout<<A[i]ij]<<" ";
cout<<"\n Diagonal Two:"
for(i=0;i<n;i++)
cout<<A[i][n-(i+1)]<<" ";
}
53.
constint S=7; // or it may be 3 or 5
intDispMRowMCol(intArr[S][S],int S)
{ int mid=S/2; inti; //Extracting middle row
cout<<"\n Middle Row:";
for(i=0;i<S;i++)
cout<<Arr[mid][i]<<" ";
//Extracting middle column
cout<<"\n Middle Column:";
for(i=0;i<S;i++)
cout<<Arr[i][mid]<<" ";
}
54.
int ALTERSUM(int B[ ][5] ,intN,int M)
{
int Sum=0;
for (int I=0;I<N;I++)
for (int J=(I%2==0)?0:1;J<M;J+=2)
Sum+=B[I][J] ;
return Sum;
}
55.
X / Y + U* (VW)=((X / Y)+(U*(VW)))
Element Stack Postfix
(
(
X
X
/
/
X
Y
/
XY
)
XY/
+
+
XY/
(
U
*
(
V
W
)
)
)
+
+
+*
+*
+*
+*+*+*
+
XY/
XY/U
XY/U
XY/U
XY/UV
XY/UV
XY/UVW
XY/UVWXY/UVW-*
XY/UVW-*+
56.
57.
58.
Equivalent postfix expression:
= A*(B+D)/E-F-(G+H/K)
= (A*(B+D)/E) (F (G + (H/K)))
= (A*(BD+)/E) (F (G + (HK/)))
= ((ABD+*) / E) (F (GHK/+))
= ABD+* E/F GHK/+ 59.
10 * 3 * (7 1) + 23
60.
a, b, AND, a, c, AND, OR
(a AND b), (a AND c), OR
(a AND b) OR (a AND c)
61.
Symbol
Stack
12
12
7
12,7
3
12,7,3
12,4
/
3
2
3,2
1
3,2,1
5
3,2,1,5
+
3,2,6
*
3,12
+
15
)
15
62.
A*(B+(CD+EF+*)/G)*H
A*(B+CD+EF+*G/))*H
(A*(BCD+EF+*G/+))H
(ABCD+EF+*G/+*)*H
ABCD+EF+*G/+*H*
63.
64.
65.
66.
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
Result
67.
T, F, NOT, AND, T, OR, F, AND
Scanned Element
Operation
Stack Status
T
Push
T
F
Push
T, F
NOT
Pop one operand from stack
T
NOT F = T
Push
T, T
AND
Pop two operands from stack
T AND T = T
Push
T
T
Push
T, T
OR
Pop two operands from stack
T OR T = T
Push
T
F
Push
T, F
AND
Pop two operands from stack
T AND F = F
Push
F
Result F
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
71.
72.
73.
110, 10
*
1100
Pop all
74.
75.
76.
77.
Y
/
(X Y / (Z + U) * V
Stack Status
Expression
(
(
X
(
X
(
XY
(
void STACK::POP()
{
if (Top!=NULL)
{
TEXTBOOKS *Temp
Temp=Top
cout<<Top->ISBN<<Top->TITLE<<deleted<<endl
Top=Top>
Link
delete Temp
}
else
cout<<Stack Empty<<endl
}
79.
void STACK::PUSH()
{
BOOKS *Temp
Temp=new BOOKS
gets(Temp->ISBN)
gets(Temp->TITLE)
Temp->Link=Top
Top=Temp
}
#include<iostream.h>
#include<stdio.h>
struct Node
{
char Country [20] ; Node *Link; };
class Stack
{ Node *Top;
public:
Stack( )
{ Top = NULL; }
void Push() ;
void Pop() ;
void Display() ;
~Stack () ;
};
void Stack::Push( )
{
Node *Temp = new Node;
gets(Temp -> Country);
Temp -> Link = Top;
Top = Temp;
}
void Stack::Pop( )
{
if (Top !=NULL)
{
Node *Temp = Top;
80.
81.
~Queue( );
} ;
void Queue::Qinsert( )
{
NODE *Temp;
Temp=new NODE;
cout<<Data:;
gets (Temp->City);
Temp->Next=NULL;
if (Rear==NULL)
{
Rear=Temp;
Front=Temp;
}
else
{
Rear>Next=Temp;
Rear=Temp;
}
}
void Queue::Qdelete( )
{
if (Front!=NULL)
{
NODE *Temp=Front;
cout<<Front->City<<Deleted \n;
Front=Front->Next;
delete Temp;
if (Front==NULL)
Rear=NULL;
}
else
cout<<Queue Empty..;
}
Queue::Qdisplay( )
{ NODE *Temp=Front;
while (Temp!=NULL)
{
cout<<Temp->City<<endl;
Temp=Temp->Next;
}
}
Queue:: ~Queue( )//Destructor Function
{ while (Front!=NULL)
{ NODE *Temp=Front;
Front=Front->Next; delete Temp;
}
}
void main( )
{ Queue QU;
charCh;
do
82.
83.
84.
{
:
:
} while (Ch!=Q);
}
void QUEINS (Node *&Front, Node *&Rear)
{ Node *Temp = new Node;
cin>>Temp->PId;
gets (Temp->Pname);
//or cin>>Temp->Pname;
//cin.get1ine(Temp->Pname);
Temp->Next = NULL;
if(Rear == NULL)
Front = Temp;
e1se
Rear -> Next = Temp;
Rear = Temp;
}
class Queue
{Node *Front, *Rear;
public:
QUEUE( )//Constructor to initialize Front and Rear
{
Front = NULL;
Rear = NULL;
}
void QUEINS( );
//Function to insert a node
void QUEDEL( );
//Function to delete a node
void QUEDISP( );
//Function to displaynodes
~Queue();
//Destructor to delete allnodes
};
void Queue::QUEDEL( )
{ if (Front!=NULL)
{NODE *Temp=Front;
cout<<Front->Itemno<< ;
cout<<Front->Itemname<<Deleted;
Front=Front->Link;
delete Temp;
if (Front NULL)
Rear=NULL;
}
else
cout<<Queue Empty..;
}
struct Book
{
intBNo ;
charBName[20] ;
Book *Next ;
} ;
class Stack
{
Book *Top;
public:
Stack( )
{
Top = NULL;
}
void Push( );
void Pop( );
void Display( );
};
void Stack::Pop( )
{
Book *Temp;
if( Top= = NULL)
cout<<Stack Underflow;
else
{
cout<<\nThe Book number of the
element to delete: <<Top->BNo;
cout<<\nThe Book name of the
element to delete: <<Top->BName;
Temp=Top;
Top=Top->Next;
delete Temp;
}
}
85.
class Queue
{
NODE *front,*rear;
public:
Queue( )
{
front = rear = NULL;
}
void Insert( );
void Delete( );
void Display( );
};
void Queue::Insert( )
{
NODE *ptr;
ptr=new NODE;
if(ptr= = NULL)
{
cout<<\nNo memory to create a
new node.;
exit(1);
}
cout<<\nEnter the name.;
gets(ptr->Name);
ptr->Link=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
Rear->Link=ptr;
rear=ptr;
}
}
86.
struct Node
{int X,Y ;
Node *Link ;
} ;
class STACK
{Node *Top ;
public :
STACK( )
{ Top = NULL;
}
void PUSH( ) ;
void POP( ) ;
~STACK( ) ;
} ;
void STACK::PUSH( )
{Node *Temp;
Temp=new Node;
if(Temp= =NULL)
{cout<<\nNo memory tocreate the node;
exit(1);
}cout<<Enter the value of X and Y;
cin>>Temp->X>>Temp->Y;
Temp->Link=Top;
Top=Temp;
}
89.
90.
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.
voidstackpop( )
{
Node *temp;
if(top==NULL)
{
cout<<UNDERFLOW.;
}
else
{
temp=Top;
Top=Top->Link;
temp->Link = NULL;
delete temp;
}}
92.
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
Algorithm for inserting in Linked-Queue:
/* Allocate space for ITEM to be inserted */
1. NEWPTR = new node
2. NEWPTR -> INFO = ITEM; NEWPTR -> LINK=NULL
/* Insert in the queue */
3. If rear = NULL Then
{
4. front = NEWPTR
5. rear = NEWPTR
6. else
{
7. rear -> LINK = NEWPTR
8. rear=NEWPTR
}
9. END.
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
Algorithm for deleting in Linked-Queue:
1. If front==NULL Then
2. Print "Queue Empty"
3. Else
{
4. ITEM=front->INFO
5. If front=rear Then
{
6. front=rear=NULL
}
7. Else
8. front = front + 1
}
9. END
94.
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 stack-array */
4. call push function
5. Else
6. call pop function
7. End
Algorithm for pushing in Linked-Stack
Step-1: If the Stack is empty go to step-2 or else go to step-3
Step-2: Create the new element and make your "stack" and "top" pointers
point to it and quit.
Step-3: Create the new element and make the last (top most) element of
the stack to point to it
Step-4: Make that new element your TOP most element by making the "top"
pointer point to it.
Algorithm for popping in Linked-Stack:
Step-1: If the Stack is empty then give an alert message "Stack
Underflow" and quit; or else proceed
Step-2: If there is only one element left go to step-3 or else step-4
Step-3: Free that element and make the "stack", "top" and "bottom"
pointers point to NULL and quit
Step-4: Make "target" point to just one element before the TOP; free the
TOP most element; make "target" as yourTOP most element
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.
15.
16.
17.
18.
19.
20.
21.
ProjId
NUMBER(4)
ProjDesig
CHAR(20)
ProjStartDT
DATE
ProjEndDT
DATE
BudgetAmount
NUMBER(7)
MaxNoStaff
NUMBER(2)
Create a table called SALGRADE with the columns specified below:
LowSal
NUMBER(7,2)
HighSal
NUMBER(7,2)
Grade
NUMBER(2)
Insert a record with suitable data in the table EMP, having system date as the Hiredate.
Illustrate Cartesian product operation between the two tables/relations using a suitable example.
What is the purpose of key in a table? Give an example of key in a table.
Explain the concept UNION between two tables, with the help of appropriate example.
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
S.NO.
1
2
3
4
5
6
7
8
9
10.
NAME
KARAN
DIVAKAR
DIVYA
ARUN
SABINA
JOHN
ROBERT
RUBINA
VIKAS
MOHAN
STIPEND
400
450
300
350
500
400
250
450
500
300
SUBJECT
PHYSICS
COMPUTER SC
CHEMISTRY
PHYSICS
MATHEMATICS
CHEMISTRY
PHYSICS
MATHEMATICS
COMPUTER SC
MATHEMATICS
AVERAGE
68
68
62
63
70
55
64
68
62
57
DIV
1
1
2
1
1
2
1
1
1
2
(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
What will be the output of the following query:
SELECT
NAME, ADVISOR
FROM
GRADUATE, GUIDE
WHERE
SUBJECT = MAINAREA
2. Write SQL commands for (a) to (d) and write the outputs for (f) on the basis of table CLUB.
Table: CLUB
COACH
ID
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
(a)
(b)
(c)
(d)
COACH
NAME
KUKREJA
RAVINA
KARAN
TARUN
ZUBIN
KETAKI
ANKITA
ZAREEN
KUSH
SHAILYA
AGE
35
34
34
33
36
36
39
37
41
37
SPORTS
KARATE
KARATE
SQUASH
BASKETBALL
SWIMMING
SWIMMING
SQUASH
KARATE
SWIMMING
BASKETBALL
DATEOFAPP
27/03/1997
20/01/1998
19/02/1998
01/01/1998
12/01/1998
24/02/1998
20/02/1998
20/02/1998
13/01/1998
19/02/1998
PAY
1000
1200
2000
1500
750
800
2200
1100
900
1700
SEX
M
F
M
M
M
F
F
F
M
M
PERSON
AJAY
SEEMA
VINOD
TANEJA
M
F
M
F
1
2
1
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)
No.
1.
2.
3.
4.
5.
6.
7.
Name
Raja
Sangita
Ritu
Kumar
Venkatraman
Sidhu
Aishwarya
Department
Computer
History
Sociology
Linguistics
History
Computer
Sociology
Dateofjoining
21/05/98
21/05/97
29/08/98
13/06/96
31/10/99
21/05/86
11/1/98
Salary
80000
9000
8000
10000
8000
14000
12000
Sex
M
F
F
M
M
M
F
(b)
(c)
(d)
(e)
(f)
NO.
11
12
13
ITEMNAME
White wood
James 007
Tom look
Table: NEWONES
TYPE
DATEOFSTOCKS
Double bed
23/03/03
Sofa
20/02/03
Baby cot
21/02/13
PRICE
20000
15000
7000
DISCOUNT
20
15
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}.
ITEMNAME
White lotus
Pink feather
Dolphin
Decent
Comfort zone
Donald
Royal Finish
Royal tiger
Econo sitting
Eating paradise
Table: ARRIVALS
NO.
ITEMNAME
11
Wood Comfort
12
Old Fox
13
Micky
TYPE
Double Bed
Baby cot
Baby cot
Office Table
Double Bed
Baby cot
Office Table
Sofa
Sofa
Dining Table
TYPE
Double Bed
Sofa
Baby cot
DATEOFSTOCK
23/02/02
20//01/02
19/02/02
01/01/02
12/01/02
24/02/02
20/02/02
22/02/02
13/12/01
19/02/02
DATEOFSTOCK
23/03/03
20/02/03
21/02/02
PRICE
30000
7000
9500
25000
25000
6500
18000
31000
9500
11500
PRICE
25000
17000
7500
DISCOUNT
25
20
20
30
25
15
30
30
25
25
DISCOUNT
25
20
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}.
Price
750
Type
Fiction
Qty.
10
700
250
325
Fiction
Text
Text
5
10
5
350
Cookery
Table: Issued
Book_Id
F0001
T0001
C0001
Quantity Issued
3
1
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
(a)
(b)
(c)
(d)
(e)
(f)
INo
T01
T02
T03
T04
T05
T06
T07
T08
T09
T10
(a)
(b)
TABLE ITEM
IName
Price
Mother Board
12000
Hard Disk
5000
Keyboard
500
Mouse
300
Mother Board
13000
Keyboard
400
LCD
6000
LCD
5500
Mouse
350
Hard Disk
4500
SNo
S01
S01
S02
S01
S02
S03
S04
S05
S05
S03
11. Answer the questions (a) and (b) on the basis of the following tables SHOPPE and ACCESSORIES.
TABLE SHOP
ID
SName
S0001
ABC Computeronics
S0002
All Infotech Media
S0003
Tech Shoppe
S0004
Greeks Techno Soft
S0005
Hitech Tech Store
No
TABLE ACCESSORIES
Name
Price
Area
CP
GK II
CP
Nehru Place
Nehru Place
ID
A01
A02
A03
A04
A05
A06
A07
T08
T09
T10
Mother Board
Hard Disk
Keyboard
Mouse
Mother Board
Keyboard
LCD
LCD
Mouse
Hard Disk
12000
5000
500
300
13000
400
6000
5500
350
4500
S01
S01
S02
S01
S02
S03
S04
S05
S05
S03
SUPCODE
S01
S03
S02
TABLE SUPPLIERS
SNAME
CITY
GET ALL INC
KOLKATA
EASY MARKET CORP
DELHI
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
TCODE
T01
T03
T02
TABLE TRADERS
TNAME
CITY
ELECTRONIC SALES
MUMBAI
BUSY STORE CORP
DELHI
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)
(b)
(c)
(d)
To display name, fee, gender, joinyear about the applicants, who have joined before 2010.
To display the names of applicants, who are paying fee more than 30000.
To display name of all applicants in ascending order of their joinyear.
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
Code
1
2
3
4
TABLE CUSTOMER
CName
VCode
HemantSahu
101
Raj Lal
108
Feroza Shah
105
Ketan Dhal
104
501
503
502
509
510
A-star
Indigo
Innova
SX4
C-Class
CCode
1001
1002
1003
1004
Suzuki
Tata
Toyota
Suzuki
RED
3
SILVER
WHITE
SILVER
Mercedes
RED
TABLE CUSTOMER
Cname
Ccode
HamantSahu
501
Raj Lal
509
Feroja Shah
503
Ketan Dhal
502
14
3
7
4
4
12
15
14
35
ECODE
DOB
11
12
13
15
18
NAME
RadheShyam
ChanderNath
Fizza
Ahmeen Ahmad
Sanya
TABLE WORKER
DESIGN
PLEVEL
Supervisor
Operator
Operator
Mechanic
Clerk
P001
P003
P003
P002
P002
DOJ
13-SEP-2004
22-FEB-2010
14-JUN-2009
21-AUG-2006
19-DEC-2005
23-AUG-1981
12-JUL-1987
14-OCT-1983
13-MAR-1984
09-JUN-1983
TABLE PAYLEVEL
PLEVEL
PAY ALLOWANCE
P001
26000
12000
P002
22000
10000
P003
12000
6000
(a) Write SQL commands for the following statements:
(i) To display the detail of all WORKER in descending order of DOB.
(ii) To display name and design of those WORKER, whoseplevel is either P001 to P002.
(iii) To display the content of all the WORKER table, whose DOB is in between 19-JAN-1984
and 18-JAN-1987.
(iv) To add a new row with the following:
19, Daya Kishore, Operator, P003, 19-JUN-2008, 11-JUL-1984.
(b) Give the output of the following SQL queries:
(i) SELECT COUNT (PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
(ii) SELECT MAX (DOB), MIN (DOJ) FROM WORKER;
(iii) SELECT NAME, PAY FROM WORKER W, PAYLEVEL P
WHERE W. PLEVEL= P.LEVEL AND W. ECODE<13;
(iv) SELECT PLEVEL, PAY+ALLOWANCE FROM PLEVEL WHERE PLEVEL = P003;
19. Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of this question:
TABLE STORE
iteemNo
Item
Scode
Qty
Rate
LastBuy
2005
Sharpener Classic
23
60
8
31-JUN-09
2003
Ball pen 0.25
22
50
25
01-FEB-09
2002
Gel Pen Premium
21
150
12
24-FEB-10
2006
Gel Pen Classic
21
250
20
11-MAY-09
2001
Eraser Small
22
220
6
19-JAN-09
2004
Eraser Big
22
110
8
02-DEC-09
2009
Ball Pen 0.5
21
180
18
03-NOV-09
Scode
21
23
22
TABLE SUPPLIERS
Sname
Premium Stationers
Soft Plastics
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).
GCODE
10023
10001
10012
10024
10090
10019
10009
10007
10020
10089
TABLE GARMENT
DESCRIPTION
PRICE
PENCIL SKIRT
1150
FORMAL SHIRT
1250
INFORMAL SHIRT
1550
BABY TOP
750
TULIP SKIRT
850
EVENING GOWN
850
INFORMAL PANT
1500
FORMAL PANT
1350
FROCK
850
SLACKS
750
FCODE
F 03
F 01
F 02
F 03
F 02
F 03
F 02
F 01
F 04
F 03
READYDATE
19-DEC-08
12-JAN-08
06-JUN-08
07-APR-07
31-MAR-07
06-JUN-08
20-OCT-08
09-MAR-08
09-SEP-07
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;
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;
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.
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),
15.
16.
17.
18.
19.
EmpName
Char(10),
Job
Char(10),
Manager
Number(4),
Hiredate
Date,
Salary
Number(7,2);
Commission Number(7,2) );
CREATE TABLE Dept
(
DeptNo
NUMBER(2) NOT NULL PRIMARY KEY,
DeptName
CHAR(12),
Location
CHAR(12);
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) );
CREATE TABLE Salgrade
(
LowSal
NUMBER(7,2),
HighSal
NUMBER(7,2),
Grade
NUMBER(2) );
Date ( ) function gives the system date.
INSERT INTO Emp
VALUES (3008, 18, XAVIER, Manager, Date( ), 3250, NULL);
The two table GABS1 and GABS are as follows:
ROLL NO
GAB 1
NAME
1
2
ABC
GABS
MARKS
GAB 2
SROLL NO
90
92
AGE
1
3
19
17
RollNo
1
1
2
2
Cartesian Product
Name
Marks
ABC
90
ABC
92
GABS
90
GABS
92
1
3
1
3
SRollNo
19
17
19
17
Age
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
3
4
5
6
SNAME
D
E
F
G
CITY
Mexico
London
UK
Germany
6 MARKS QUESTIONS
1.
(a)
(b)
(c)
(d)
(e)
(f)
2.
(a)
(b)
(c)
3.
4.
(f)
(g)
5.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
6.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
7.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
8.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
9.
(a)
(b)
(c)
(d)
(e)
(f)
10.
(g)
(a)
(b)
(The given query is wrong as no. information about students and fee etc. is available.
The query should actually be
To display teachers Name, Salary, Age for male teacher only)
SELECT Name, Salary, Age FROM Teacher
WHERE Age > 23 AND Sex = M;
SELECT COUNT (*) FROM Teacher
WHERE Age > 23;
INSERT INTO Teacher
VALUES (9, Raja, 26, Computer, {13/05/95}, 2300, M);
(i) 3 (ii) 35 (iii)
23600 (AVG (Salary)) (iv) 2300 after insertion (It is
SUM (Salary))
SELECT * FROM Hospital
WHERE Department = Cardiology;
SELECT Name FROM Hospital
WHERE Department = ENT AND Sex = F;
SELECT Name, Datofadm FROM Hospital
ORDER BY Datofadm;
SELECT Name, Charges, Age FROM Hospital
WHERE Sex = F;
SELECT COUNT (*) FROM Hospital
WHERE Age < 30;
INSERT INTO Hospital
VALUES (11, Aftab, 24, Surgery, {25/02/98}, 300, M;
(i) 5 (ii) 16
(iii) 750 (iv) 340.
(i)
SELECT IName, Price
FROM ITEM
ORDER BY Price ASC;
(ii)
SELECT IName
FROM STORE
WHERE Area = CP;
(iii)
SELECT IName,
MIN (Price) Minimum Price,
MAZ (Price) Maximum Price
FROM ITEM
GROUP BY IName;
(iv)
SELECT IName, Price, SName
FROM ITEM I, STORE S
WHERE I, SNo = S.No
(i)
INAME
Mother Board
Hard Disk
LCD
(ii)
AREA
GK II
CP
Nehru place
COUNT(*)
1
2
2
(iii)
(iv)
11.
INAME
DISCOUNT
Keyboard
25
Mother Board
650
Keyboard
20
Hard Disk
225
(a) (i) SELECT Name, Price
FROM ACCESSORIES
ORDER BY Price ASC;
(ii) SELECT ID, Price
FROM SHOPPE
WHERE Area = Nehru Place;
(iii) SELECT MIN (Price) Minimum Price,
MAX (Price) Maximum Price,
Name
FROM ACCESSORIES
GROUP BY Name;
(iv)
SELECT Name, Price, SName
FROM ACCESSORIES A. SHOPPE S
WHERE A. ID = S. ID
(b)
(i)
NAME
Mother Board
Hard Disk
LCD
(ii)
AREA
COUNT(*)
CP
2
GK II
1
Nehru Place
2
(iii)
12.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
FROM PRODUCTS
ORDER BY COMPANY DESC;
(g1)
SUPCODE
S01
S02
S03
(g2)
(g3)
(g4)
13.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
MAX(PRICE) MIN(PRICE)
28000
1100
AMOUNT
550000
PNAME
DIGITAL CAMERA 14X
PEN DRIVE 16 GB
SELECT *
FROM ITEMS ORDER BY INAME;
SELECT INAME, PRICE
FROM ITEMS
WHERE PRICE BETWEEN 10000
AND 22000;
SELECT TCODE, COUNT (*)
FROM ITEMS
GROUP BY TCODE;
SELECT PRICE, INAME, QTY
FROM ITEMS
WHERE QTY >150;
SELECT TNAME
FROM TRADERS
WHERE CITY = MUMBAI OR CITY =DELHI;
SELECT COMPANY, INAME
FROM ITEMS
OREDER BY COMPANY DESC;
(g1)
MAX (PRICE)
MIN (PRICE)
38000
1200
(g2)
AMOUNT
1075000
(g3)
TCODE
T01
T02
T03
(g4)
14.
(a)
SNAME
GET ALL INC
GET ALL INC
INAME
TNAME
LED SCREEN 40
DISP HOUSE INC
CAR GPS SYSTEM ELECTRONIC SALES
(b)
(c)
(d)
(e)
(f)
(g)
WHERE JOINYEAR<2010;
SELECT NAME
FROM APPLICANTS
WHERE FEE >30000;
SELECT NAME
FROM APPLICANTS
ORDER BY JOINYEAR;
SELECT JOINYEAR, COUNT (*)
FROM APPLICANTS
GROUP BY JOINYEAR
SELECT C_ID, COUNT (*)
FROM APPLICANTS
ORDER BY C_ID;
SELECT NAME, COURSE
FROM APPLICANTS, COURSES
WHERE APPLICANTS. C_ID=COURSES.C_ID;
(g1)
NAME
JOINYEAR
Avisha
2009
(g2)
MIN (JOINYEAR)
2009
(g3)
AVG(FEE)
31666.666
(g4)
15.
SUM(FEE)
55000
C_ID
A01
(b) (i)
COUNT (DISTINCT Make)
4
(ii)
MAX (Charges)
MIN (Charges)
35
12
(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 following result.
COUNT(*)
5
(iv)
VehicleName
SX4
C-Class
16. (a) (i) SELECT CarName
FROM CARDEN
WHERE Color = SILVER;
(ii) SELECT CarName, Make, Capacity
FROM CARDEN;
ORDER BY Capacity DESC;
(iii) SELECT MAX (Charges)
FROM CARDEN;
(iv) SELECT CName, CarName
FROM CARDEN, CUSTOMER
WHERE CARDEN.Ccode = CUSTOMER.Ccode;
(b)
(ii)
(i)
MIN (Charges)
12
(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
(iii) NAME
Abdul Ahmad
Ravi Chander
(iv)
18.
SGRADE
S02
SALARY+HRA
44000
MAX(DOB)
12-JUL-1987
MIN (DOJ)
13-SEP-2004
(iii)
NAME
RadheShyam
ChanderNath
26000
12000
PLEVEL
P003
PAY+ALLOWANCE
18000
(iv)
19.
SALARY
24000
32000
(a)
(i)SELECT *
(iii)
Rate * Qty
880
Item
Sname
PAY
20.
MAX(Lastbuy)
24-FEB-10
21.
(i)
DEPARTMENT
CITY
MEDIA
DELHI
INFRASTRUCTURE MUMBAI
(viii)
MAX(DOJ)
2014-06-09
MIN(DOB)
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
1
0
0
1
1
1
0
1
0
1
1
1
0
0
1
6. Write the POS form of boolean function G, which is represented in a truth table as follows:
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
G
0
1
1
0
0
0
1
1
7. Write the SOP form of Boolean function F, which is represented in a truth table as follows:
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
F
1
0
1
0
1
0
0
1
8. Write the POS form of a boolean function F, which is represented in truth table as follows:
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
F
0
1
1
0
1
0
0
1
9. Write the SOP form of a boolean function F, which is represented in a truth table as follows:
A
0
0
0
0
1
1
1
B
0
0
1
1
0
0
1
C
0
1
0
1
0
1
0
F
1
0
0
1
0
0
1
10. Write the SOP form of a boolean function F, which is represented in a truth table as follows:
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z F(X,Y, Z)
0
1
1
0
0
0
1
1
0
0
1
0
0
1
1
1
11. Write the POS form of boolean function H, which is represented in a truth table as follows:
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
H
1
0
1
1
1
0
0
1
12. Write the SOP form of boolean function G, which is represented in truth table as follows:
P
0
0
0
0
1
1
1
1
Q
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
G
0
0
1
1
1
0
1
1
13. Write the POS form of boolean function H, which is represented in a truth table as follows:
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
H
0
1
1
1
1
0
0
1
14. Write the POS form a boolean function G, which is represented in a truth table as follows:
u
0
0
0
0
1
1
1
1
v
0
0
1
1
0
0
1
1
w
0
1
0
1
0
1
0
1
G
1
1
0
0
1
1
0
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)
18. Prove that X . (X + Y) = X by truth table method.
19. Find the complement of the following Boolean function:
F1 = AB CD
20. In the Boolean Algebra, verify using truth table that X + XY for each X, y in (0, 1).
21. In the Boolean Algebra, verify using truth table that (X + Y) + XY for each X Y in (0, 1).
22. Give the dual of the following result in Boolean Algebra
X . X = for each X.
23. Define the followings:
(a) Minterm
(b) Maxterm (c) Canonical form
24. Interpret the following logic Circuit as Boolean expression:
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:
11 Write the equivalent Boolean expression for the following logic circuit:
20. Write the equivalent boolean expression for the following logic circuit:
25.
26. Write the equivalent boolean expression for the following logic circuit:
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 Sumof-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)
6. Reduce the following boolean expression using K-map:
F(P, Q, R, S) = (1, 2, 3, 4, 5, 6, 7, 8, 10)
7. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (2, 3, 4, 5, 6, 7, 8, 10, 11)
8. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (0, 1, 2, 4, 5, 6, 8, 10,)
9. Reduce the following boolean expression using K-map:
F(P, Q, R, S) = (0, 1, 2, 4, 5, 6, 8, 12)
10. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (3, 4, 5, 6, 7, 13, 15)
11. Reduce the following boolean expression using K-map:
F(u, v, w, z) = (3, 5, 7, 10, 11, 13, 15)
12. Reduce the following boolean expression using K-map:
F(P, Q, R, S) = (1, 2, 3, 5, 6, 7, 9, 11, 12, 13, 15)
13. Reduce the following boolean expression using K-map:
H(u, v, w, z) = (0, 1, 4, 5, 6, 7, 11, 12, 13, 14, 15)
14. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (0, 1, 2, 3, 6, 7, 8, 11, 14, 15)
15. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (0,2, 3, 4, 6, 7, 8, 10, 12,)
16. Reduce the following boolean expression using K-map:
F(A, B, C, D) = (0, 1, 2, 4, 5, 8, 9, 10, 11,)
Q
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
F
1
0
0
1
0
0
1
1
Minterm
PQR
PQR
PQ R
PQ R
P QR
P QR
P O R
PQR
Y
0
Z
0
F
1
Maxterm
X+Y+Z
0
0
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
0
1
0
0
1
1
X + Y + Z
X + Y+ Z
X + Y+ Z
X + Y + Z
X + Y+ Z
X + Y+ Z
X + Y+ Z
V
0
0
1
1
0
0
1
1
W
0
1
0
1
0
1
0
1
G
1
0
1
0
1
0
0
1
Maxterm
U + V +W
U + V + W
U + V+ W
U + V+ W
U + V + W
U + V+ W
U + V+ W
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
0
0
0
0
1
1
1
1
V
0
0
1
1
0
0
1
1
W
0
1
0
1
0
1
0
1
G
0
1
0
1
1
0
1
0
Maxterm
U + V +W
U + V + W
U + V+ W
U + V+ W
U + V + W
U + V+ W
U + V+ W
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
0
0
0
0
1
0
0
1
1
0
0
1
0
1
0
Minterm
0
ABC
0
ABC
1
ABC
1
ABC
1
ABC
1
1
1
0
1
1
1
0
1
0
0
1
ABC
ABC
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.
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
0
0
1
1
Maxterm
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
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
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
F
1
0
1
0
1
0
0
1
Minterm
X+Y+Z
X+Y+Z
X + Y+ Z
X+Y+Z
X+Y+Z
X + Y+ Z
X + Y+ Z
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
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
0
1
Maxterm
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
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.
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
0
1
0
0
1
1
Minterm
A .B .C
A .B .C
A .B .C
A .B .C
A .B .C
A .B .C
A .B .C
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
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
F(X, Y,Z)
1
1
0
1
1
0
0
1
Minterm
X+Y+Z
X+Y+Z
X + Y+ Z
X+Y+Z
X+Y+Z
X + Y+ Z
X + Y+ Z
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
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
H
1
0
1
1
1
0
0
1
Maxterm
X+Y+Z
X+Y+Z
X + Y+ Z
X+Y+Z
X+Y+Z
X + Y+ Z
X + Y+ Z
X + Y+ Z
To get the POS form, we need to maxterms for all those input combinations that produce output as
0. Thus,
P
0
0
0
0
1
1
1
1
Q
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
GMinterm
0
P .Q . R
0
P .Q . R
1
P .Q . R
1
P .Q . R
1
P .Q . R
0
P .Q . R
1
P .Q . R
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.
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
1
1
0
0
1
Maxterm
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
A+B+C
To get the POS from, we need to product maxterms for all those input combinations that produce
output as 0. Thus,
H(A, B, C) = (A + B + C). (A + B + C) .(A + B + C).
14.
u
0
0
0
0
1
1
1
1
v
0
0
1
1
0
0
1
1
w
0
1
0
1
0
1
0
1
GMaxterm
1
u + v +w
1
u+v+w
0
u + v+ w
0
u + v+ w
1
u+v+w
1
u + v+ w
0
u + v+ w
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,
15.
16.
17.
18.
X
0
0
1
1
Y
0
1
0
1
X+Y
0
1
1
1
X. (X + Y)
0
0
1
1
From the above table it is obvious that X . (X + Y) = X because both the columns are identical.
19.
20.
21.
Y
0
1
0
1
X+Y
0
0
0
1
X. (X + Y)
0
0
1
1
Comparing the columns X + XY and X, we find, contents of both the columns are identical, hence
verified.
As it is a 2 variable expression, truth table will be as follows:
X
X+Y
(X + Y)
XY
0
0
1
1
0
1
0
1
1
1
1
1
0
0
0
1
1
0
0
1
0
1
0
1
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
25.
F =(W + X) (Y + Z).
26.
27.
28.
29.
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.
X+Y=X.Y
X.Y= X+Y
2
1.
Marks Questions
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.
4.
5.
= A + C. (1+B)
=A+C
= LHS
6.
DeMorgans Laws:
It states that
(i)
(A + B) = A.B
(ii) (A. B) = A + B
Truth table for A + B = A .B
A
0
0
1
1
8.
B
0
1
0
1
A+B (A+B)
0
1
1
0
1
0
1
0
A
1
1
0
0
B
1
0
1
0
A.B
1
0
0
0
9.
10.
X
(i) X + 0 = X
0
0
0
0
1
(ii) X + X = 1
X
X
0
1
1
0
X+0
0
1
So, X + 0 + X
X + X
1
1
As X + X = 1. Hence proved.
11.
X X.X
1
0
(ii) X + 1 = 1
X
1
X+1
0
1
1
1
0
0
As X. X = 0. Hence proved.
1
1
As X + 1 =1.Hence proved.
13.
u .(u+ v) =u +v
u
0
0
1
1
v
0
1
0
1
u
1
1
0
0
u+ v u + v u.(u + v)
1
0
0
1
1
0
0
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.
16.
X + Y.Z= (X + Y). (X + Z)
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
YZ
0
0
0
1
0
0
0
1
X + YZ X + Y X + Z
0
0
0
0
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
(X + Y).(X + Z)
0
0
0
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.
DeMorgans Laws
The two DeMorgansthrorems are:
(i) XY = X + Y
This theorem states, that the complement of a product is equal to sum of complements, i.e.
complement of two or more variables used in AND gate is the same as the OR gate of the
complement of each individual variables.
Truth Table
X
Y
X
Y
XYXYX + Y
0
0
1
1
0
1
0
1
1
1
0
0
1
0
1
0
0
0
0
1
1
1
1
0
1
1
1
0
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.
X
0
0
1
1
Y
0
1
0
1
Truth Table
X+Y
X
0
1
1
1
1
0
1
0
Y
1
0
1
0
X+Y
1
0
0
0
X.Y
1
0
0
0
X.Y + X.Y = (X + Y) . (X + Y)
Taking RHS
(X + Y) . (X + Y)
= X X + X Y + Y X + Y Y
= 0 + X Y + Y X + 0
[X.X' = 0]
22.
= XY + X . Y
= RHS
[X.Y = Y.X]
Hence proved
(A + B) .(A + B) = AB + AB
LHS
(A + B) .(A + B)
=A.A + AB + BA + BB
= 0 + AB + BA + 0
= AB + AB
= RHS
[as A.A = 0]
[as A.B = B.A]
Hence proved
23.
XY +XY +XY + X + Y
X
0
0
1
1
Y
0
1
0
1
As columns
So,
X
1
1
0
1
YXY
1
0
1
0
XY
0
1
0
0
XY
0
0
1
0
XY + XY + XY
1
1
0
1
0
1
0
0
X + Y
1
1
1
0
26.
27.
28.
P
0
0
0
0
1
1
1
1
Q
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
QQR
1
1
0
0
1
1
0
0
P + QRMaxterm
0
0
1
1
0
0
0
0
0
1
1
1
0
1
0
1
P+Q+R
P + Q + R
P + Q+ R
P + Q + R
P + Q + R
P + Q + R
P + Q+ R
P + Q + R
29.
i.e.
30.
31.
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
Y + Z X.(Y + Z)
0
0
1
0
1
0
1
0
0
0
1
1
1
1
1
1
XY
0
0
0
0
0
0
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
YZ X + YZ
0
0
0
0
0
0
1
1
0
1
0
1
0
1
1
1
(u + v + w) .(u + v + w) .(u + v + w)
XY + XZ
0
0
0
0
0
1
1
1
Hence proved
X+Y
XZ
0
0
0
0
0
1
0
1
0
0
1
1
1
1
1
1
X + Z(X + Y)(X + Z)
0
1
0
1
1
1
1
1
0
0
0
1
1
1
1
1
Hence proved
33.
34.
35.
36.
37.
38.
39.
= (1 0 1) .(0 1 1) . (0 0 0)
= M5 .M3 .M0 =(0, 3, 5)
So, SOP expression will be = (1, 2, 4, 6, 7)
= (u .v .w) + (u .v .w) + (u . v .w) + (u .v .w) + (u .v .w)
x y z + x y z + x y z + xyz
x y z + x y z + x yz + xyz + xyz + xyz = x + y
L.H.S. = xy (z + z) + xy (z + z) +xy (z + z)
= xy + xy + xy
(z + z = 1, z + z = 1)
= x (y + y) + xy
= x + xy
(y + y = 1)
= x + (x ) y
(x = (x ))
= x + y
(a + ab = a + b As x + xy = x + y)
= R.H.S. Hence proved.
X + Y = X .1 +Y .1
= X . (Y + Y) + Y(X + X)
(X + X = 1 complementarity law)
= XY + XY + XY + XY
= XY + XY + XY + XY
= XY + XY + XY
(XY + XY + XY Idempotent law)
If three inputs we take as X, Y and Z then
F= m0 + m1 + m2 + m5
m0= 000X Y Z
m1 = 001
XYZ
m2 = 010
XYZ
m5 = 101
XYZ
Canonical S-O-P form of the expression is
XYZ+XYZ+XYZ+XYZ
ABCD + ABCD + ABCD + ABCD
= ABC(D + D) + ABC(D + D)
= ABC .1 + ABC .1
(D + D = 1)
= AC(B + B)
= AC .1 = AC
(B + B = 1)
L.H.S = X . (X + Y)
=X.X+X.Y
= X + X .Y
= X . (1 + Y)
= X .1 = X = R.H.S
= X .1 = X = R.H.S
32.
LHS = X .Y + Y . Z
= X . Y (Z + Z) + (X + X) Y . Z
= XY Z + XYZ + XYZ + XYZ
(X . X = X)
(1 + Y = 1)
(Z + Z = 1 and X + X = 1)
40.
41.
42.
43.
44.
[1 + Y = 1]
[X + Y = Y + X]
= (Z + X) (Z + Y)
45
. (X + Y) . Z =X . Z + Y . Z
[X + YZ = (X + Y) (X + Z)]
3 Marks Questions
1. F(A, B, C, D) = (1, 4, 5, 9, 11, 12, 13, 15)
22.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49. What is the difference between packet switching and circuit switching techniques?
50. (i) Expand the following abbreviations: (a) HTTP (b) VolP
51. Name one commonly used open source Internet browser and one commonly used open source operating
system.
52. Which of the following crime(s) is/are covered under cybercrime?
(i)
Stealing brand new hard disk from a shop.
(ii)
Getting into unknown persons social networking account and start messaging on his behalf.
(iii)
Copying some important data from a computer without taking permission from the owner of the
data.
53. What out of the following, you will use to have an audio visual chat with an expert sitting in a far away place
to fix-up technical issue?
(i) e-mail
(ii) VoIP
(iv)
FTP
54. Name the client side scripting language and one server side scripting language.
55. Which out of the following does not come under cyber crime?
(i) Stealing a mouse from someones computer.
(ii) Operating someones Internet banking account without his knowledge.
(iv)
Entering in someones computer remotely and copying data, without seeking his permission.
56. Write one advantage of star topology of network? Also, illustrate how 5 computers can be connected with
each other using star topology of network.
57. Give one suitable example of each URL and Domain name.
58. Name the two open source software along with its application.
59. Which of the following come under cyber crime?
(i) Operating someones Internet banking account, without his knowledge.
(ii) Stealing a keyboard from someones computer.
(iii) Working on someones computer his/her permission.
60. Write one advantage of bus of network. Also, illustrate how four computers can be connected with each
other using star topology of network.
61. Name two proprietary software along with their application.
62. Message switching technique in network communication.
63. Differentiate between bus and star topology of networks.
64. Out of the following identity client side script(s) and server side scripts(s).
(i) ASP (ii) Java script (iii) VB script (iv) JSP
67. In networking, what is WAN? How is it different from LAN?
68. Differentiate between XML and HTML.
69. What is web 2.0?
70. What is the function of modem?
71. Name any two components required for networking?
72. What are repeaters?
73. What was the role of ARPANET in the computer network?
74. Which of the following is notan unit for data transfer rate?
(i) Bps
(ii) Abps
(iii) Gbps(iv) Kbps
75. What is the difference between Trojan horse and virus in terms of computer?
76. What term we use for a software/hardware device, which is used to block, unauthorized access
while permitting authorized communications. This term is also used for a device or set of
devices configured to permit, deny, encrypt, decrypt, or proxy for all(in and out) computer
traffic between different security domains based upon a set of rules and other criteria.
77. Write the full forms of the following. (i) GNU (ii) XML
78. Which of the following is not a unit for data transfer rate?
(i) Mbps (ii) Kbps (iii) Sbps(iv) Gbps
79. What is the difference between virus and worms in the computer?
80. Write the full forms of the following: (FSF)
81. Name any two common web browsers:
82. What is protocol? Which protocol is used to search information from internet using an
internet browser?
83. Name the two switching techniques used to transfer data between two terminals
(computers).
84. What is the difference between LAN and WAN?
85. Expand the following abbreviations: (i) HTTP (ii) ARPANET
86. Distinguish between web site and web browser?
87. What is Firewall?
88. How is coaxial cable different of optical fibre?
89. How is hacker different from a cracker?
90. Write two advantage and disadvantage of networks.
91. What is ARPAnet ? What is NSFnet ?
92. What do you understand by InterSpace?
93. Name two switching circuits and explain any one.
94. What is communication channel? Name the basic types of communication channels available.
95. What are the factors that must be considered before making a choice for the topology?
96. What are the similarities and differences between bus and tree topologies?
97. What are the limitations of star topology?
98. When do you think, ring topology becomes the best choice for a network?
99. Write the two advantages and two disadvantages of Bus Topology in network.
100. Briefly mention two advantages and two disadvantages of Star Topology in network.
101. Write two disadvantages of twisted pair cables.
102. What is remote login?
103. What is structure of an E-mail message?
104. What is web scripting?
4 Marks Questions
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)
(ii)
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.
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
Block
Conference 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
Block
Human
Resource
Block
Finance Block
4. G.R.K International Inc. is planning to connect its Bengaluru Office Setup with its Head Office in Delhi. The
Bengaluru G.R.K International Inc. is spread across an area if approx.. 1 square kilometers consisting of 3
blocks. Human Resources, Academics and Administration. You as network expert have to suggest answers to
the four queries (i) to (iv) raised by them.
NOTE keep the distances between blocks and number of computers in each block in mind, while providing
them the solutions.
Bengaluru office setup
Human
Resources
Delhi Head
Office
Administration
Academics
5.
Expertia Professional Global (EPG) in an online corporate training provider company for IT related courses.
The company is setting up their new courses in Mumbai. You as a network expert have to study the physical
locations of various buildings and number of computer to be installed in the planning phase, provide the
best possible answers for the queries (i) to (iv) raised by them.
Physical locations of the buildings of EPG
Finance
Building
Administrative Building
Distance
60
120
70
6. Granuda consultants are setting up a secured network for their office campus at Faridabad 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 Kolkata. Answer the questions (i) to (iv) after going throw the building positions in the campus
and other details, which are given below.
Faridabad Campus
Building
RAVI
Building
JAMUNA
Head Office
KOLKATA
Building
GANGA
7.
Work a lot consultants are setting up a secured network for their office campus of Gurgaon for their day-toDay 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
Head Office
MUMBAI
Building
GREEN
Building
RED
Building
Blue
110 m
45 m
65 m
1760 km
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
(a) Switch
(b) Repeater
(iv) The organization is planning to provide a high speed link with its head office situated in the Mumbai using a
wired connection. Which of the following cables will be most suitable for this job?
(a) Optical fibre
(b) Coaxial cable
(c) Ethernet cable
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
Block
Law
Block
Technology
Block
HR
Centre
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
School
Technology
School
Admin
Centre
Law
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
Compound
Main
Compound
Training
Compound
Finance
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
(i) Suggest a cable layout of connections between the compounds.
(ii) Suggest the most suitable place (i.e. compound) to house the server for this NGO. Also, provide a suitable
reasonfor your suggestion.
(iii) Suggest the placement of the following devices with justification.
(iv) The NGO is planning to connect its International office situated in Mumbai, communication link, will you
suggestfor a very high speed connectivity?
(a) Telephone Analog line
(b) Optical fibre
(c) Ethernet cable.
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
Building
Resource
Building
Training
Building
Accounts
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.
Kolkata
Admission
Office
Freshminds
University
Ana Nagar
Campus
Commerce Block
RAVI
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
University
Parampur
Campus
Delhi
Admission
Office
Research Building
RAVI
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:
Lib
Wing
Student
Wing
Admission
Wing
Admin
Wing
150 m
11. CDMA stands for Code Division Multiple Access which is a digital cellular technology that uses spread
spectrum technique. Spread-spectrum is a technique in which data is sent in small pieces over a
number of discrete frequencies available for use. Each users signal is spread over the entire
bandwidth.
12. WLL refers to Wireless in Local Loop. It is a system analogous with local telephone service that
provides telephony by deploying a multicity of multichannel transceivers.
13. 3G is a specification for third generation of mobile communications technology. 3G promises
bandwidth of up to 384 Kbps when a device is stationary, 128 Kbps in a car and 2 Mbps in fixed
applications.
EDGE Enhanced Data rates for Global Evolutionis a radio based high-speed mobile data
standardthat allows data transmission speeds of 384 Kbps to be achieved when all eight timeslots
are used.
14. Hub is a hardware device used to connect several computers together.
Switchis a device used to segment networks into different sub networks called subnets.
15. RJ-45 is short for Registered Jack-45. It is an eight-wire connector, used to connect computers on
LANs especially Ethernets.
16. Cookies are messages that a web server transmits to a web browser so that the web server can keep
track of the users activity on a specific web site.
17. The telnet is an internet facility that facilitates remote login. Remove login is the process of accessing
a network from a remote place without actually being at the actual place of working.
18. (i) Modulator/DeModulator
(ii) File Transfer Protocol
19. A repeater is a device that amplifies a signal being transmitted on the network. It is used in long
network lines, which exceed the maximum rates distance for a single run.
20. It is a device that works like a bridge but can handle different protocols. For example, a router can
link Ethernet with any other type of network.
21. FTP (File Transfer Protocol) transfers files from one system to another. It defines rules for file transfer
both systems.(In which file transfer is taking place) must adhere to.
22. URL refers to Uniform Resource Locator. A URL stores the address of a web page on WWW.
23. HTMLHyperText Markup Language is a document layout and hyperlink specification language, used
for creating web pages.
24. DHTML Dynamic Hyper Text Markup language refers to web content that is dynamic i.e., changes
each time it is viewed.
25. XML is a markup language for creating documents containing structured information.
26. In HTML both tag semantics and tag are fixed but XML specifies neither semantics nor tag
sets.Rather it provides facility to define tags and relationships among them.
27. The system designed to prevent unauthorized access to or from a private network is called a firewall.
28. Cookies are messages that a web server transmits to a web browser so that the web server can keep
track of the users activity on a specific web site.
29. The Crackers are the malicious programmers who break into secure systems whereas Hackers are
more interested in gaining knowledge about computer systems and possibly using this knowledge for
playful pranks.
30. Cyber Law is a generic term, which refers to all the legal and regulatory aspects of Internet and the
World Wide Web.
31. Non-dedicated Servers. It is a workstation on a small network that can double up as a server.
32. Dedicated Server. On bigger networks, a computer is reserved for the cause of serving which is called
dedicated server.
33. The 80-20 rule of network says that: 80% of the traffic on a given network segment should be local
and not more than 20% of the network trafficshould need to move across a backbone i.e., the spine
connecting various subnetworks.
34. Bridge is not a broadcast device, as it filters traffic depending upon the receivers MAC address.
35. Characteristic of 2G mobile technology is that it has introduced data services for mobile, starting with
text messaging.
Characteristics of 3G mobile technology is that it is faster than 2G and supports video calling.
36. Char generally involves one-to-one communication. On the other hand video conferencing means
more than two persons are involved in a discussion.
37. General Packet Radio Service
38. Characteristics of Wi-Fi are as follows:
(i)
It is a wireless solution for getting connected to the internet.
(ii)
It is handly as well as available throughout the journey.
39. In order to chat, you need have an account on the same service as the person you are chatting with,
e.g., on the other hand, in case of e-mail, it is not necessary i.e. you can have an account from any
provider and you can establish your own.
40. When two mobiles are connected using Bluetooth to transfer a picture file, PAN (Personal Area
Network) is created.
41. Following are the two popular open sources used as operating system.
(i)
GNU
(ii) Open Solaris
42. Two characteristics of cloud computing are as follows:
(i)
On demand self-services.
(ii)
It provides the facility to pooled resources together to serve multiple customers with
different physical and virtual resources dynamically assigned and reassigned according to the
customer demand.
43. (i) Open source software is software whose source code is available for customer and it can be
modified and redistributed without any limitations. On the other hand, source code is not available in
proprietary software.
(iii)
open source software are generally free of cost.
44. (ii) Stealing keyboard and mouse from the shop.
45. HTTPis a protocol used to transfer files from a web server onto a browser in order to view a web
page that is on the internet.
FTP is a protocol used to upload files from a workstation to a FTP server or download files from a FTP
server to a workstation.
46. IP address is an identifier for a computer or device on a TCP/IP network. E.g. 1.160.10.240 could be
an IP address. A domain name is a name that identifies one or more IP addresses. e.g. the domain
name Microsoft.com represents about a dozen IP addresses.
47. Two advantages of using optical fibre cables over an Ethernet cable are as follows:
(i)
(ii)
Low power because signals in optical fibres degrade less, low-power transmitters can be used.
Digital SignalsOptical fibres are ideal suited for carrying digital information, which is especially
in computer networks.
48. Proprietary software can be distributed freely by the permission by the owner. User only purchases
the compiled version of this software while the source code for an OSS is open for all, which can be
copied, modified for redistributed.
49. (i) Packet Switching In this there us a fixed size of packet. In this, data packets are stored in the
main memory.
This improves the access time.
(ii) Circuit switching In this, firstly complete physical connection between two computers is
established. After that data are transmitted from the source computer to the destination
computer. E.g. In telephone call, circuit switching is used.
50. (i) (a) HTTP: HyperText Transfer Protocol.
(b) VolP: Voice over Internet Protocol.
51. Open Source Internet Browser: Chromium.
Open Source Operating System:Linux
52. (ii) Getting into unknown persons social networking account and start messaging on this behalf.
53. (ii) VoIP
54. Client Side Scripting Language: VB Script
Server Side Scripting Language: ASP
55. (i) Stealing a mouse from someones computer.
Comp3
Server
Comp2
Comp4
Comp5
Comp1
Comp3
Server
Comp2
Comp4
or more.
73. ARPANET (Advanced Research Projects Agency Network). The goal of this project was to connect
computers at different universities and US defense. ARPANET started with a handful of computer
but it expanded rapidly.
74. (ii) Abps is not unit for data transfer rate.
75. Unlike viruses, Trojan does not replicate them but they can be just a lot destructive. One of the
most insidious types of Trojan is a program that claims to rid your computer of viruses but instead
introduce viruses onto your computer.
76. Firewall
77. (i) GNU GNUs NOT UNIX.
(ii) XML eXtensible Markup language.
78. (iii) Sbps
79. The main difference between virus and worms is the method by which they reproduce and
spread. A virus is dependent upon a boot sector and the transfer of files between machines to
spread, while a worm can run completely independently and spread itself through network
connections.
80. (i) FSF Free Software Foundation
81. Netscape Navigator and Internet Explorer.
82. Protocol is a set of rules that two or more computers must follow to communicate on network.
HTTP(HyperText Transfer Protocol) is used for searching information from internet, using
internet browser.
83. Switching techniques used to transfer data between two terminals.
(i) Circuit switching
(ii) Packet switching
84. LAN The network which is confined to a building or a block is called local area network, e.g.
school.
WANThe network which is spread across country or continent is called wide area network, e.g.
Internet.
85. (i) HTTPHyperText Transfer Protocol.
(ii) ARPANETAdvanced Research Projects Agency Network.
86. WebsiteItis a collection of related web pages served from a single web domain.
Web browserIt is a software that is used to access and display the web pages.
87. Firewall is a security system that prevents an unauthorized access to a private network. Firewalls
can be implemented in both hardware and software or combination of both.
88. The data transmission characteristics of coaxial cable are considerably better than twisted pair
but not better in relation to optical fibre. The coaxial cable is being used as a shared cable
network, with part of the bandwidth being used for data traffic. Optical fibre is difficult to install
because they are fragile and need special care to install. One of the major advantages of optical
fibre over coaxial cable is its complete immunity to noise, because the information is travelling on
a modulated light beam.
89. Hackers These are the persons who get unauthorized access to the websites and replace them
with other websites or unlawful information.
Crackers The person by using certain software to track authenticated information or to crack the
Security codes such as user names and password to illegally access the information of computers
are called crackers.
90. Advantage:
We can share resources such as printers and scanners.
Can share data and access file from any computer.
Disadvantage:
Server faults stop applications from being available.
Department ofDefense.
NSFnetwas developed by the National Science Foundation which was high capacity network and
strictlyused for academic and engineering research.
92. Interspace is a client/server software program that allows multiple users to communicate online
with real time audio, video and text chat I dynamic 3D environments.
93The two switching circuits are
Circuit Switching
Message Switching
Circuit Switching - In this technique, first the complete physical connection between two computers is
Established and then data are transmitted from the source computer to the destination computer.
94. Communication channel mean the connecting cables that link various workstations.
Following are three basic types of communication channels available:
a) Twisted-Pair Cables
b) Coaxial Cables
c) Fiber-optic Cables
95. There are number of factors to consider in before making a choice for the topology, the most important of
which are as following :
(a) Cost.
(b) Flexibility
(c) Reliability
96. Similarities:
In both Bus and Tree topologies transmission can be done in both the directions, and can be received by
all other stations.
In both cases, there is no need to remove packets from the medium.
Difference:
Bus topology is slower as compared to tree topology of network.
Tree topology is expensive as compared to Bus Topology
97. Requires more cable length than a linear topology.
If the hub, switch, or concentrator fails, nodes attached are disabled.
More expensive than linear bus topologies because of the cost of the hubs, etc.
98. Ring topology becomes the best choice for a network when,
Short amount of cable is required.
No wiring closet space requires
99. Advantage:
Easy to connect a computer or peripheral to a linear bus.
Requires less cable length than a star topology.
Disadvantage :
Slower as compared to tree and star topologies of network
Breakage of wire at any point disturbs the entire network
100. Advantage:
Easy to install and wire.
No disruptions to the network when connecting or removing devices.
Disadvantage :
Requires more cable length than a linear topology.
If the hub, switch, or concentrator fails, nodes attached are disabled.
101. Disadvantage :
It is not capable to carrying signal to long distance.
It connects only up to 100 meters.
102. Remote login: Remote login is the process of accessing a network from a remote place without actually
being at the actual place of working.
103. An electronic mail messages is structured very much like a paper letter.
(ii)
(iii)
Firewall OR Router
(iv)
c) Video Conferencing
2.
(i) TTC should install its server in finance block as it is having maximum number of computers.
(ii)
Human Resource
Block
Conference Block
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
Block
Human
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.
Human
Resources
Academics
Administration
(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
Administration
Building
Faculty Studio
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
(iii) Switch
(iv) WAN as it is another city.
HR
Centre
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
Resource
Compound
Finance
Compound
Training
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
Building
Main
Building
Training
Building
Accounts
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
Main
Building
Switch
Training
Building
Switch
Resource
Building
Repeater
Switch
Accounts
Building
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
Wing
Student
Wing
Switch
Repeater
Switch
Re
pe
at
er
Admission
Wing
Switch
Admin
Wing
Switch