b) computer program: see the sphere program above.
c) table:
|
r
|
V(r)
|
|
1
|
4.19
|
|
2
|
33.51
|
|
3
|
113.10
|
|
4
|
268.08
|
|
...
|
...
|
(Note: The function could also be described using mathematical notation or a graph.)
program lowestValue; { p98n2 lowest.pas --
find the lowest value
of the given function }
uses WinCrt;
var
x, f, lo, hi : real;
begin
writeln('Enter lo: ');
readln(lo);
writeln('Enter hi: ');
readln(hi);
writeln(' x
f'); { write headings }
x := lo;
while x <= hi do
begin
f := x * x - 5 * x + 4;
writeln(x : 6:2, ' ', f : 6:2);
x := x + 1.0;
end;
end.
program findBest2; { p102n1 findbst2.pas --
maximize the volume
of a cylinder }
uses WinCrt;
var
r, h, V, previousV, increase : real;
begin
writeln('What is the initial value of r?');
readln(r);
writeln('How much should r be increased each time?');
readln(increase);
previousV := 0;
V := 500 * r - 3.14159 * r * r * r;
while V >= previousV do
begin
r := r + increase;
previousV := V;
V := 500 * r - 3.14159 * r * r * r;
writeln(r : 10:3, V : 10:3);
end;
r := r - increase; { previous r was best }
h := (1000 - 2 * 3.14159 * r * r) / ( 2 * 3.14159 * r);
writeln('r = ', r : 10:3, ' h = ', h : 10:3);
writeln('maximum volume = ', previousV : 10:3);
end.
program temperatureArray; { temparr.pas --
store 24 temperatures
in an array
and allow user to query
array }
uses WinCrt;
type
tempArray = array[1..24] of real;
var
temp : tempArray;
i : integer;
begin
{ store 24 temperatures in an array }
i := 1;
while i <= 24 do
begin
writeln('Enter temp ', i);
readln(temp[i]);
i := i + 1;
end;
{ allow user to query array }
while i <> 0 do
begin
writeln('Which temp do you want? (1 - 24; 0 to stop)');
readln(i);
if (i >= 1) and (i <= 24) then
begin
writeln('temp ', i, ' is ', temp[i]
: 5:2);
end
else
begin
if i <> 0 then
begin
writeln(i, ' is
out of range.');
end;
end;
end;
end.
program search; { p110n2 search.pas --
search an array of integers
}
uses WinCrt;
type
intArray = array[1..10] of integer;
var
A : intArray;
i, n : integer;
found : string;
begin
{ fill the array }
i := 1;
while i <= 10 do
begin
writeln('Enter integer number ', i);
readln( A[i] );
i := i + 1;
end;
{ search the array }
writeln('Enter the integer to search for.');
readln(n);
i := 1;
found := 'false';
while (found = 'false') and (i <= 10) do
begin
if n = A[i] then
begin
writeln('FOUND');
found := 'true';
end;
i := i + 1;
end;
if found = 'false' then
begin
writeln('NOT FOUND');
end;
end.
p. 89 Exercise 2