Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Q1) Evaluate the following expressions:
  2.  
  3. (a) 10%2 = 0
  4.  
  5. (b) 23%4 = 3
  6.  
  7. (c) 36%6 = 0
  8.  
  9. (d) 13/5 = 2
  10.  
  11. (e) 13.0/5 = 2
  12.  
  13. Q2) Evaluate: (12%5+1)*2/6+5+3*(8/(22%10)-3)
  14.  
  15. Answer : 9
  16.  
  17. Q3) Evaluate: static_cast<int>(7.8 + static_cast<float>(15%3)/2) =
  18.  
  19. Answer: 7
  20.  
  21. Q4) True or false: The following is valid C++ code. Circle the error, if any.
  22.  
  23. #include <iostream>
  24.  
  25. using namespace std;
  26.  
  27. int main() {
  28.  
  29. char ch;
  30.  
  31. cin << ch;
  32.  
  33. cout << ch; /* Wrong sythax */
  34.  
  35. return 0;
  36.  
  37. }
  38.  
  39. Answer: False
  40.  
  41. Reason: Error in line cout<<ch
  42.  
  43. Wrong syntax. Correct statement must be like cout>>ch
  44.  
  45. Q5) What would you do to read input with spaces into a single string variable, str, from cin? Write the C++ statement.
  46.  
  47. Answer:
  48.  
  49. Sample code:
  50.  
  51. #include<iostream.h>
  52.  
  53. void main()
  54.  
  55. {
  56.  
  57. char str[100]; /* array of characters */
  58.  
  59. cout<<"enter any string: ";
  60.  
  61. cin>>str; /* reads a string including white spaces */
  62.  
  63. cout<<" you entered is: "<<str;
  64.  
  65. }
  66.  
  67. Sample output:
  68.  
  69. enter any string: hello how are you?
  70.  
  71. you entered is: hello how are you?
  72.  
  73. Q6)
  74.  
  75. //code
  76.  
  77. int x, y; //x and y are integers
  78.  
  79. double z; //z is a double
  80.  
  81. cin >> x >> y >> z;
  82.  
  83. //input
  84.  
  85. 37
  86.  
  87. 86.56
  88.  
  89. 32
  90.  
  91. After the above piece of code executes, what will be the values of x, y, and z?
  92.  
  93. Answer:
  94.  
  95. after the program execution value of x will 37 value of y will be 86 and value of z will be 0.56
  96.  
  97. 囲DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: TC File Edit Search Run Compile Debug Project CHECK.CPP inclu
  98.  
  99. output:
  100.  
  101. DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: TC B6.56 The values are B6 0.56
  102.  
  103. Q7) Evaluate (write its value next to each expression):
  104.  
  105. (a) 'a' < 'b'
  106.  
  107. Answer: True
  108.  
  109. (b) string("hope") < string("hype")
  110.  
  111. Answer: True
  112.  
  113. (c) string (“usm”) > string (“msu”) && string (“olemiss”) < string (“usm”)
  114.  
  115. Answer: False
  116.  
  117. (d) 10 + 12.5 <= 22.5
  118.  
  119. Answer: True
  120.  
  121. (e) !(5 < 2) || !(7 > 2)
  122.  
  123. Answer: True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement