Você está na página 1de 3

KENDRIYA VIDYALAYA IIT CAMPUS, CHENNAI – 36

Achievement Test-IV
XII Computer Science(083)
Time:1:30Hrs M.M:35
1. a. Observe the following C++ code carefully and obtain the output, which will appear on the 2
screen after execution of it.
#include<iostream.h>
void main(){
int arr[]={7,5,8,6,2},*p,i;
char *str="OLYMPIAD";
p=arr;
for(i=0;i<5;i++)
{ if(*p%2==0)
*p += i;
else
*p -= i;
p++;
}
cout<<arr[0]<<' '<<str<<endl;
p-=3;
str += 4;
cout<<*p<<' '<<str<<endl;

b. Observe the following C++ code carefully and rewrite the same after removing all the syntax 2
error(s) present in the code. Ensure that you underline each correction in the code.
#include<fstream.h>
class Car{
int cno;
void company[10];
float price;
void Car //constructor
{
cno,price=0;
}
void getCar()
{
cin>>cno>>company>>price;
}
};
void main(){
Car c1,c2;
c1.getCar();
c2.getCar();
}
c. Observe the following C++ code carefully and obtain the output, which will appear on the 3
screen after execution of it.
#include<iostream.h>
void main(){
int a[]={75,13,33,65,43}, i;
int *ptr=a;

Page 1 of 3
while(*ptr<43){
if(*ptr%3)
*ptr += 2;
else
*ptr += 1;
ptr++;
}
for(i=0;i<4;i++){
cout<< a[i] <<'*';
if(i%3==0)
cout<<endl;
}
cout<<a[i] + 3<<endl;
}
d. Observe the following C++ code carefully and obtain the output, which will appear on the 2
screen after execution of it.
Important Note :
All the desired header files are already included in the code, which are required to run the code.
void main ( )
{
char *String="HELLO";
int *Point,Value[]={20,10,30,40};
Point= Value;
cout<<*Point<<String<<endl;
String++ ;
Point++ ;
cout<<*Point<<String<<endl ;
e. Write a function CountHisHer ( ) in C++ which reads the contents of a text file diary.txt and 2
counts the words His and Her (not case sensitive).
For example, if the file contains :
Pinaky has gone to his friend's house. His friend's name is Ravya . Her house is 12 KM from
here.
The function should display the output as
Count for His : 2
Count for Her: l
2. a. Write a function in C++ to read the content of a text file "DELHI.TXT" and display the number 2
of lines on screen, which are either starting with 'P' or starting with 'T'.
b. Write the output of the following C++ code. 2

c. 4
3. a. An array A[-3…10][-2…1] of type integer is stored along column. Find the address of A[4][1] if 3
the address of A[0][0] is 2000.
b. 3
c. Write a function Arrange(int a[],int size) in C++ which will arrange all even elements of the 3
array towards the left side of the array and all odd elements of the array towards the right side of
the array in the same order they appear in the original array.
For example: if the original array is:
11 25 10 2 63 45 20
Then after rearranging it should be:
10 2 20 11 25 63 45
d. 2

Page 2 of 3
4. a. Write a function in C++ which opens a Text File "Sample.txt" and finds the number of vowels 2
and consonants in it.
b. Write a function in C++ which opens a binary file "All.dat" and copies the records which have 3
checked value as "true" from the file "All.dat" to another file "Check.dat", other records should
not be copied. The file "All.dat" contains the object of following class as its records:
class Correction
{ int rollno;
char name[30];
char subject[30];
char checked[20];
public:
char * Rchecked(){return checked;}
};

Page 3 of 3

Você também pode gostar