1 answer

LAB 2 SUBJECT: Algorithms, Compiling, Debugging Goal: Enter and compile a program. Write an algorithm (psuedo...

Question:

LAB 2 SUBJECT: Algorithms, Compiling, Debugging Goal: Enter and compile a program. Write an algorithm (psuedo code) to calculate the shaded area of the object below Algorithm should be general: It should work for all values of A,B,C,D and different number of boxes (drawing below shows 3 x 3 shaded boxes and 1 x 1 white boxes). Do not assume A=B or C-D (as shown in the first diagram). Do not assume that the boxes are 3x3 and 1x 1. Dimensions A & B refer to the small box indicated by the dotted line. The second image shows a second possible object. Your algorithm should work for both images. USE GOOD VARIABLE NAMES (NOT ABCD). 1)
media%2Fe0a%2Fe0a38eb2-0009-42e3-88a1-72
LAB 2 SUBJECT: Algorithms, Compiling, Debugging Goal: Enter and compile a program. Write an algorithm (psuedo code) to calculate the shaded area of the object below Algorithm should be general: It should work for all values of A,B,C,D and different number of boxes (drawing below shows 3 x 3 shaded boxes and 1 x 1 white boxes). Do not assume A=B or C-D (as shown in the first diagram). Do not assume that the boxes are 3x3 and 1x 1. Dimensions A & B refer to the small box indicated by the dotted line. The second image shows a second possible object. Your algorithm should work for both images. USE GOOD VARIABLE NAMES (NOT ABCD). 1)

Answers

Algorithm 1

//We will adopt the standard algorithm writing
//conventions as per Donald Knuth's book, The Art of Computer Programming

-------------
Answer to 1)
--------------

algorithm find_area
input:
    shaded_box_length, shaded_box_width, white_box_length, white_box_width
    Integers shaded_box_x, shaded_box_y, white_box_x, white_box_y: shaded_box_x is the number of shaded boxes in horizontal direction, white_box_y is the number of white boxes in verticial direction. Other definitions follow similarly.
output:
    area: the area of shaded boxes in total

number_of_shaded_boxes <- shaded_box_x * shaded_box_y
number_of_white_boxes <- white_box_x * white_box_y
area_of_shaded_box <- shaded_box_length * shaded_box_width
area_of_white_box <- white_box_length * white_box_width
area <- (number_of_shaded_boxes * area_of_shaded_box) - (number_of_white_boxes * area_of_white_box)

if area < 0
    print 'Area cannot be negative'
else
    print(area)


Explanation:
The algorithm simply calculates the area of shaded region by subtracting the total area of bigger box from the white boxes. The boundary conditions for values input to the program are not checked based on the assumption that a input function is doing the constraint checking. It should check for positive real values for dimensions entered and the dimensions of white box should not exceed the outer shaded box dimensions.

------------
Answer to 2)
------------

algorithm calculate_interest
input:
    interest_rate: the rate of interest
    principal: original loan amount
    payment: payment made in this year
    amount: outstanding amount before the start of the year
    year: current year number in which payments were made. eg.

2017 or 2018.
    year_of_loan: year in which loan was taken
output:
    interest: total interest on the loan in this year
    balance: outstanding amount at the end of this year

balance <- amount - payment
interest <- interest_rate*balance/100
amount <- balance + interest    //amount for next year

Explanation:
The algorithm takes in the the remaining balance prior to this year and then calculates the balance that will remain at the end of this year.
Interest is calculated using the formula I = PRT/100 where P is the principal amount, R is rate of interest and T is time. Here, T is 1 since we are calculating for each year.

------------
Answer to 3)
------------

algorithm medical_payments
input:
    total_charges: total charges overdue
    prescription_charge: charge per prescription
    prescription_quantitiy: number of prescriptions
output:
    customer_pay: amount paid by the patient
    insurance_company_pay: amount paid by the insurance company
assumption:
    presciption charges are excluded from total charges
variables:
    customer_deductible_amount: It is set to $1000 amount that each customer pays in the beginning.
assumption: total charges is greater than the deductible amount
    co_pay: fixed amount to be paid by the customer
    prescription_pay: total prescription charge
    prescription_co_pay: co pay for each prescription by customer
    prescription_insurance_pay: amount paid by insurance company for the presciption

if customer_deductible_amount > total_charges
    customer_deductible_amount <- customer_deductible_amount - total charges
    co_pay <- total_charges
    insurance_company_pay <- 0

else
    co_pay <- 0.2 * (total_charges - customer_deductible_amount)
    insurance_company_pay <- total_charges - co_pay

prescription_pay <- prescription_quantity * prescription_charge
prescription_co_pay <- prescription_quantity * 40
prescription_insurance_pay <- prescription_pay - prescription_co_pay

customer_pay <- co_pay + prescription_co_pay
insurance_company_pay <- insurance_company_pay + prescription_insurance_pay

Explanation:
The algorithm checks if the total charge is less than the deductible amount that customer has. If it is true than the amount is deducted from the deductible and insurance company doesn't pay anything other than the prescription fees. Otherwise, the 20% of the amount is paid by the customer and rest by insurance company. For presciptions, $40 is paid per prescription by the customer and rest by the insurance company.

Prescription charges are not included in the deductible and insurance company pays for them.

.

Similar Solved Questions

