Professional Documents
Culture Documents
1.
2.
3.
4.
5.
6.
7.
8.
9.
(625.375)10=(?)8
(10011110.110011)2=(?)16
(3ABFE.4B2)16=(?)10
(55.678)10=(?)8
(10010.1111)2=(?)8
(45CAE.4DE2)16=(?)8
(625.375)10=(?)4
(10011110.110011)2=(?)8
(3ABFE.4BCD2)16=(?)4
(12345.25)10=(?)8
10. What is OOP? What is difference between Procedural Programming and Object Oriented
Programming ?
11. Explain the following in terms of OOP:
(A) CLASS (B) OBJECT (C) POLYMORPHISM (D) Data Abstraction ( E ) Inheritance
12. . What is special thing about main() function ? What are its rolls?
13. .What is identifier? What is the naming convention for the identifiers ?
14. Identify valid and invalid identifiers and justify your answer also .
Minus 3ABC int INT _SUM printf scanf _sum _float pow num^2
$sum num 1 ram.shyam
salry_max
15. What are the implicit type conversion rules in C++ when adding, multiplying, etc. Fill ?
int + float = ?
int * float = ?
float * int = ?
int / float = ?
float / int = ?
int / int = ?
int ^ float = ?
16. Explain the difference between type promotion and type casting with suitable example code.
17. Find he output of the following
void main()
{
int camel=15,cow=33;
cout<<( camel ++)*b camel <<endl;
cout<<( cow ++)*(-- camel)<<endl;
}
1 QUESTION BANK CLASS XI COMPUTER SCIENCE
VARANASI @@ VIZAG@@KANPUR
VIZAG@@KANPUR@@KANPUR
20. Rewrite the code after removing errors. Underline each correction
#include<iostream.h>
void main()
{
int n1,n2,n3,avg;
cout<"\nEnter three numbers ";
cin>>n1,n2,n3;
sum=n1+n2+n3;
avg=sum/3
cout<<"Average of three numbers is "<<avg;
}
21. Write a program to find area and perimeter of a circle, a rectangle , a square.
22. What is escape sequence? Explain with example?
23. Name the header files which are required for successful execution of the following c++ code:
void main( ){
char String[ ] = String;
QUESTION BANK
// line 1
void main(){
int LIST[ ]=[100,200,300,400] , Y; // line 2
COUNT= 4;
// line 3
cin>>Y;
for(i=COUNT-1 ; I >=0;,i--)
switch(i) {
case 0 :
case 2 : cout<<Y*LIST[i]<endl; // line 4
break;
case 1:
case 3 : cout >> Y+LIST[i];
}
}
25.
26.
27.
28.
29.
30.
31.
32.
Explain Robustness?
Explain different types of errors with example.
What is purpose of comments in a program?
What is a Self-documenting code? How documentations are useful?
What is system maintenance? How many different types of maintenance?
. Explain different types of programming paradigm in details.
Name the header files to which the following belong:
(i)
abs( )
(ii) random( )
Rewrite the following program after
#include<iostream.h>
void main( )
removing
all
the
{ F = 10, S = 20;
test(F;S);
test(S); }
void test(int x, int y = 20)
{ x=x+y;
QUESTION BANK
syntax
error(s),
if
any
count<<x>>y;}
33. Write the output of the following program
#include<iostream.h>
#include<conio.h>
void main( )
{
long NUM=1234543;
int F=0,S=0;
do{
if (R %2 != 0)
F += R;
else
S += R;
NUM /= 10;
} while (NUM>0);
cout<<(F-S);
getch();
}
34. Rewrite the following code using conditional operator.
if (age>=18)
cout<<"Major";
else
cout<<"Minor";
35. Give the output of the following code
void main()
{
int x,y;
for(x=1; x<=4; x++)
{
for(y=1; y<=x; y++)
cout<<x<<y<<" ";
cout<<endl;
}
}
36. Write a program to display 2, 4, 8, 16, 32,.,1024.
37. Name the header file to be used for the functions clrscr() and strcpy().
38. Differentiate between Call by Value and Call by Reference with suitable code.
QUESTION BANK
39. Find the possible output(s) of the following code. Also write the minimum and maximum value of r.
void main()
{
}
(i) 120,121,122,123,
(ii)122,123,124,125,
(iii) 121,122,123,124,
(iv)123,124,
40. Observe the following program GUESS.CPP carefully, if the value of variable Num entered by the
user is 5 , choose the correct possible output(s) from the options from (i) to (iv) and justify your option: (2)
// Program Name : GUESS.CPP
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
void main()
{
randomize();
int Num,rndnum;
cin>>Num;
rndnum=random(Num)+5;
for(int N=1;N<=rndnum;N++)
cout<<N<<"##";
getch();
}
Output :
(i)1##2##3##4##
(ii)1##2##
(iii)1##2##3##4##5##6##7##8##9##
(iv)1##2##3##
41. Write a program to check if a given number is a prime number or not?
QUESTION BANK
[4]
Unit Name
Total Marks
COMPUTER FUNDAMENTALS
10
II
INTRODUCTION TO C++
14
III
PROGRAMMING METHODOLOGY
12
IV
PROGRAMMING IN C++
34
70
BLUEPRINT
Unit
No.
Unit Name
VSA(1)
VSA(2)
SA(3)
LA(4)
Total Marks
COMPUTER
FUNDAMENTALS
3(3)
4(2)
3(1)
10
II
INTRODUCTION TO C++
1(1)
10(5)
3(1)
14
III
PROGRAMMING
METHODOLOGY
2(2)
6(3)
4(1)
12
IV
PROGRAMMING IN C++
3(3)
6(3)
9(3)
16(4)
34
QUESTION BANK
Total
9(9)
26(13)
15(5)
20(5)
70
long
If either is
int
unsigned int
If either is long
If either is
double
if either is
double
If either is
If either is long
long
int
float
unsigned int
int
int
unsigned int
int
unsigned int
int
Note. The minimum size of operations is int. So short/char are promted to int before the
operation is done In all your expressions the int is promoted to a float before the operation is
performed. The result of the operation is a float.
int + float => float + float = float
int * float => float * float = float
float * int => float * float = float
int / float => float / float = float
float / int => float / float = float
int / int
= int
down
vote
Whole chapter 4 talks about conversions, but I think you should be mostly interested in these :
4.5 Integral promotions [conv.prom]
An rvalue of type char, signed char, unsigned char, short int, or unsigned short int can be
QUESTION BANK
converted to an rvalue of type int if int can represent all the values of the source type; otherwise, the source rvalue can be converted to an rvalue of type unsigned int.
An rvalue of type wchar_t (3.9.1) or an enumeration type (7.2) can be converted to an rvalue of
the first
of the following types that can represent all the values of its underlying type: int, unsigned int,
long, or unsigned long.
An rvalue for an integral bit-field (9.6) can be converted to an rvalue of type int if int can
represent all
the values of the bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field. If the bit-field is larger yet, no integral promotion applies to
it. If the
bit-field has an enumerated type, it is treated as any other value of that type for promotion
purposes.
An rvalue of type bool can be converted to an rvalue of type int, with false becoming zero and
true
becoming one.
These conversions are called integral promotions.
4.6 Floating point promotion [conv.fpprom]
An rvalue of type float can be converted to an rvalue of type double. The value is unchanged.
This conversion is called floating point promotion.
Therefore, all conversions involving float - the result is float.
Only the one involving both int - the result is int : int / int = int
Previously, you learned that the value of a variable is stored as a sequence of bits, and the data type of the
variable tells the compiler how to translate those bits into meaningful values. Often it is the case that data
needs to be converted from one type to another type. This is called type conversion.
QUESTION BANK
Implicit type conversion is done automatically by the compiler whenever data from different types is
intermixed. When a value from one type is assigned to another type, the compiler implicitly converts the
value into a value of the new type. For example:
1
2
In the top example, the value 3 is promoted to a double value and then assigned to dValue. The compiler
will not complain about doing this. However, some type conversions are inherently unsafe, and if the
compiler can detect that an unsafe conversion is being implicitly requested, it will issue a warning. In the
second example, the fractional part of the double value is dropped because integers can not support
fractional values. Because converting a double to an int usually causes data loss (making it unsafe),
compilers such as Visual Studio Express 2005 will typically issue a warning. Other unsafe conversions
involve assigning unsigned variables to signed variables (and vice-versa), and assigning large integers
(eg. a 4-byte long) to integer variables of a smaller size (eg. a 2-byte short).
Warning: Microsofts Visual C++ 2005 does not seem to issue warnings for unsafe signed/unsigned
conversions.
When evaluating
When evaluating expressions, the compiler breaks each expression down into individual subexpressions.
Typically, these subexpressions involve a unary or binary operator and some operands. Most binary
operators require their operands to be of the same type. If operands of mixed types are used, the compiler
will convert one operand to agree with the other. To do this, it uses a heirarchy of data types:
QUESTION BANK
If either operand is of type long double, the other shall be converted to long double.
Otherwise, if either operand is double, the other shall be converted to double.
Otherwise, if either operand is float, the other shall be converted to float.
Otherwise, the integral promotions (4.5) shall be performed on both operands.54)
Then, if either operand is unsigned long the other shall be converted to unsigned long.
Otherwise, if one operand is a long int and the other unsigned int, then if a long int can represent all the
values of an unsigned int, the unsigned int shall be converted to a long int; otherwise both operands shall
be converted to unsigned long int.
Otherwise, if either operand is long, the other shall be converted to long.
Otherwise, if either operand is unsigned, the other shall be converted to unsigned.
Only the one involving both int - the result is int : int / int = int
10
QUESTION BANK
Here, the compiler sees variable x as an int, but variable y as a data type called 'tdType'
that happens to be the same size as an int. If you wrote a function that took a parameter of
type defType, the caller could pass a normal int and the compiler wouldn't know the
difference. If the function instead took a parameter of type tdType, the compiler would
ensure that a variable of the proper type was used during function calls.
Preprocessor macros ("#define's") are a lexical replacement tool a la "search and replace".
They are entirely agnostic of the programming language and have no understanding what
you're trying to do. You can think of them as a glorified copy/paste mechanic -occasionally that's useful, but you should use it with care.
Typedefs are a C language feature that lets you create aliases for types. This is extremely
useful to make complicated compound types (like structs and function pointers) readable
and handlable (in C++ there are even situations where you must typedef a type).
Example program for #define, #include preprocessors in C:
#define - This macro defines constant value and can be any of the basic data types.
#include <file_name> - The source code of the file file_name is included in the main C
program where #include <file_name> is mentioned.
#include <stdio.h>
#define height 100
#define number 3.14
#define letter 'A'
#define letter_sequence "ABC"
#define backslash_char '\?'
void main()
{
printf("value
printf("value
printf("value
printf("value
printf("value
of
of
of
of
of
height
: %d \n", height );
number : %f \n", number );
letter : %c \n", letter );
letter_sequence : %s \n", letter_sequence);
backslash_char : %c \n", backslash_char);
}
Output:
value of height : 100
value of number : 3.140000
value of letter : A
value of letter_sequence : ABC
value of backslash_char : ?
11
QUESTION BANK
http://fresh2refresh.com
12
QUESTION BANK
When this line appears in a file, all subsequent occurrences of identifier will be
replaced by the replacement-text automatically before the program is compiled.
For example:
#define PI 3.14159
Replaces all subsequent occurrences of the symbolic constant PI with the numeric
constant 3.14159. const type qualifier also can be used to declare numeric
constant that will be discussed in another Module.
Symbolic constants enable the programmer to create a name for a constant and
use the name throughout the program, the advantage is, it only need to be
modified once in the #define directive, and when the program is recompiled, all
occurrences of the constant in the program will be modified automatically, making
writing the source code easier in big programs.
That means everything, to the right of the symbolic constant name replaces the
symbolic constant.
Consider the following macro definition with one argument for a circle area:
#define
13
QUESTION BANK
CIR_AREA(x)
PI*(x)*(x)
Is expanded to:
area = 3.14159*(4)*(4);
Since the expression consists only of constants, at compile time, the value of the
expression is evaluated and assigned to variable area.
The parentheses around each x in the replacement text, force a proper order of
evaluation when the macro argument is an expression. For example, the
following statement:
area = CIR_AREA(y + 2);
Is expanded to:
area = 3.14159*(y + 2)*(y + 2);
This evaluates correctly because the parentheses force the proper order of
evaluation. If the parentheses are omitted, the macro expression is:
area = 3.14159*y+2*y+2;
Because of the operator precedence rules, you have to be careful about this.
Performs the same calculation as macro CIR_AREA, but here the overhead of a
function call is associated with circleArea function.
The advantages of macro CIR_AREA are that macros insert code directly in the
program, avoiding function overhead (creating and dismantling the stack), and the
program remains readable because the CIR_AREA calculation is defined
separately and named meaningfully. The disadvantage is that its argument is
evaluated twice. Another better alternative is using the inline function, by adding
the inline keyword.
14
QUESTION BANK
The following is a macro definition with 2 arguments for the area of a rectangle:
#define
RECTANGLE_AREA(p, q)
(p)*(q)
If the replacement text for a macro or symbolic constant is longer than the
remainder of the line, a backslash (\) must be placed at the end of the line
indicating that the replacement text continues on the next line. For example:
#define
RECTANGLE_AREA(p, q) \
(p)*(q)
The scope of a symbolic constant or macro is from its definition until it is undefined
with #undef, or until the end of the file. Once undefined, a name can be redefined
with#define.
getchar()
getc(stdin)
The macro definition of getchar() uses function getc() to get one character from
the standard input stream. putchar() function of the stdio.h header, and the
character handling functions of the ctype.h header implemented as macros as
well.
A program example.
15
QUESTION BANK
#include <iostream>
#define
THREETIMES(x)
#define
CIRAREA(y)
#define
REC(z, a)
#define
PI
(x)*(x)*(x)
(PI)*(y)*(y)
(z)*(a)
3.14159
int main(void)
{
float p = 2.5;
float r = 3.5, s, t, u = 1.5, v = 2.5;
s = CIRAREA(r+p);
cout<<"Circle area = PI*r*r = "<<s<<endl;
t = REC(u, v);
cout<<"Rectangle area = u*v = "<<t<<endl;
return 0;
}
[THE END]
16
QUESTION BANK