Académique Documents
Professionnel Documents
Culture Documents
1. a) Look at the following C++ code and find the possible output(s) from the options (i) to (iv)
following it. Also, write the maximum values that can be assigned to each of the variables N
and M. [ 2]
Note: Assume all the required header files are already being included in the code.
The function random (n) generates an integer between 0 and n 1.
void main()
{ randomize ();
int N=random(3),M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for (int R=0; R<N; R++)
{
for (int C=0; C<M; C++)
cout<<DOCK[R][C]<<" ";
cout<<endl; } }
I) 1 2 3 ii) 1 2 3
2 3 4 2 3 4
3 4 5
iii) 1 2 iv) 1 2
2 3 2 3
3 4
2. Answer the following question (i) to (iv) based on the following code: [4]
class student
{
int regno;
public:
char name[20];
void enterstud();
void display();
};
class fest
{
char event[20];
long double prize;
void alterfest();
protected:
float avgpoints;
public:
void enterfest();
void displayfest();
};
class sports:public student,fest
{
char coach;
long salary;
public:
void entersports();
void display();
};
3. An array is declared as float Num[40][60] and is stored column wise.Find the address of
Num[30][20],if the address of Num[10][50] is stored at 28000.Also find the total number of
bytes allocated for the array Num in memory. [3]
4. Write a used defined function named Enot() to display those words not starting with E or e in
uppercase from a text file named Notes.Txt. [2]
For example: if the file Notes.txt contains
Learn to RESPECT every drop of water either from the SKY or from the EYE
The output should be
LEARN TO RESPECT DROP OF WATER FROM THE SKY OR FROM THE
5. Anil typed the following C++ code and during compilation he found three errors as follows:
(i) Function strlen should have prototype (ii) Undefined symbol cout (iii) Undefined symbol
endl . On asking, his teacher told him to include necessary header files in the code. Write the
names of the header files, which Anil needs to include, for successful compilation and
execution of the following code : [ 1]
void main() {
char Txt[] = "Welcome";
for(int C= 0; C<strlen(Txt); C++)
Txt[C] = Txt[C]+1;
cout<<Txt<<endl; }
6.Find and write the output of the following C++ program code : [3]
Note: Assume all required header files are already being included in the program.
void main()
{
int *Point, Score[]={100,95,150,75,65,120};
Point = Score;
for (int L = 0; L<6; L++)
{ if ((*Point)%10==0)
*Point /= 2;
else
*Point -= 2;
if((*Point)%5==0)
*Point /= 5;
Point++; }
for(int L = 5; L>=0; L--)
cout<<Score[L]<<"*";
}
7. Write the definition of a class BOX in C++ with the following description: [4]
Private Members
- BoxNumber // data member of integer type
- Side // data member of float type
- Area // data member of float type
- ExecArea() // Member function to calculate and assign
// Area as Side * Side
Public Members -
GetBox() - // A function to allow user to enter values of
// BoxNumber and Side. Also, this
// function should call ExecArea() to calculate
// Area
(i) Which type of Inheritance out of the following is illustrated in the above example? Single Level
Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the member functions, which are directly accessible by the object T of
class Third as declared in main () function.
(iii) Write Statement 2 to call function Display () of class Second from the object T of class Third.
(iv) What will be the order of execution of the constructors, when the object T of class Third is
declared inside main ()?
9. Out of the following find those identifiers, which cannot be used for naming variables or functions
in a C++ program: [2]
Total*Tax, While, class, switch, 3rdRow, finally, Column31, _total
10. Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction. [2]
Note: Assume all required header files are already being included in the program.
16. )Observe the program segment given below carefully, and answer the question that follows class
Applicant [1]
{ long Aid ; // Applicants Id
char Name[20] ; // Applicants Name
float Score ; // Applicants Score public ;
void Enroll( ) ;
void Disp( ) ;
void MarksScore( ) ; //Function to change Score
long R_Aid( )
{ return Aid; )
};
void ScoreUpdate (long Id)
{ fstream File ;
File.open (APPLI.DAT , ios :: binary | ios :: in | ios :: out) ;
Applicant A ;
int Record = 0, Found = 0 ;
while (!Found && File.read ( (char*)&C, sizeof(c) ) )
{ if (Id = = A.R_Aid( ) )
{ cout << Enter new Score ;
A.MarksScore( ) ;
____________ //Statement 1
____________ //Statement 2
Found=1;
}
Record++ ;
} if (Found = = 1)
cout << Record Updated ;
File.close( ) ;
}
Write the Statement 1 to position the File Pointer at the beginning of the Record for which the
Applicants Id matches with the argument passed, and Statement 2 to write the updated record at
that position.
17. Write the function AECount( ) in C++, which should read character of a text file NOTES.txt, should
count and display the occurrence of alphabets A and E (including small case a and e too) [2]
A:1
E:7
18. Write a function in C++, which accepts an integer array and its size as parameters and rearranges
the array in reverse. [2]
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 the array as 10, 12, 8, 7, 6, 1, 5, 2, 4
19.
An array T [15][10] is stored along the row in the memory with each element requiring 8 bytes of
storage. If the base address of array T is 14000, find out the location of T [10][7]. [3]
20. Obtain the output of the following C++ program as expected to appear on the screen after its
execution. [2]
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;
}
21. (a) What do you understand by Data Encapsulation and Data Hiding? Also, give an example in C+
+ to illustrate both. [2]
Public Members:
*A function enrollment() to allow users to enter values for Enrollno, Name, Style and call function
chkfee()to assign value of fee variable according to the Style entered by the user.
*A function display() to allow users to view the details of all the data members.
23. Write a function in C++ to search for a camera from a binary file "CAMERA.DAT" containing the
objects of class" CAMERA (as defined below). The user should enter the Model No and the function
should search display the details of the camera. [3]
class CAMERA {
long ModelNo;
float MegaPixel;
int Zoom;
char Details[120];
public:
void Enter ( )
{cin>>ModelNo>>MegaPixel>>Zoom;
gets(Details); }
void Display ( )
{cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;
}
long GetModelNo ( )
{return ModelNo;
}
};
27. 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;
}
Test(char P[])
{ strcpy(Paper, P);
Marks=0;
}
Test(int M)
{ strcpy(Paper, Computer)
Marks=M;
}
Test(char P[],int M)
{ 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? [1]
(ii)Write statements in C++ that would execute Function 2 and
Function 4 of class Text. [2]