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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
LAB 2 SUBJECT: Algorithms, Compiling, Debugging Goal: Enter and compile a program. Write an algorithm (psuedo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’,...

    Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9. I have posted 3 input files: sudoku1.txt, sudoku2.txt and sudoku3.txt Problem Analysis & Design - Think about how you will need to solve this problem. You should do an...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • Write a Python program that calculate and summarize the sales of every day and finds out...

    Write a Python program that calculate and summarize the sales of every day and finds out who are the best employee who made more profits. For simplicity: We assume that the program works for only two days and for only two employees. i.e. the program collects and summarize the sales of only two days for only two employees The program accepts undefined number of sales for each employee. For example: You could assume in the first day the first employee...

  • O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input image...

    c++ solve each task please O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input images that fit into the array, don't Thard-code" the cat picture dimensions into the program, use variables w and h instead Task D. One-pixethick frame Program frame.cpp Same as the previous task, but it should be a frame exactly one pixel thick Example: Task E. Scale 200% Program scale.cpp Scale the original picture to 200% of its size. It can be done by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT