Thursday, 25 February 2016

11th & 12th CS 2012 (Outside Delhi) Common Assignment



1(a)
Give the difference between the type casting and automatic type conversion. Also, give a suitable C++ code to illustrate both.
2
Ans
Type Casting
Automatic Type Conversion
Explicitly converting an expression of a given type into another type is known as type casting.

Example:
Float f=7.9;
int c=(int)f;
cout<<c;

Output:
7
Implicitly converting data type to another by assigning
to a variable of another type.

Example:
Char x=’A’;
int c=x;
cout<<c;

Output:
65

(b)
Which C++ header file(s) are essentially required to be included to run/execute the following C++ source code (Note: Do not include any header file, which is/are not required):

void main ()
{  
char Text[]=”Something”;
cout <<”Remaining SMS chars:“<<160-strlen (Text)<<endl;
}
1
(c)
Find the output of the following program:
#include<iostream.h>
#include<conio.h>      
typedef char str80[80];
void main()      
{
char *Notes;
str80 str=”vR2GooD”;
int L=6;
Notes=str;
while(L>=3)
{
str[L]=(isupper(str[L])?tolower(str[L]):
cout<<Notes<<endl;
L--;
Notes++;
}
}
2
Ans
(Full 2 marks)
(1½ marks)
(1½ marks)
(1½ marks)
vR2Good
R2GoOd
2GOOd
gOOd
v
R
2
g
vR2Good
vR2GoOd
vR2GOOd
vR2gOOd
vR2GooD
R2GooD
2GooD
GooD


(d)
Observe the following program and find out, which outputs out if (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable chance?
#include<iostream.h>
#include<stdlib.h>
void main()
{
randomize();
int Arr[]={9,6},N;
int Chance=random(2)+10;
for(int C=0;C<2;C++)
  N=random(2);
  cout<<Arr[N]+Chance<<”#”;
 }
}                 
(i)9#6#
(ii)19#17#
(iii)19#16#
(iv)20#16#


Ans
The outputs not expected from the program are (i),(ii)and(iv)
Minimum value of chance=10
Maximum value of chance=11



            

No comments:

Post a Comment