Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1-4. Design detailed algorithms for the following problems. Your algorithm must

ID: 3853653 • Letter: 1

Question

1-4. Design detailed algorithms for the following problems. Your algorithm must have at least 4 to 5 steps and be clear. Please refer to chapter 1 examples and write only algorithms in either pseudocode or step-by-step descriptions.

1. Design an algorithm to find the weighted average of four test scores. The input data needs to be read in as a series of score-weight pairs. For example, this sample input data corresponds to a weighted average of 80:
80 0.20 90 0.20 85 0.10 75 0.50
Be sure to initialize any variables to zero when necessary.

Step1: Mutiply80*0.20
Step2: Mutiply90*0.20
Step3: Mutiply85*0.10
Step4: Mutiply75*0.50
Step5: Find the sum of steps 1-4
Result: Weighted average of test scores

2. Write an algorithm to prompt for and then read in the radius, in inches, and price of a pizza; then, compute and output the price of the pizza per square inch.

3. Chris and Terry have opened a new lawn service. They provide three types of services: mowing, fertilizing, and planting trees. The cost of mowing is $40.00 per 5000 square yards, fertilizing is $35.00 per application, and planting a tree is $50.00. Write an algorithm that prompts the user to enter the area of the lawn, the number of fertilizing applications, and the number of trees to be planted. The algorithm then outputs the billing amount. (Assume that the user orders all three services.)

4. Design an algorithm to find the roots of a quadratic equation of the form ax2 + bx + c. First prompt for floating-point values a, b, and c. If a is zero, output a message that the input values are invalid; otherwise, if there are no real roots output a message that there are no real roots; otherwise output both roots

Explanation / Answer

ALGORITHM 1:

1)Read score and corrosponding weight for 4 test

2)Repeat 4 times for each pair ofscore and weight .

Multiply each score and weight and store in temp variable

Add temp to sum variable.

3)Calculate average using sum divided by total tests.

4)Print average

5)Exit

=================================================================

1)Start

2)enter radius in inches

3)enter price of pizza

4)find area of pizza using formula PI*r*r

5)Multiply given area with price ,then display price of pizza per sq inch

6)Exit

===========================================================

1)start

2)enter the area of the lawn,

3)Enter the number of fertilizing applications,

4)Enter the number of trees to be planted.

5)Calculate cost of moving as 40*area

6)Calculate cost of fertilizing as 35* number of fertilizing applications,

7)Calculate cost of planingas 50*number of trees

8)Add values in step fro step 5-7 and display

9)Exit

======================================================================

Step 1:
read a,b,c
Step 2:
if(a==0||b==0||c==0)
print "error:No roots"
stop
endif
Step 3:
if(b*b-4ac=0)
root1=root2=-b/2a
print "two roots are equal"
stop
endif
Step 4:
if(b*b-4ac>0) then
root1=-b+sqrt(b*b-4ac)/2a
root2=-b-sqrt(b*b-4ac)/2a
print two roots
stop
endif
Step 5:
if(b*b-4ac>0) then
Real=(-b/2a)
Img=sqrt(d)/2a
print two roots
stop
endif
Step 6:[Exit]
Stop