Question
46. What does the following code print? int k = 1; cout < < k++ < < ' '; cout < < ++k < <
46. What does the following code print?
int k = 1; cout << k++ << ' '; cout << ++k << endl;
47. What does the following code print?
int k = 5; cout << --k << ' '; cout << k-- << endl;
48. What does the following code print?
int x = 1; int y = 0; { int x = 2; y = x + x; { int y = 4; x = y + 1; } } cout << x << ' ' << y << endl;
49. What does the following code print?
int x = 0; { int x = 1; cout << x << ' '; } cout << x << endl;
50. What does the following code print?
int x = true; double y = int(5.4) + 0.1 * true + false; cout << (x - y) << endl;
51. What does the following code print?
int x = 3.4; double d = false; cout << (x + d) << endl;
52. What does the following code print?
cout << (100 % 5) << endl;
53. What does the following code print?
cout << (31 % 2) << endl;
54. What does the following code print?
class T { public: T() { cout << 'A'; } char f() { return 'B'; } char g(char x) { if (x == 'A') return 'C'; else return 'D'; } }; int main() { T t, u; t.g('B'); u.f(); t.g('A'); }
55. What does the following code print?
class T { public: T() { data = 'X'; cout << 'A'; } void f() const { cout << 'B' << data; } char g(char x) { cout << 'C' << x; return x; } char data; }; int main() { T a; a.f(); a.data = a.g('Z'); a.g('Q'); a.f(); return 0; }
Coding
56. Write C++ code that reads 2 floating-point numbers and displays the sum of those numbers.
57. Write C++ code that reads 1 line and displays the length of that line.
58. Define the body of is_even, this function shall return true if the value of x is an even integer; false shall be returned otherwise.
bool is_even(int x) { }
59. Define the body of sum_of_double, this function shall return the sum of the values found in v or 0 if v is empty.
double sum_of_doubles(const vector
60. Define the body of find_double, this function shall return the index of the first occurrence of the value of x found in one of the elements of v or -1 if no such value was found. Do not perform function calls in your code.
int find_double(const vector
61. Complete the following program; this program should display a random integer value between a minimum and maximum value (inclusive) specified by the user.
#include
62. Define the body of factorial, this function shall return the factorial of x or 1 if x is less than or equal to 1. Examples: factorial of 0 is 1, factorial of 1 is 1, factorial of 3 is 3 * 2 * 1 = 6, factorial of 4 is 4 * 3 * 2 * 1 = 24, factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120.
int factorial(int x) { }
63. Define the body of is_prime, this function shall return true if x is a prime integer and false otherwise.
bool is_prime(int x) { }
This is a study guide and i need the answers for it to help me study. Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started