Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ST.

KABIR SCHOOL
UNIT TEST –I --COMPUTER SCIENCE PAPER (083) --2018 --M.M 50

What are the main types of C++ data types? Write data types of each type.
C++ offers two types of data types:
1. Fundamental data types: These are five fundamental data types: char, int, float, double and void.
2. Derived data types: These are derived data types: array, function, pointer, reference, constant, class,
structure, union and enumeration.
What are the similarities and difference between an array and a structure?
Similarities:
 Both are collection of elements.
Differences:
 An array can hold multiple elements of same data type whereas a structure can hold multiple elements
of different data types.
 The component element of an array is referenced by the array name and the index value e.g., NAME[3],
FILE[7] etc. on the other hand, the component element of a structure is referenced by the structure name
and the elemet name e.g., style.main, check.value etc.
2 3 4 5
Write a program to read a number n and print n , n , n , and n .
#include<iostream.h>
#include<conio.h>
void main()
{ int n; clrscr();
cout<<"Enter n:
"; cin>>n;
cout<<n*n<<"\t"<<n*n*n<<"\t"<<n*n*n*n<<"\t"<<n*n*n*n*n;
getch();
}
What is an integer constant? Write integer forming rule of C++.
Integer constants are whole numbers without any fractional part. Integer forming rule of C++ is as following:
An integer constant must have at least one digit and must not contain any decimal point. It may contain either + or

sign. A number with no sign is assumed to be positive. Commas cannot appear in an integer constant.
What are tokens in C++? How many types of tokens are allowed in C++? Explain your answer.
Token is a smallest individual unit in a program. In C++ following types of tokens are allowed:
1. Keyword: Reserve word having special meaning and purpose. For example, break, for, int etc.
2. Identifier: Name given by user for a part of the program. For example, MyFile, _CHK etc.
3. Literals: Data items that never change their value during a program run. For example, 1234, ‘A’, 2.0 etc.
4. Punctuators: The characters which are used as punctuators in C++: [ ] ( ) { } , ; : * … = #
5. Operators: Operators are tokens that trigger some computation or action when applied to variables ad
other objects in an expression. For example, +, -, &, * etc.
How are keywords different from identifiers?
Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are a few.
For
example, goto, switch, else etc. are
keywords.
Identifier is the user-defined name given to a part of a program viz. variable, object, function etc. identifiers are
not reserved. These are defined by the user but they can have letters, digits and a symbol underscore. They must
begin with either a letter or underscore. For instance, _chk, chess, trial etc. are identifiers in C++.
Identify the errors in the following code segments:
(i) int main() { cout<<"Enter two numbers";
cin>>num>>auto
;
float area=Legth*breadth; }

(ii) #include<isostream.h>
void Main()
{ int a,b;
cin<<
>>;
if(a>b)MAX=a
}
(i) 1. The header file iostream.h has not been included.
2. The variables num, Length and breadth have not been declared before using them.
3. auto is a keyword which cannot be used as a variable name.

(ii) 1. There is a spelling mistake in declaration of header file iostream.h


2. The variables MAX has not been declared before using it.
3. The statement cin<< >> has not been written correctly.
4. The statement MAX = a has not been terminated with ;.
What are operators? What is their function? Give examples of some unary and binary operators?
Operators are tokens that trigger some computation or action when applied to variables ad other objects in an
expression. Following are some unary and binary operators:
Unary Operators Binary
Operators
& Address operator + Addition
* Indirection operator - Subtraction
++ Increment operator % Reminder/Modulus
-- Decrement operator && logical AND
What is type conversion? What is meant by implicit and explicit type conversion?
Type conversion: The process of converting one predefined type into another is called Type conversion.
Implicit type conversion: An implicit type conversion is a conversion performed by the compiler
without programmer’s intervention.
Explicit type conversion: An explicit type conversion is user-defined that forces an expression to be of specific
type.
What are arithmetic operators in C++? Distinguish between unary and binary arithmetic operators. Give
examples for each of them.
Ans. The operators which are performed arithmetic operations are called arithmetic operators.
Unary arithmetic operators Binary arithmetic
operators A unary operator requires a single operand. A binary operators
requires two operands. unary+, unary-, ++, --, sizeof etc. are unary operators. +, -, *,
/, % etc. are binary operators.
For example, if a=2 then +a means 2 For example, 2 + 5 results in 7

What is the function of increment/ decrement operator? How many varieties do they come in? How are
these two varieties different from one another?
Ans. The increment and decrement operators (++ and --) add 1 or subtract 1 from operand’s value. They
come in two forms: postfix and prefix.

Postfix Prefix
It uses the value of theversion version
operand and then changes it. It first changes its operand’s value and then uses it.
For example, a++ or a-- For example, ++a or --a
Writ a C++ program to input a student type (‘A’ or ’B’). if the student type is ‘A’ initialize the college account
with
Rs. 200/- otherwise initialize the hostel account with Rs. 200/-.
Write a C++ program to input a number. If the number n is odd and positive, print its square root otherwise
5
print n .
Write a C++ program to input three integers and print the largest of three.
Write a program to generate the following table:
1992 17421
1993 29210
1994 100523
1995 106802
1996 127000
Use a single cout statement for output. (Hint: Make use of \n and \t.)
Write a C++ program that accepts radius of a circle and prints its area.

You might also like