1. translate the algorithm to C++ and write the C++ using Xcoral
2. Compile your C++ program using g++
3. Test the program on several inputs, convince yourself that it works
under different conditions. There may be some inputs that make the
program not work properly, bring those to the attention of your
professor before you proceed to fixing those. To fix any problem in
the program, use Xcoral to edit the program, save the program, and
then recompile using g++.
REMEMBER: if you are looking at a compiler error for more than 5 mins or so, then ask for help.
host% cd host% cd cis121 host% mkdir lab-translate host% cd lab-translate
host% xcoral search_average.cpp &Now here is the algorithm:
get the values of numbers L1, L2,...LN
get the value of Search
set the value of i to 1
while (i <= N)
if (Search equals Li)
print Li
add 1 to i
End While
set average to result of subalgorithm ComputeAverage(L, N)
if average < 0
print "divide by 0 error in computing average"
else
print "the average is " average
endif
Stop
ComputeAvarege Alg (L, N)
set the value of i to 1
set the value of sum to 0
While i <= N
set the value of sum to sum + Li
End While
if N greater than 0
return sum/N
else
return -1
endif
Stop
Remember to save the program after each change before you compile. Look back at the previous lab for the command to compile programs. If you do not have it with you, then you may get it from the class website (print and keep a copy of that lab with you at all times).
host% turnin cis121a testturnin search_average.cppif you get an error message then notify your professor.
get the value of N
set the value of i = 1
set the value of j = 0
While (j < N)
set the value of i to 1
While (i <= N)
print i
set the value of i to i + 1
End While
print endl
set the value of j to j + 1
End While
host% print patterns.cpp search_average.cpp
select either printer that is in room 223, and go get your output off of the printer.