There are several parts to this question which are to be answered independently and separately. Each part
Question:
There are several parts to this question which are to be answered independently and separately. Each part consists of a fragment of C/C++ code. Write the exact output produced by the code in the answer box. If an error occurs, or it enters an infinite loop, state and explain why.
You may show workings outside the answer box in the space beside it. Partial marks may be awarded for workings if the final answer is wrong. Assume that all appropriate preprocessor directives e.g., #include , etc. have already been defined.
A.
int f(int &x) {
x *= 2;
cout << "f:" << x << endl;
return x;
}
int g(int x) {
cout << "g:" << x << endl;
return f(x) + x;
}
int main() {
int x = 2;
int y = g(f(x));
cout << x << "," << y << endl;
}
B.
int i;
for (i = 0; i < 10; ++i) {
cout << i << ",";
if (i % 2) { ++i; }
if (i % 3) { continue; }
if (i % 5) { break; }
}
cout << i << endl;
C.
int date = 30/9/2021;
if (date) {
cout << "today" << endl;
} else {
cout << "is" << endl;
}
date += 1;
if (date == 1/10/2021) {
cout << "childrens" << endl;
} else if (date+2 == 31/10) {
cout << "day" << endl;
}
cout << date << endl;
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts