KENDRIYA VIDYALAYA NO.2 PORTBLAIR 2017-18
HOLIDAY HOMEWORK
CLASS XII B SUBJECT :COMPUTER SCIENCE
1) What is the difference between Run Type error and Syntax error? Give one example of each.
2) What do you mean by a reference of a variable in C++? Explain how is it created with suitable example?
3) What is the difference between Actual parameter and Formal parameter? Give an example in C++ to illustrate both type of parameters.
4) Rewrite the following program after removing syntactical error(s) if any. Underline each correction #include “iostream.h”
Class MEMBER
{ int Mno;
float Fees;
PUBLIC:
void Register ( )
{cin>Mno>Fees;}
void Display( )
{cout<Mno<" : "<Fees<endl;}
};
void main()
{
MEMBER delete;
Register();
delete.Display(); }
5) Go through the following c++ code, find out the correct possible output(s) from the suggested output options i) to iv).
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
void main()
{ randomize( );
int A[]={4,5,6,7,8,9,10,11};
int N=5;
int num=random(A[N]);
for(int i=num;i>=1;i--)
{ cout<i;
if(i!=1)
cout<','; } }
OUTPUTS
1) 5,4,3,2,1
2) 10,9,8,7,6,5,4,3,2,1
3) 8,7,6,5,4,3,2,1
4) 9,8,7,6,5,4,3,2,1
6) Study the following program and select the possible output from it.
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int Points;
Points = 100 + random(LIMIT);
for (int P=Points; P>=100;P--)
cout<P<“#”;
cout<endl; }
(i) 103#102#101#100#
(ii) 100#101#102#103#
(iii) 100#101#102#103#104#
(iv) 104#103#102#101#100#
7) In the following program, find the correct possible output(s) from the options. Justify your answer. #include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int p=99,q=999;
int x=random(3)+4;
int y=random(2)+2;
for(int i=0;i<x;i++)
cout<’#’;
cout<p<’-’;
for(i=0;i<y;i++)
cout<’@’;
cout<q<endl; }
i. ##99-@999
ii. ##99-@@999
iii. ######99-@@999
iv. ####99-@@@
8) Give the output of the following program ( Assuming that all required header files are included in the program ) :
void PACK(char *str)
{ char ch='A';
int L,M,N;
for(L=0;L<str[L]!='\0';L++);
for(M=0;M<=L;M++)
if(str[M]=='-')
{ for(N=M;N<=L;N++)
str[N]=str[N+1];
M--; }
else
if(isdigit(str[M]))
str[M]=ch++; }
void main( )
{ char STD[ ]="The-STD-code--is-0542";
PACK(STD);
cout<STD<endl;
getch();}
9) Find the output of the following program: (Assuming all header files are included)
void Mycode(char Msg[],char C)
{ for(int i=0;Msg[i]!=’\0’;i++)
{ if(Msg[i]>=’B’ & Msg[i]<=’H’)
Msg[i]=tolower(Msg[i]);
else if(Msg[i]==’A’ || Msg[i]==’a’)
Msg[i]=C;
else
if(i%2==0)
Msg[i]=toupper(Msg[i]);
else Msg[i]=Msg[i-1]; } }
void main() { char text[]=”ApaCHeSeRvEr”;
Mycode(Text,’#’); cout<” New Line = “<text;}
10) Find the output of the following program:
#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; }
11) Define a class Stock in C+ + with the following description:
Private Members
· ICode of type integer (Item Code)
· Item of type string (Item Name)
· Price of type float(Price of each item)
· Qty of type integer (quantity in stock)
· Discount of type float (Discount percentage on the item)
· A member function FindDisc( ) to calculate discount as per the following rule:
If Qty<=50 Discount is 0
If Qty (51 to 100) Discount is 5 %
If Qty>100 Discount is 10 %
Public Members:
· A constructor to assign all values with 0 and null respectively
· A function Buy( ) to allow user to enter values for ICode, Item, Price, Qty and call function FindDisc( ) to calculate the discount.
· A Function ShowAll( ) to allow userto view the content of all the data members.
12) Define a class Applicants with the following information:
Private members
rollno of type int
Name of type character with size as 30
Category of type character (‘G’ for general , ‘S’ for Schedule caste , ‘T’ for Schedule Tribe)
Fees of type Float
Public members
A constructor to initialise category as a blank character and fees as 0.
A function to input Roll number , name and category of the student, and to calculate fees of the student on the basis of category entered as :
Category ‘G’ then Fees is 12000
Category ‘S’ then Fees is 4000
Category ‘T’ then Fees is 3500
A function to display all the information of the applicant.
13) Define a class STATE in C++ with following description :Private members :
· Name of state (type string)
· Population (long int)
· Number of girls under 16 years of age attending school (long int)
· Total number of girls under 16 years of age (long int)
· A member function CALC_PER( ) to calculate & return the percentage of girls attending the school as ( Number of girls attending the school/Total number of girls*100)
Public members :
Ø A constructor to initialize name of the state as “NOT ALLOTTED”
Ø A function INSTATE( ) to allow user to enter data for all data members
Ø A function OUTSTATE( ) to allow user to view the content of all the data members along with the percentage of girls attending the school.
14) Define a class Tourist in C++ with the following specification :
Data Members
· Carno – to store Car no.
· Origin – to store Place name
· Destination – to store place name
· Type – to store care type such as ‘E’ for Economy
· Distance – to store distance in Kilometer
· Charge – to store Care fare
Member Functions
· A constructor function to initialize Type as 'E' and carno as 250
· A function CalcCharge() to calculate Fare as per the following criteria :
Type Charge
'E' 16*Distance
'A' 22*Distance
'L' 30*Distance
· A function Enter() to allow user to enter values for Carno, Origin, Destination, Type and Distance. Also, this function should call CalcCharge() to calculate Fare.
· A function Show() to display the content of all the data members on screen.
15) Define a class RESTRA in C++ with following description:
Private Members
· FoodCode of type int
· Food of type String
· FType of type string
· Sticker of type string
· A member function GetSticker() to assign the following values for Sticker as per the given FType:
Ftype / StickerVegetarian / GREEN
Contains Egg / YELLOW
Non-Vegetarian / RED
Public Members
· A function GetFood() to allow user to enter values for FoodCode,Food,FType and call function GetSticker() to assign Sticker.
· A function ShowFood() to allow user to view the content of all data members