-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathExercise 3.5 (Completed)
149 lines (143 loc) · 5.1 KB
/
Exercise 3.5 (Completed)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
1. (Modify) Rewrite the following program to use the symbolic constant PI in place of the
value 3.1416 used in the program:
#include <iostream>
using namespace std;
int main()
{
double radius, circum;
cout << “Enter a radius: “;
cin >> radius;
circum = 2.0 * 3.1416 * radius;
cout << “\nThe circumference of the circle is “
<< circum << endl;
return 0;
}
----------------Corrected---------------------------------------
#include <iostream>
using namespace std;
int main()
{
double radius, circum, PI;
PI = 3.1416;
cout << “Enter a radius: “;
cin >> radius;
circum = 2.0 * 3.1416 * radius;
cout << “\nThe circumference of the circle is “
<< circum << endl;
return 0;
}
2. (Modify) Rewrite the following program to use the named constant FACTOR in place of the
expression (5.0/9.0) used in the program:
#include <iostream>
using namespace std;
int main()
{
double fahren, celsius;
cout << “Enter a temperature in degrees Fahrenheit: “;
cin >> fahren;
celsius = (5.0/9.0) * (fahren - 32.0);
cout << “The equivalent Celsius temperature is “
<< celsius << endl;
return 0;
}
-------------Corrected------------------------------------
#include <iostream>
using namespace std;
int main()
{
double fahren, celsius, FACTOR;
FACTOR = (5.0/9.0);
cout << “Enter a temperature in degrees Fahrenheit: “;
cin >> fahren;
celsius = FACTOR * (fahren - 32.0);
cout << “The equivalent Celsius temperature is “
<< celsius << endl;
return 0;
}
3. (Modify) Rewrite the following program to use the symbolic constant PRIME in place of the
value 0.04 used in the program:
#include <iostream>
using namespace std;
int main()
{
double prime, amount, interest;
prime = 0.04; // prime interest rate-
cout << Enter the amount: “;
cin >> amount;
interest = prime * amount;
cout << “The interest earned is “
<< interest << “ dollars” << endl;
return 0;
}
-------------------Corrected------------------
#include <iostream>
using namespace std;
int main()
{
double prime, amount, interest;
cout << "Enter the amount: "<< endl;
cin >> amount;
cout << "Enter the prime : "<< endl;
cin >> prime;
interest = prime * amount;
cout << “The interest earned is “
<< interest << “ dollars” << endl;
return 0;
}
4. (Program) Heat is radiated from the sun and all planets orbiting the sun. The heat that’s radiated
can be calculated by using the following formula:
E = e σ T^4
E is the energy radiated per second in units of watts per meter squared (watts/m2).
e is the emissivity of the substance, which is 1 for the sun and all the planets.
σ is the constant (.000000056697 = 5.6697e-8).
T is the surface temperature in degrees Celsius.
For example, the heat radiated from the sun, which has an emissivity of 1 and a surface temperature
of approximately 6000° C, is as follows:
E = (1) × (.000000056697) × (6000)4 watts/m2
= 73,479,300 watts/m2
Using the formula, write a C++ program that accepts a planet’s temperature and provides the
heat generated from the planet as its output. Your program should assign the value 5.6697e-8
to a symbolic constant named HEATFACTOR.
#include <iostream>
#include <math.h>
using namespace std;
int main(){
double E,e, T, HEATFACTOR;
HEATFACTOR = 5.6697*exp(-8);
e = 1;
cin >> σ >> T;
E = e * HEATFACTOR * pow(T,4);
cout << E << endl;
return 0;
}
After determining that your program is working correctly (make sure it produces the correct radiation for the sun),
use it to complete the following chart:
Planet (emissivity = 1) Average Surface Heat Radiated
Temperature (° Celsius) (watts/m2)
Mercury 270 * 301.311 *
Venus 462 * 2583.020 *
Earth 14 * 0.002 *
5. (Program) During the day, heat is absorbed by many objects, such as cars, roofs, and brick
walls. This heat is then radiated back into the environment during the cooler evening hours.
Using the formula E = e σ T4 (see Exercise 4), write a C++ program that determines the
amount of heat radiated for the objects listed in the following table. Your program should
request the object’s average surface temperature and emissivity, and then calculate and display
the heat radiated. Make sure to use a symbolic constant named HEATFACTOR for the value of
σ.
#include <iostream>
#include <math.h>
using namespace std;
int main(){
double E,e, T, HEATFACTOR;
HEATFACTOR = 5.6697*exp(-8);
cin >> e >> HEATFACTOR >> T;
E = e * HEATFACTOR * pow(T,4);
cout << E << endl;
return 0;
}
Complete the following chart, making three runs of the program:
Substance Average Surface Emissivity Heat Radiated
Temperature(° Celsius) (watts/ms)
Automobile 47 .3 .082999
Brick 45 .9 .209244
Commercial roof 48 .05 .0150486