Professional Documents
Culture Documents
Bharatiya Vidya Bhavan - Middle East: Holiday Assignment 2019-20
Bharatiya Vidya Bhavan - Middle East: Holiday Assignment 2019-20
Class: XII
I. Do the Project and show its execution immediately after Half Yearly Examination
II. Write down the answers for the following questions in a thin ruled notebook. Write the questions with
black ink and answers with blue ink.
III. Submission date: - 2 September 2019
2. In the following C++ program what is the expected value of myscore from options
(i) to (iv) given below.
#include<stdlib.h>
#include<iostream.h>
void main( ) {
randomize( );
int score[]={ 25, 20,34,56, 72, 63};
int myscore=score[2+random(2)];
cout<<myscore<<endl;
}
i. 25
ii. 34
iii. 20
1
iv. None of these
#include<string.h>
#include<iostream.h>
#include<ctype.h>
void change(char msg[ ], int len) {
for( int count=0;count< len;count++) {
if(islower(msg[ count]))
msg[count]=toupper(msg[count]);
else if(isupper(msg[ count]))
msg[count]=tolower(msg[count]);
else if(isdigit(msg[ count]))
msg[count]=msg[count]+1;
else
msg[count]= ‘*’; } }
void main( ) {
char message[ ]= “15th AugusT CelebratED”;
int size= strlen( message);
change(message,size);
cout<<message<<endl;
for( int c=0,r=size-1;c<=size/2; c++,r--) {
char temp=message[c];
message[c]=message[r];
message[r]=temp; }
cout<<message<<endl; }
4. What is the difference between call by value and call by reference? Give example.
5. Rewrite the corrected code for the following program. Underline each correction.
#include<iostream.h>
structure club{
2
int mem number;
char memname[20];
char memtype[] = “HELLO”;};
void main( ){ club p1, p2;
cin<<”Member Number:”;
cin>>memnumber.p1;
cout<<”Member Name:”;
cin>>p1.membername;
p1.memtype = “WORLD”;
p2 = p1;
cin<<”Member Number:”<<p2.memnumber;
cin<<”Member Name:”<<p2.memname;
cin<<”Member Number;”<<p2.memtype; }
7. Rewrite the following program after removing the syntactical error(s), if any.
Underline each correction.
# include <iostream.h>
void main(){ struct STUDENT {
8. What is the difference between global and local variables? Give an example to
illustrate the same.
3
int F = 0, S = 0;
do{ int Rem = NUM% 10;
if (Rem % 2 !=0)
F+ =R;
else
S+ = R;
NUM/=10;
} while(NUM>0);
cout<<F-S;}
12. Answer the questions (i) and (ii) after going through the following class:
class Interview
{ int month;
public:
Interview (int y) {month=y ;} //Constructor 1
Interview (Interview &t); //Constructor 2
};
13. Define copy constructor. Mention the conditions where a copy constructor is
invoked.
14. Define a class named ADMISSION in C++ with the following descriptions:
Private members:
AD_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
4
CLASS Character
FEES Float
Public Members:
What is the output if the file content before the execution of the program is the
string “ABC” (Note that” “are not part of the file)
class ABC {
int x=10;
float y;
ABC( ) {y=5;}
~( ) { } }
void main( ) {
ABC a1,a2; }
5
class ci {
int l;
public: ci(int j){ l=j}
ci(ci &v) { l=v.l}
void initialize( ) { l=0;} };
void main( ) {
ci orig(1);
ci x(orig);
ci a=orig; }
Referring to the sample code above, What initializes the object x.
i. initialize( ) function
19. Following is the structure of each record in a data file named “COLONY.DAT”.
struct COLONY
{ char Colony Code[10];
char Colony Name[10];
int No of People;};
Write a function in C++ to update the file with a new value of No _of_People. The
value of Colony_Code and No_of_People are read during the execution of the
program.
20. Write a function to count the number of words present in a text file named
“PARA.TXT”. Assume that each word is separated by a single blank/space
character and no blanks/spaces in the beginning and end of the file.
21. Illustrate the use of inline function in C++ with the help of an example.
Rewrite the following program after removing the syntactical error(s), if any.
22.
6
Underline each correction.
#include <iostream.h>
void main( )
{ struct movie
{ char movie_name [20];
char movie type;
int ticket cost = 100;
}MOVIE;
gets(movie_name);
gets(movie_type); }
Private Members:
Playcode integer
Playtitle 25 character
Duration float
Noofscenes integer
Public members:
A constructor function to initialize duration as 45 seconds and noofscene as 5.
24. Observe the following program RANDNUM.CPP carefully. If the value of VAL
entered by the user is 10, choose the correct possible output(s) from the options
from i) to iv) and justify your option.
//program RANDNUM.CPP
#include<iostream.h>
7
#include<stdlib.h>
#include<time.h>
void main() {
randomize();
cin>>VAL;
Rnd=8 + random(VAL) * 1;
while(n<=Rnd) {
cout<<n<< “\t”;
n++; }}
output options:
i) 1 2 3 4 5 6 7 8 9 10 11 12 13
ii) 0 1 2 3
iii) 1 2 3 4 5
iv) 1 2 3 4 5 6 7 8
#include<ctype.h>
#include<conio.h>
#include<string.h>
char *ptr=Text;
int length=strlen(Text);
8
void main() {
clrscr();
int position=0;
PointersFun(Data, position);
cout.write(Data + 3, 4); }
9
S1.display ( );
S2.display ( );}
29. Define a class named HOUSING in C++ with the following descriptions:
Private members
REG_NO integer(Ranges 10 — 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
10
REGNO from the array.
30. Answer the questions (i) to (iii) based on the following code:
class furniture{
char Type;
char Model[10];
public:
furniture();
void Read_fur_details( );
void Disp_fur_details( );};
class sofa : public furniture {
int no_of_seats;
float cost_of_sofa;
public:
void Read_sofa_details( );
void Disp_sofa_details( );};
class office: private sofa {
int no_of_pieces;
char delivery_datel10l;
public:
void Read_office_details( );
void Disp_office_details( ); };
void main( ){ office MyFurniture; }
(a) Mention the member names which are accessible by MyFurniture declared
in main () function.
(c) Mention the names of functions accessible from the member function
Read_office_details () of class office.
31. Write a function to count the number of spaces present in a text file named
11
“PARA.TXT”.
33. Find the output of the following program: #include < iostream.h>
void main( ){ int *Pointer Array [10];
int marks [ ]= {75, 68, 90, 34, 0, 10, 90, 65};
for (int I = 0; marks [ I]!=0; I++) {
PointerArray [I]=&marks[I];
* (PointerArray [I] ) += 5; }
int index = 0;
while(index < I )
{ int p=*(PointerArray[index] );
if(p >=60) cout <<p<<’,’;
index ++; }}
34. What is the importance of constructor in object oriented programming? Explain
with the help of an example.
35. How does invoking of constructor differ in inheritance and containership? Give
example.
36. Write a function in c++ to search and display details of all trains, whose
destination is “Delhi” from a binary file “TRAIN.DAT”. Assuming the binary file is
containing the objects of the following class:
38. Define any two features of OOPs. Also give suitable example in C++.
12
39. Name the header file(s) that shall be needed for successful compilation of the
following C++ code.
void main(){
int a[10];
for(int i=0;i<10;i++) {
cin>>a[i];
if(a[i]%2==0)
a[i]=pow(a[i],3);
else
a[i]=sqrt(a[i]);
if(a[i]>32767)
exit(0); }
getch(); }
40. Rewrite the following program after removing syntactical error(s) if any. Underline
each correction.
#include<iostream.h>
type def int integer;
struct number {
int a [5]={1,2,3,4,5}; }
void main(); {
number x
for(int i=0;i<5;i++)
cin>>x[i].a;
for(int j=0; j<5, j++)
cout>>a[i]>>”\t”;
getch(); }
41. Write a function in C++ to open binary file “stock.dat”, which contains a set of
records of following structure Products. The function will display the full records
having the type as “Electronics”.
struct Products
{ int id;
char Iname[30];
int type;
};
13
42. Define a function which take a single dimensional array as its argument and
display the number of digits in each element in the array
43. Define a function which take a single dimensional array as its argument and
returns the element which occurs the maximum number of times in the array.
44. An array P[-2..50][-1..20] is stored in the memory along the column with each
element occupying 2 bytes. Find out the base address and address of element
P[12][7], if an element P[3][4] is stored at the memory location 4200. Find the total
number of elements stored in P and number of bytes allocated to P.
14