C++---XI
Computer Fundamentals
1. What is an OS? Give two examples. (KNO)
2. What is the difference between compiler and interpreter? (UND)
3. What is application software describe the use of any 3. (UND)
4. What is the main difference between RISC and CISC microprocessors? (UND)
5. How is RAM different from ROM? (UND)
6. How and why is cache memory used? (KNO)
7. Why is secondary memory needed? (KNO)
8. State important functions of an OS. (KNO)
9. State different parts of a CPU and explain function of each part . (KNO)
10. Is SOLAIS a hardware ?(KNO)
Number System
Q1. Convert the following binary numbers into decimal numbers, and octal numbers:
a. 1100110
b. 11001010
Q2. Convert the following decimal numbers into binary numbers, and hexadecimal numbers:
a. 75
b. 55
Q3.
Perform the following conversions
a) (2BC2)16 = ( )10
b) (EB4A)16 = ( ) 2
c)(288) 2 = (
)8
d) (426)8 = (
)10
e) (1111011110101)2 = (
)8
f) Find the 8 bit 2complement of the decimal no. 21
C++ Basic (2 Marks/3 Marks)
Q1 Write the following codes as directed:
a. switch --- case to if --- else
switch (ch)
{
case 1: cout<<free style; break;
case 20
case 2: cout<<back stroke; break;
case 3: cout<<butterfly; break;
default :cout<<none;
}
b.while loop to for loop
i=2;
while(i<=25)
{
j=1;
while(j<=i)
{
cout<<(i%j);
j++;
}
i+=3;
}
c. ifelse to ternary operator
if ( ( a%100)==0)
cout<<sun;
else
cout<<moon;
Q3. Which header file is required for the following functions:
isdigit(), fabs(), random(), strcpy(), setw(), strcat(), toupper(), log()
Q4.
a)What is the purpose of comments and indentation in a program?
b)What do you mean by robustness of a program?
c)What are the characteristics of a good program?
d)How would you explain preincrement operator ++ with an example?
e)How can you convert switch..case into for loop?
f)What is the difference between = and = = operator?
g) State the difference between a and a.
h) How many types of comments are there in c++, explain with examples?
i)How many bytes of memory will be required to store
a. 45.678
b. William Shakespeare
c. \n
d. int s[3]
Q5. Rewrite the corrected code. Underline each correction. No mark will be given if correction is not underlined
a)
# include <iostream.h>
#include (iostream.h)
void main( )
{
int X[ ]={60, 50, 30, 40}, Y; Count=4;
cin>>Y;
for ( I = Count1; I>=0; I)
switch (I)
{
case 0 :
case 2 : cout<<Y*X[I]<endl; break;
case 1 :
case 3 : cout>>Y+X[I];
}
}
b)i)Rewrite the following code using switch :
if (a == 0)
cout<< Zero;
if (a == 1 )
cout<< One;
if (a == 2 )
cout<< Two;
if (a == 3)
cout<< Three;
Q6.
(a)
A = A + B;
B = A B;
A = A B;
}
void main()
{
int a = 4, b = 18;
X(a,b);
cout<< a<<,<<b;
}
(b)
(c)
(d)
(e)
void main()
{
int x=5,y=8;
small(x,y) = -1;
cout<< x=<< x<<y=<<y<<endl;
small(x,y) = 6;
cout<< x=<< x++<<y=<<y--<<endl;
small(x,y) = 3;
cout<< x=<< x<<y=<<y<<endl;}
(f)
# include <iostream.h>
# include<conio.h>
void main()
{
clrscr() ;
for (inti = 0; i< 8 ; i++)
if (i%2 == 0)
cout<< i+1 << ;
else if ( i%3 == 0 )
cout<<i*i <<endl;
else if ( i%5 == 0)
cout<< 2*i-1 << ;
else
cout<<i<<endl;
getch() ;
}
(g)Find the output of the following program:
# include<iostream.h>
# include<ctype.h>
void main()
{
char Text[] = "Mind@Work!";
for (int I=0; Text[I]!='\0'; I++)
{
if (!isalpha(Text[I]))
Text[I] = '*';
else if (!isupper(Text[I]))
Text[I] = Text[I] + 1;
else
Text[I] = Text[I+1];
}
puts(Text);
}
Q8. Differentiate between the following ( Also give an example of each):
a. cin and gets( )
b. Binary and Unary operators
c. Entry controlled loops and Exit controlled loops
d. Break and continue
e. Got and for
f. Call by value and call by reference
g. Actual parameter and formal parameter
h. Islower and tolower
Practice Set-2
Subject C++ Basic
ii) a4 +b4-c + | d |
iv) ax8+bx6-tan-1b
i) x *(++ y) y % 10 +3
ii) (x+y> z) ?( ++ x y) : (- - z + ++y) where x=8, y=10, z=8
3. Construct logical expressions to represent the following conditions
i) salary is in the range 8000 to 10000
ii) ch is an uppercase letter
iii) weight is greater than or equal to 30 but less than 50
iv) a is an odd number
4. Evaluate the following
a) x-y<z &&y+z>x||x-z<=y-x+z if x=4, y=8,z=9
b) y&&(x-z) || !(2y<z-x) if x=10 ,y=11, z=10
5. Convert the following if-else to a single conditional statement using conditional
operator.
if(qty>=20)
order = max +5;
else
order = max;
6. Write equivalent c++ expressions for the following.
[2]
i) cos2x + e2y
ii) (1-y3)0.5
sin z - | 1+a6 |
(1+x4)0.25
7. Evaluate the following expressions
i) y = ++x + ++x where x=10
ii) !(a<b) && c!= d || b+c< a where a=7, b=3, c=5, d=6
8..
Give the output
#include<iostream.h>
void main( )
{ int a=2,b=5,c=3,m;
m=(a>b) ? c : (( b>c) ? b : c ) ;
cout<<m;
}
9. Give the output
#include<iostream.h>
void main()
{ int U=10, V=20;
cout<<[1]=<<U++<<&<<V-5<<endl;
cout<<[2]=<<++V<<&<<U+2<<endl; }
10. Differentiate between the following.
i)cin>> and gets( )
ii) cout<< and puts()
iii) Unary, Binary and Ternary operators
iv) = and ==
v) / and %
11. Evaluate the following expressions
i) x *(++ y) y % 10 +3
ii) (x+y> z) ?( ++ x y) : (- - z + ++y) where x=8, y=10, z=8
12. Evaluate the following expressions
i) y = ++x + ++x where x=10
ii) !(a<b) && c!= d || b+c< a where a=7, b=3, c=5, d=6
13 #include<iostream.h>
void main( )
{
int a=2,b=5,c=3,m;
m=(a>b) ? c : (( b>c) ? b : c ) ;
cout<<m;
}
14. What is the output of the following?
i) # include<iostream.h>
void main ( )
{
intch=20;
cout<< ++ch<<\n<<ch<<\n;
}
1) What output does the above code fragment produce?
2) What is the effect of replacing ++ch with ch+1?
15
# include<iostream.h>
void main( )
{
a=3;
a=a+1;
if (a>5)
cout<<a;
else
cout<<(a+5);
iv) *
ft2
(ii) v-w/(a+b)9
27 Using the given values of x, y and z, evaluate the following( answer in True/
False)
(X<=Y) | | ( ! (Z >= Y) &&(Z = =X))
(i) X=10, Y=2, Z=11
(ii) X=11,Y=11,Z=11
(iii)
X=9,Y=10,Z=5
28.(i) (1010.11)2 = (___)8
(ii) (6AF)16= (___)2
(iii) (10111)2
= (___)10
29. Answer the following questions.
(a) What is the purpose of comments and indentation in a program ?
(b) What do you mean by cascading of I/O operators?
(c) What are the predefined stream objects in I/O Library ?
(d) The modulus operator works only with integers True or False.
(e) What do you mean by runtime error and logical errors ?
30. What is the output of following program?
int result = 4 + 5 * 6 + 2;
cout<<result;
int a = 5 + 7 % 2;
cout<<a;
31 Write the corresponding C++ expressions for the following mathematical
expressions:
(ii)
(iv) A+B+
32 Evaluate the following :
(a>=b)||(!c==b) &&(c<a) [ a=10,b=5,c=11]
c=(a++)*d+a [a=5,b=3,d=1.5]
(x<y)&&(z==x) || y [x=3,y=5,z=9]
33
int x=17;
int y=x--;
cout<<++y;
--x;
cout<<--x + y++<<y++;
int z=9,x=17;
int y;
y=x%z;
cout<<x/y<<y++<<-- z * x;
int x=9;
int z=x++ + +
+x;
cout<<z;
int x=17;
int y=x++;
cout<<++y;
x++;
cout<<++x +
y++<<y++;