Sunteți pe pagina 1din 12

PRACTICE Set1

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)

Write the output of the following program


#include<iostream.h>
void X( int A, int&B)
{

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)

What will be the output of following segment?


#include<iostream.h>
void main()
{
inti,j,x=0;
for(i=0;i<5;++i)
for(j=0;j<i;j++)
{
x + = (i + j 1);
cout<<x;
}
cout<<\n<<x;
}
Give the output for the following program segment given below
for(i = -5; i< -8;i--)
cout<<i+1<<endl;
Give the output of the following code
# include <iostream.h>
int g = 20;
voidfunc(int&x,int y)
{
x=x-y;
y=x*10;
cout<<x<<,<<y<<endl;
}
void main()
{
int g = 7;
func(g,::g);
cout<<g<<,<<::g<<endl;
func(::g,g);
cout<<g<<,<<::g<<endl;
}
Explain the output of the following code
# include <iostream.h>
void&small ( int&a, int&b)
{
if (a<b)
return a;
else
return b;

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

i. Runtime error and syntax error


Q9. Explain the usage of following pre-defined functions, by giving an example. Also mention their header file:
strcmpi(), pow()
Q10. What are reference parameters? What is the benefit of using them?
Q11. Define the following(give an example of each) :
a. string
b. Function Definition
c. Prototype
(3-4 Marks)
1)Write a program to accept time in a 12 hour clock and display the correct time using AM or PM.
2) Write a program to accept an integer value for n. If n is even and positive, display its double otherwise display its
square.
3)WAP to input money amount from user and find how many 1000 rs, 500 rs and 100 rs notes are there
4) Write a program to display 10 terms of the series given below and their sum.
1 2/4 3/9 4/16 5/25 .
5)Write a program to display a triangle of height N as shown below.
1
22
333
.
nnnn n
6) Write a program to input an int array of 10 elements and display cubes of all the numbers in reverse order.
7) Write a program to accept a string and display its last five letters in reverse order
8) Write a program to input elements in an integer array of size 10 and display its elements which are multiple of 5
9) Write a c++ function to input a number and return 1 if it is Armstrong number else return 0.
10)Write a program to generate following pattern.
1
121
12321
1234321
123454321
11) Generate following pattern.
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
12)Write a c++ function to input a number and return its reverse.
13)WAP to input a string in uppercase and display it in lowercase.
14) Write the user-defined functions for the following:
To search for a string data in an array S containing n strings. The function prototype is intSearch(char S[ ][80], int
n, char data[ ] ). If the string is present the function returns its location else it returns -1.
15)Write C++ programs for the following:
To take the input of a string and an integer n and then display n characters from left and n characters from right of
the string

16)Write a program in C++ that displays the following menu:


1. Series
2. Pattern
3. Exit
This program accepts the users choice and depending on it, executes either SERIES() or PATTERN().
SERIES(int x, int n) prints the sum of the following series like N terms:
x + (x + x2 ) + (x + x2 + x3 )
PATTERN (int n) prints the following pattern till N rows:
1
1 2
1 2 3
17) Write a C++ function that compares two strings and returns 0 if the two strings are equal and 1 if the strings
are unequal (without using strcmp( ) func)?
18) Write a function to find the sum of the series: 12 + 22 + 32 + 42 + 52 +..upto N terms?
19) Write a program to read a name (first name, middle name, last name) from a user and produce an output where
the first letter of each name is capitalized.
20) Write a function to accept a number as a parameter and return its reverse.

Practice Set-2
Subject C++ Basic

1. Write equivalent c++ expressions for the following.


i) cos x
tan x +xex
-1

ii) a4 +b4-c + | d |

iii) val=2(yz)-xe2x +4cos x


2. Evaluate the following expressions

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);

16 What output will be the following code fragment produce?


void main( )
{

intval, res, n=1000;


cin>>val;
res = n+val>1750 ? 400:200;
cout<<res;
}
(i) ifval=2000
(ii) if val=1000 (iii) if val=500
17 Find the error from the following code segment and rewrite the corrected code
underlining the correction made.
# include(iostream.h)
void mains ( )
int X,Y;
cin>>X;
cout>>y;
if x= =y
cout<<Y+X;
else
cout>>Y;
}
18 What is the output of the following?
i) # include<iostream.h>
void main ( )
{ inti=0;
cout<<i++<< <<i++<< <<i++<<endl;
cout<<++i<< <<++i<< <<++i<<endl
19
Convert the following conditional statement into its equivalent if-else
statement.
N=((a<b)?a:b);
20. What will be the size of the following constants
i) 100
ii) 98.967
iii) 8

iv) *

21 What will be the output of the following?


#include<iostream.h>
void main()
{
int a=5, b=5, c=3, ans;
ans = (a < ++b ? b/2 : c/2);
cout<<ans;
}
22. What will be the output of the following?
#include<iostream.h>
void main()
{ int A=5, B=10;
cout<< Line1 =<<A++<<&<<B-2<<endl;
cout<< Line2=<<++B<<&<<A+3<<endl;
}
23 . Predict the output of following code segment
int n=7;
cout<<n++=<<n++<<,n=<<n<<\n;
24. What will be the size of following constants : \a , A\a , Reema\s , / \ .
25. What will be the size of following constants?
Computer, \

26 Write the corresponding C++ expressions for the following mathematical


expressions:
i) ut+

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

What is the output of following program?


int x = 10,y; int x = 10;
int x = 10;
y = x++;
cout<<++x;
cout<<x++;
cout<<y<<x
;

34. What is the output of following program?


inti=9,z=20;
int a=25;
cout<<i++<<++i<<z+ i++; int x=a/3;
cout<<a++;
cout<<++a;
cout<<a<<++x<<a++<<x--;

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++;

35 Write the equivalent C++ expressions for the following :


T=(z+3) *(y-4) (ii) W=log(v) (iii) A=tan-1 x
36 Explain the following functions with example
Clrscr() (ii) pow() (iii) sqrt (iv) ceil() (v) setw() (vi) floor
37. Convert the following :(i) (EB4A)16= (?)8 (ii) (22.25)10=(?)2

(iii) (B2F)16= (?)8

38. Given the following expressions


a)
v=5
b)
v == 5
i)
How are these two different
ii)
What will be the result of the two if the value of val is 10 initially?
39. Correct the error(s) if any in the following code segment
inti, float k;
i = 25;
k = 75.90;
cout>> \n Enter The new values of I and k ;
cin<<i<< k;
cout<< The new values are
\n <<i<<\n << k;
40.State true or false
(i) A variable of type char can hold value 310.
(ii) A short int and int variable may have equal sizes in C++
(iii) The char is treated as one of the integer type
(iv) An identifier declared as char type cannot hold numbers
(v) Data type long float is a valid data type

S-ar putea să vă placă și