Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q1) Evaluate the following expressions:
- (a) 10%2 = 0
- (b) 23%4 = 3
- (c) 36%6 = 0
- (d) 13/5 = 2
- (e) 13.0/5 = 2
- Q2) Evaluate: (12%5+1)*2/6+5+3*(8/(22%10)-3)
- Answer : 9
- Q3) Evaluate: static_cast<int>(7.8 + static_cast<float>(15%3)/2) =
- Answer: 7
- Q4) True or false: The following is valid C++ code. Circle the error, if any.
- #include <iostream>
- using namespace std;
- int main() {
- char ch;
- cin << ch;
- cout << ch; /* Wrong sythax */
- return 0;
- }
- Answer: False
- Reason: Error in line cout<<ch
- Wrong syntax. Correct statement must be like cout>>ch
- Q5) What would you do to read input with spaces into a single string variable, str, from cin? Write the C++ statement.
- Answer:
- Sample code:
- #include<iostream.h>
- void main()
- {
- char str[100]; /* array of characters */
- cout<<"enter any string: ";
- cin>>str; /* reads a string including white spaces */
- cout<<" you entered is: "<<str;
- }
- Sample output:
- enter any string: hello how are you?
- you entered is: hello how are you?
- Q6)
- //code
- int x, y; //x and y are integers
- double z; //z is a double
- cin >> x >> y >> z;
- //input
- 37
- 86.56
- 32
- After the above piece of code executes, what will be the values of x, y, and z?
- Answer:
- after the program execution value of x will 37 value of y will be 86 and value of z will be 0.56
- 囲DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: TC File Edit Search Run Compile Debug Project CHECK.CPP inclu
- output:
- DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: TC B6.56 The values are B6 0.56
- Q7) Evaluate (write its value next to each expression):
- (a) 'a' < 'b'
- Answer: True
- (b) string("hope") < string("hype")
- Answer: True
- (c) string (“usm”) > string (“msu”) && string (“olemiss”) < string (“usm”)
- Answer: False
- (d) 10 + 12.5 <= 22.5
- Answer: True
- (e) !(5 < 2) || !(7 > 2)
- Answer: True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement