Consider each of the following code fragments below that could be part of a C++ program. Each fragment contains a call to a standard C/C++ library function. Answer each question in one of the following three ways: - If the code fragment contains a compile-time error, write the word error for the answer. - If the code fragment contains no compile-time errors and you can determine its output at compile-time, provide the fragment’s literal output. - If the code fragment contains no compile-time errors but you cannot determine its exact output at compile-time, provide one possible evaluation and write the word example for the answer and provide one possible literal output that the code fragment could produce. (a) std::cout << sqrt(4.5) << '\n'; (b) std::cout << sqrt(4.5, 3.1) << '\n'; (c) std::cout << rand(4) << '\n'; (d) double d = 16.0; std::cout << sqrt(d) << '\n';
Consider each of the following code fragments below that could be part of a C++ program. Each fragment contains a call to a standard C/C++ library function. Answer each question in one of the following three ways:
- If the code fragment contains a compile-time error, write the word error for the answer.
- If the code fragment contains no compile-time errors and you can determine its output at compile-time, provide the fragment’s literal output.
- If the code fragment contains no compile-time errors but you cannot determine its exact output at compile-time, provide one possible evaluation and write the word example for the answer and provide one possible literal output that the code fragment could produce.
(a) std::cout << sqrt(4.5) << '\n';
(b) std::cout << sqrt(4.5, 3.1) << '\n';
(c) std::cout << rand(4) << '\n';
(d) double d = 16.0;
std::cout << sqrt(d) << '\n';
(e) std::cout << srand() << '\n';
(f) std::cout << rand() << '\n';
(g) int i = 16; std::cout << sqrt(i) << '\n';
(h) std::cout << srand(55) << '\n';
(i) std::cout << tolower('A') << '\n';
(j) std::cout << exp() << '\n';
(k) std::cout << sqrt() << '\n';
(l) std::cout << toupper('E') << '\n';
(m) std::cout << toupper('e') << '\n';
(n) std::cout << toupper("e") << '\n';
(o) std::cout << exp(4.5) << '\n';
(p) std::cout << toupper('h', 5) << '\n';
(q) std::cout << ispunct('!') << '\n';
(r) std::cout << tolower("F") << '\n';
(s) char ch = 'D'; std::cout << tolower(ch) << '\n';
(t) std::cout << exp(4.5, 3) << '\n';
(u) std::cout << toupper('7') << '\n';
(v) double a = 5, b = 3; std::cout << exp(a, b) << '\n';
(w) std::cout << exp(3, 5, 2) << '\n';
(x) std::cout << tolower(70) << '\n';
(y) double a = 5; std::cout << exp(a, 3) << '\n';
(z) double a = 5; std::cout << exp(3, a) << '\n';
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images