1 answer
How do you find the roots, real and imaginary, of #y= (x+2)^2-x-5 # using the quadratic formula?
How do you find the roots, real and imaginary, of #y= (x+2)^2-x-5 # using the quadratic formula?...
1 answer
A student adds 5.00 g of dry ice (solid #CO_2#) to an empty balloon. What will be the volume of the balloon at STP after all the dry ice sublimes (converts to gaseous #CO_2#)?
A student adds 5.00 g of dry ice (solid #CO_2#) to an empty balloon. What will be the volume of the balloon at STP after all the dry ice sublimes (converts to gaseous #CO_2#)?...
1 answer
For each of the following words, write the affix and how the affix changes the lexical...
For each of the following words, write the affix and how the affix changes the lexical category of the word. Indicate the type of the affix (derivational or inflectional affix). Some words may have more than one affix. In this case indicate the type of each affix and how each affix changes the lexic...
1 answer
Use the following information to determine the equilibrium Y in a 3-sector model: Y = C+I+G...
Use the following information to determine the equilibrium Y in a 3-sector model: Y = C+I+G where: C= 150+ 0.8DI | = 50 G = 200 Also assume that T = Tr = 0 DI = Y-T+ Tr $150 $400 $750 $2,000 $4,000 Question 22 (2.5 points) Which of the following actions will increase budget deficits and also the nat...
1 answer
Hello! I need help solving these problems for engineering economy. Please show the full solution and...
Hello! I need help solving these problems for engineering economy. Please show the full solution and all work for BOTH PROBLEMS. please write neatly and large (the resolution of photos on the site are low). please be as detailed as possible and answer BOTH questions. Thank you 8. Find the present ...
1 answer
You distilled 100 mL of 40:60 ethanol:water, and collected 20 mL of pure azeotrope. What is...
You distilled 100 mL of 40:60 ethanol:water, and collected 20 mL of pure azeotrope. What is the percent recovery of ethanol?...
1 answer
Consider the following information: Portfolio Expected Return Beta Risk-free 8 % 0 Market 10.2 1.0 A 8.2 0.7 a. Calculate the expected return of portfolio A with a beta of 0.7. (Round your answer to 2...
Consider the following information: Portfolio Expected Return Beta Risk-free 8 % 0 Market 10.2 1.0 A 8.2 0.7 a. Calculate the expected return of portfolio A with a beta of 0.7. (Round your answer to 2 decimal places.) Expected return % b. What is the alpha of portfolio A. (Negative value should be i...
1 answer
Problem 3-13 Schedules of Cost of Goods Manufactured and Cost of Goods Sold; Income Statement [LO3-3)...
Problem 3-13 Schedules of Cost of Goods Manufactured and Cost of Goods Sold; Income Statement [LO3-3) Superior Company provided the following data for the year ended December 31 (all raw materials are used in production as direct materials): $ 212,000 $ 264,000 Selling expenses Purchases of raw mate...
1 answer
Rewrite this papers by software Insert Node at position 3 From above Double linked list temp...
rewrite this papers by software Insert Node at position 3 From above Double linked list temp = head. and it moves to position 2 her...
1 answer
. In cash flows from financing activities, how much did the company borrow? 6 Months Ended...
. In cash flows from financing activities, how much did the company borrow? 6 Months Ended Consolidated Statements of Cash Flows-USD (S) $ in Thousands Jun. 30, 2018 Jun. 30, 2017 CASH FLOWS FROM OPERATING ACTIVITIES: Net income Adjustments to reconcile net income to net cash provided by operating a...
1 answer
An example of a capacity option in aggregate operations planning for services is inventory. True or...
An example of a capacity option in aggregate operations planning for services is inventory. True or False...
1 answer
Laurel contributed equipment worth $150,000, purchased 8 months ago for $164,500 cash and used in...
Laurel contributed equipment worth $150,000, purchased 8 months ago for $164,500 cash and used in her sole proprietorship, to Sand Creek LLC in exchange for a 20 percent profits and capital interest in the LLC. Laurel agreed to guarantee all $12,600 of Sand Creek’s accounts payable, but she di...
1 answer
Calculate the enthalpy change for the neutralization of HCl by NaOH?
In a coffee cup calorimeter, 50.0 mL of 1.0 M NaOH and 50.0 mL of 1.0 M HCl are mixed. Both solutions are originally at 23.5 degrees C and after the reaction, the final temperature is 29.9 degrees Celsius. Calculate the enthalpy change for the neutralization of HCl by NaOH I don't understand how...
1 answer
Q3. Explain the operation of constant Volts/Hz (V/f) control of induction motor - open loop implementation...
Q3. Explain the operation of constant Volts/Hz (V/f) control of induction motor - open loop implementation with linear offset. 10/30, 60H supply Diode rectifier No Vo Boost DB V2v, sin e voltage G V le Inverter ИЯ ve=v2v, sin (6 Speed command Motor Q3. Explain the operation of constant ...
1 answer
Junior rides his tricycle off a level porch. If he left the porch at a speed...
Junior rides his tricycle off a level porch. If he left the porch at a speed of 5 m/s and landed a horizontal distance of 2 m from the base, then what is the height of the porch?...
1 answer
Wasted Food. Today the hot topic of local food is present in the media. Read the...
Wasted Food. Today the hot topic of local food is present in the media. Read the Highlight section of Chapter 20 of nutrition textbook and discuss your feelings on Environmentally Friendly Food Choices. Make at least 2 points and give your thoughts. write 1 to 2 pages....
1 answer
I. For each case, calculate planned [desired] detection risk:                                 
I. For each case, calculate planned [desired] detection risk:                                        &nb...