Sunteți pe pagina 1din 3

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE EC101A: Computer Systems and Programming Spring Semester: 2010-2011 August 3, 2011 1.

Which of the following are invalid identifiers: (i) 123Greeting (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 x 3 + 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 ); 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 ) ) ) ); What does the following code print?

5.

6.

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 that obtains two integers from the user, then displays the larger number followed by the words is larger. If the numbers are equal, then displays These numbers are equal. 9.Write a program using for-loop for reading an integer i, where 0 i 9. Output the message XXX Sequence Found whenever the input sequence is 592, 346, or 465. XXX represents the respective sequence and the output should print the numerical value of the sequence (such as 346 Sequence Found, etc.). Also explain how you handle the case where the input sequence is 873465920. Terminate the program whenever 000 sequence is encountered. 10..A restaurant owner gives a discount on food purchases as per the following table. Food Purchase (Rupees) 0 to 50 51 to 100 101 to 200 200+ Discount (Percentage) No Discount 5% 8% 10%

The restaurant also charges service tax according to this table

Number of people 5 10 15 20

Service Tax No Tax 2.5% 3.5% 5%

Write a program that inputs the number of people at a table and the total food purchase amount. Using the above table, compute the final bill amount for the table.

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