Computer Science 18
Computer Science 18
General Instructions :
All the questions are compulsory
The Question paper contains 7 Questions.
Programming language used : C++
OR
(g) Write names of any two popular open source software, which are used
as Operating System. 1
OR
(b) Out of the following, find those identifiers, which can be used for naming
variables, constants or functions in a C++ program : 2
For, Switch, case, A#num, else, 10books, include, define
OR
(b) (i) Convert the following if else to a single statement using conditional 1
operator :
if (marks >= 90)
Grade = 'A';
else
Grade = 'B';
(ii) What is debugging? 1
(c) Observe the given code and replace multi line comment with single
line comment : 1
void main ()
{ float percentage ;
cout<<"\n Enter the percentage";
cin>>percentage;
/* Following condition is giving the message for eligibility for
admission.*/
if (percentage >= 70 && percentage <=100)
{ cout<<"\n Eligible for admission";
}
}
(d) Observe the following loops and find the number of times these loops
will execute? 3
(i) Loop 1
for (int i = –12; i<=0; i++)
{
cout<<++i<<endl;
}
3. (a) Observe the following program very carefully and write the names of
those header file (s), which are essentially needed to compile and execute
the folowing program successfully : 2
void main ()
{ char ch = 'R';
char str [20]; gets (str);
cout<<tolower (ch);
cout<<strlwr(str);
}
xi-computer science (3)
(b) Write C++ statements/expressions for the following : 1+1=2
(i) Declare a varialbe Account_Type and assign a value "Saving".
(ii) Declare and assign variable cost in such a way that only positive
values can be assigned.
OR
(c) Find and write the output of the following C++ Program code : 3
Note : Assume all required header files are already included in the
Program.
int x = 10;
void main ()
{
int x = 5, y =5;
cout<<x++;
cout<<",";
cout<<++::x;
cout<<",";
cout<<y%::x<<","<<- -::x;
cout<<",";
y=(x>::x)? x++:++x;
cout<<y<<","<<x;
}
OR
−b + b 2 − 4ac
x=
2a
(e) Consider the part of code below : 1+1=2
double length;
int breadth;
cin>>length >>breadth;
cout<<length *breadth; // statement 1
cout<<(int)length * breadth; // statement 2
(i) Write the resultant data type of the value of statement 1 and
statement2.
(ii) Identify the type of conversion in statement 2.
OR
(b) Rewrite the correct code after removing the errors and underline the
correction in following code : 2
#include<iostream.h>
void main ()
int count [30], S=0;
count = {15, 6, 60, 75, 80};
for (p = 0; p<5; p++)
{
if (count[p]%2 = 0)
S = S+count[p];
}
cout<<S;
}
(c) Write a program in C++ to accept an integer array of 7 elements
and interchanges elements is such a way that the first element is
swapped with the last, second element is swapped with the second
last element & so on, only if any one or both the elements are odd. 3
e.g. if array of seven elements is :
7, 18, 6, 9, 21, 10, 4
After execution of the above program, the contents of the array
will be :
4, 18, 21, 9, 6, 10, 7
5. (a) Observe the following program carefully and attempt the given
questions : 2
Note : Assume all the required header files are already included in the code.
void main ()
{
randomize();
int val []={450, 550, 650, 750};
int index;
for (int i=1; i<=3; i++)
{
index = random (i)+1;
cout<<val [index]<<"\t";
}
}
(i) Out of all the four values stored in the array val, which value will
never be displayed in the output and which value would be most
likely be displayed in the output?
xi-computer science (7)
(ii) Mention the minimum and maximum value assigned to the variable
index?
OR
(a) What is the benefit of using default parameter / argument in a function?
Give a suitable example to illustrate it using a C++ code. 2
(b) Find and write the output of the following program code : 2
Note : Assume all required header files are already being included in
the program.
void main ()
{
int Ar[] = {10, 12, 15, 21};
for (int i=0; i<4; i++)
{
if (Ar[i]%2==0)
Ar[i]/=2;
else if (Ar[i]%3==0)
Ar[i]+=3;
if (Ar[i]%5==0)
Ar[i] – = 5;
}
for (i=0; i<4; i++)
cout<<Ar[i]<<"#";
}
OR
(b) Find and wirte the output of the following program code : 2
Note : Assume all required header files are already included in the program.
void MyStr (char str[], char CH)
{
for (int i=0; str[i]! = '\0'; i++)
{
if (str [i]>='C' && str [i] <='H')
str [i] = tolower (str [i]);
(c) What is the difference between actual and formal parameter? Give a
suitable example to illustrate using a C++ code. 2
(d) Convert the following C++ code using switch case statements : 2
void main ()
{ char ch;
cout<<"\n Enter your choice to select subjects (a, b, c)" ;
cin>>ch;
if (ch=='a' ||ch=='b')
{ cout<<"Mathematics";
}
else if (ch=='c')
{ cout<<"History";
}
else
{
cout<<"Please enter valid choice";
}
}
OR
xi-computer science ( 10 )
{
int L, B, H;
};
void HallIn(Hall & R, int Val = 1)
{
R.L +=val;
R.B – = val;
R.H += R.L.
}
void HallOut (Hall & R, int val =1)
{
R.L – = val;
R.B+ = val;
R.H –=R.L;
}
void main ()
{ Hall H1 = {10, 20, 5}, H2 = {30, 10, 40};
HallIn (H1);
HallOut (H2, 5);
cout<<H1.L<<","<<H1.B<<","<<H1.H<<endl;
cout<<H2.L<<","<<H2.B<<","<<H2.H<<endl;
HallIn (H2, 10);
cout<<H2.L<<","<<H2.B<<","<<H2.H<<endl;
}
OR
(a) Observe the following C++ code very carefully and rewrite it after
removing any / all syntactical errors with each corrections underlined.
Note : Assume all header files are already being included in the program.
structure Item
{
int item_no=501;
char item_name[20];
float price;
}
xi-computer science ( 11 )
void main ()
{
I Item;
cout<<"Enter Item No. =";
cin>>I.item_no;
cout<<"Enter Item Name =";
gets (Item_name);
cout<<"Enter price=";
cin>>price.I;
}
(b) Define a structure Travel to store information about travelers. The structure 4
has following data elements :
Data Item Type
t_no char[10]
t_Name char[30]
fare double
Write function definitions for the following :
void Input (Travel t[10]) to input details of 10 travelers.
void show_Details (Travel t[10]) to display details of the travelers who are
paying fare more than 20000.
xi-computer science ( 12 )