Pls I need Help!!!

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.

Hope this helps!
tanx my boss let me try
have run it but still not getting the concept only the i. is given error
pls can someone help me with an example so that i follow
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cmath>
#include <cctype>
using namespace std;

int main()
{
cout<<sqrt(4.5) <<endl;
cout<<sqrt(4.5, 3.1) <<endl;
cout<< rand(4) <<endl;

double d = 16.0;
cout<<sqrt(d) <<endl;
cout<<srand() <<endl;
cout<< rand() <<endl;

inti = 16;
cout<<sqrt(i) <<endl;

cout<<srand(55) <<endl;
cout<<tolower('A') <<endl;
cout<<exp() <<endl;
cout<<sqrt() <<endl;
cout<<toupper('E') <<endl;
cout<<toupper('e') <<endl;
cout<<toupper("e") <<endl;
cout<<exp(4.5) <<endl;
cout<<toupper('h', 5) <<endl;
cout<<ispunct('!') <<endl;
cout<<tolower("F") <<endl;

char ch = 'D';
cout<<tolower(ch) <<endl;
cout<<exp(4.5, 3) <<endl;
cout<<toupper('7') <<endl;

double a = 5, b = 3;
cout<<exp(a, b) <<endl;
cout<<exp(3, 5, 2) <<endl;
cout<<tolower(70) <<endl;

double a = 5;
cout<<exp(a, 3) <<endl;

}


That's what the program will look like.
Compile it.
List and resolve the errors.
Last edited on
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.
Last edited on
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??
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cmath>
#include <cctype>
using namespace std;

int main()
{
cout<<sqrt(4.5) <<endl;
//cout<<sqrt(4.5, 3.1) <<endl;
//cout<< rand(4) <<endl;

double d = 16.0;
cout<<sqrt(d) <<endl;
//cout<<srand() <<endl;
cout<< rand() <<endl;

int i = 16;
cout<<sqrt(i) <<endl;

//cout<<srand(55) <<endl;
cout<<tolower('A') <<endl;
//cout<<exp() <<endl;
//cout<<sqrt() <<endl;
cout<<toupper('E') <<endl;
cout<<toupper('e') <<endl;
//cout<<toupper("e") <<endl;
cout<<exp(4.5) <<endl;
//cout<<toupper('h', 5) <<endl;
cout<<ispunct('!') <<endl;
//cout<<tolower("F") <<endl;

char ch = 'D';
cout<<tolower(ch) <<endl;
//cout<<exp(4.5, 3) <<endl;
cout<<toupper('7') <<endl;

//double a = 5, b = 3;
//cout<<exp(a, b) <<endl;
//cout<<exp(3, 5, 2) <<endl;
cout<<tolower(70) <<endl;

//double a = 5;
//cout<<exp(a, 3) <<endl;

}
"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.
closed account (48T7M4Gy)
Exactly!
ooh ook. How can I say thanks to you all. You guys are really kind. continue with the good work to help us the weak ones here.
Am glad you are been helped out. Here is what you will have at the end;


i. cout << sqrt(4.5) << endl; -[output] 2.12132

ii. cout << sqrt(4.5, 3.1) << endl; -[Error] no matching function for call to ‘sqrt(double,double)’

iii. cout << rand(4) << endl; -[Error] ‘rand’ was declared in this scope.

iv. double d = 16.0;
cout << sqrt(d) << endl; -[output] 4

v. cout << srand() << endl; -[Error] ‘srand’ was not declared in this scope.

vi. cout << rand() << endl; -[Error] ‘rand’ was not declared in this scope.

vii. int i = 16;

cout << sqrt(i) << endl; -[output] 4

viii. cout << srand(55) << endl; -[Error] ‘srand’ was not declared in this scope.

ix. cout << tolower('A') << endl; -[output] 97

x. cout << exp() << endl; -[Error] no matching function for call to ‘expo()’.

xi. cout << sqrt() << endl; -[Error] no matching function for call to ‘sqrt()’.

xii. cout << toupper('E') << endl; -[output] 69

xiii. cout << toupper('e') << endl; -[output] 69

xiv. cout << toupper("e") << endl; -[Error] invalid conversion from 'const char*' to 'int' [-fpermissive]

xv. cout << exp(4.5) << endl; -[output] 90.0171

xvi. cout << toupper('h', 5) << -[Error] no matching function for call to 'toupper(char, int)'

xvii. cout << ispunct('!') << endl; -[output] 16

xviii. cout << tolower("F") << endl; - [Error] invalid conversion from 'const char*' to 'int' [-fpermissive]

xix. char ch = 'D';

cout << tolower(ch) << endl; -[output] 100

xx. cout << exp(4.5, 3) << endl; -[Error] no matching function for call to 'exp(double, int)'

xxi. cout << toupper('7') << endl; -[output]55

xxii. double a = 5, b = 3;
cout << exp(a, b) << endl; -[Error] no matching function for call to 'exp(double&, double&)'

xxiii. cout << exp(3, 5, 2) << endl; -[Error] no matching function for call to 'exp(int, int, int)'

xxiv. cout << tolower(70) << endl; -[output]102

xxv. double a = 5; -[Error] redeclaration of 'double a'

cout << exp(a, 3) << endl; -[Error] no matching function for call to 'exp(double&, int)'
Topic archived. No new replies allowed.