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. Write a program to execute each of the following code, including the appropriate header in each program. 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.
i. cout<<sqrt(4.5) <<endl;
ii. cout<<sqrt(4.5, 3.1) <<endl;
iii. cout<< rand(4) <<endl;
iv. double d = 16.0;
cout<<sqrt(d) <<endl;
v. cout<<srand() <<endl;
vi. cout<< rand() <<endl;
vii. inti = 16;
cout<<sqrt(i) <<endl;
viii. cout<<srand(55) <<endl;
ix. cout<<tolower('A') <<endl;
x. cout<<exp() <<endl;
xi. cout<<sqrt() <<endl;
xii. cout<<toupper('E') <<endl;
xiii. cout<<toupper('e') <<endl;
xiv. cout<<toupper("e") <<endl;
xv. cout<<exp(4.5) <<endl;
xvi. cout<<toupper('h', 5) <<endl;
xvii. cout<<ispunct('!') <<endl;
xviii. cout<<tolower("F") <<endl;
xix. char ch = 'D';
cout<<tolower(ch) <<endl;
xx. cout<<exp(4.5, 3) <<endl;
xxi. cout<<toupper('7') <<endl;
xxii. double a = 5, b = 3;
cout<<exp(a, b) <<endl;
xxiii. cout<<exp(3, 5, 2) <<endl;
xxiv. cout<<tolower(70) <<endl;
xxv. double a = 5;
cout<<exp(a, 3) <<endl;
Please gurus kindly help me out I dont understand the question.
Put the code into the main() function of a program. Then add the headers to try to make it compile.
For each statement that won't compile, even with the right headers, write "error" for that question and the comment out the statement so the rest will compile.
Once you have the rest of the statements running, decide if the output is the only possible output or just one possible output. Write your answer accordingly.
Alright man.
He wants you to put all those declarations and assignment statements in a full working program.
Since he is using certain library functions like "sqrt" and "tolower",
he wants you to include the right header files in the program.
That means you need to include:
<cmath>
<cctype> in your header files so you can use the functions.
Then he wants you to compile the code.
If there is an error at particular line, write down what the error is.
If there is no error, write down the output (the answer).
If there is no error, but the output is undetermined, write down why the program is not evaluating the line.
tanx my boss. when i run in the c++ shell here i got errors in line 9,10,14,17,18,20,22,23,26,28,30,34,37,38,39,42 & 43 but i copy all the code together with the headers into dev c++ program and compile i had error in line 9 cout<<sqrt(4.5, 3.1) <<endl; so please could this be the only compile error? I am a little bit confused.
Boss pls I have seen the errors when i compiled. They are marked in red and the lines are also been showed and the particular kind of error that happened in that line. so pls after listing all the error should I provide a solution for them??
"They are marked in red and the lines are also been showed and the particular kind of error that happened in that line. so pls after listing all the error should I provide a solution for them??"
You don't need to provide a solution; according to your original post, you just need to provide the reason why the errors exist.
So for example on line 9, you can say that the parameters for the sqrt function were not properly declared.