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: 3853678 • 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.



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

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

Algorithm:

1.Initialize Weighted_Average to zero, declaring floating array s[7] for read scores.

2.Input:Enter four test scores corresponding weighted average.

3.Calculate weighted average using formula

Weighted_Average = s[0]*s[1]+ s[2]*s[3]+ s[4]*s[5]+ s[6]*s[7];

//here we are calculated for 4 test scores as given in the query.

4.print out put Weighted_Average.

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.

Algorithm:

1.Declaring radius,price and square_inch floating variables for storing their values,area to zero.

2.prompt to Enter the value radius of circle in inches

Read radius.

3. prompt to Enter the price of pizza

Read price

4.calculate area=pi* radius* radius..

5. calculate square_inch=cost/area.

6.print square_inch.

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

Alogrithm

1.Declaring variables bill_amount,number_of_trees,square_yards,fertilizing for store their corresponding values.

2.Promt to enter Number of square yards for mowing.

Read square_yards.

3.promt o enter number of fertilizing applications

Read fertilizing.

4.prompt to enter number of trees for planting tree

Read number_of_trees.

5.calculate

bill_amount = (square_yards*(5000/40))+ (fertilizing*35)+( number_of_trees*50)

6.Print bill_amount in dollars.

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

Algorithm:

Step1:Declaring a,b,c,r1,r2,r,d variables corresponding to store

their values.

Step2: enter values a,b and c of quadratic equation.

Read a,b,c

3.if(a==0) print input values are invalid

else calculate d=b*b-4*a*c;

4.If d<0

Print there are no real roots

5.if d=0

Calculate r= -b+sqrt(d)/2*a;

Print The roots are real and same is r

6.if d>0

Calculate r1 = (-b + sqrt(d)) / (2*a);

r2 = (-b - sqrt(d)) / (2*a);

Print the roots are real and different they are r1 r2