Вы находитесь на странице: 1из 2

ESN-103 ; Computer Programming, IIT Roorkee

1. Which of the following are invalid identifiers:


(i) 13Greeting (ii) Intel1 (iii) Pentium 3 (iv) Pentium_4
(v) this (vi) %age (vii) no return (viii) I am Correct
Modify the invalid identifier such that it becomes a valid identifier, by adding,
removing, or modifying no more than 2 characters.
2. Identify whether the user defined identifiers or variables given below are valid or invalid. If
the identifiers or variables are invalid, give reasons for the same.
i) no-of-students ii) no_of_students iii) 1subject iv) iitr, v) rupees&paise,
vi) Float vii) int viii) x ix) y# x) $distance.
3. Write the display when each of the following C++ statements is executed. If nothing is
displayed then write “nothing”. Assume x = 2 and y = 3,z=4.
a) cout << x: b) cout << x + x; c) cout <<”x = “;
d) cout << “x = “ << x; e) cout << x + y << ” = “<< y + x;
f) z = x + y; g) cin >> x*2 >> y; h) // cout << “ x + y “<< x + y*z ;
i) cout <<”\n”;
4 Given the algebraic equation y = a x3 + 9, which of the following, if any, are correct C++
statements for this equation?.
a) y = a * x * x * x + 9; b) y = a * x * x * ( x + 9 ); c) y = ( a * x ) * x * ( x + 79);
d) y = (a * x ) * x * x + 9; e) y = a * ( x* x * x ) + 9;
f) y = a * x * ( x * x + 9 );
5. State the order of evaluation of the operation in each of the following C++ statements and
find the value of x after each statement is executed.
i. x = 9 + 3 * 8 / 2 – 1;
ii. x = 3 % 3 + 2 * 2 – 2 / 2;
iii. x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );
6. What does the following code print?
cout << “*\n**\n***\n****\n*****”<< endl;
7..Find errors in the code segments below and if incorrect then fix them. Write the output
of the corrected code segment. You may directly copy these codes in files in Dev C++
and try fixing the code with the help of compiler.
(i)
#include <iostream
using namespace std
const double pi = 3.14159;
int main()
{
{
float length, width, area;
cout < "Enter The Length Of The Rectangle: ;
cin >> length;
cout << "Enter The Width Of Rectangle: ";
cin >> width;
area = = length*width;
cut <<"The area of the rectangle is : "<< area << endl;
return 0;
}
(ii)
#include <iostream.>
int main()
{
double side;
/get user input
cout<<"Please enter the length of the side : ";
cin>>radius;
/*act on user input /
if(side < 0.0) then
cout<<"Cannot have a negative side"<<endl;
else
cout<<"The area of the square is "<<side * side<<endl;
return 0
}
8. Write a program to calculate the compound interest.

9. Write a program to convert temperature from Fahrenheit to Celsius or Celsius to


Fahrenheit depending on the user choice.Use flag for user choice.

10. Write a program to check if one number is divisible by other.

Вам также может понравиться