181k views
5 votes
Write a program that computes a patient's bill for a hospital stay. The different components of the program are

• The PatientAccount class will keep track of the patient's charges. It will keep track of the number of days spent in the hospital.
• The surgery method will have the charges for at least five types of surgery. It will update the charges member variable. A data file will contain at least five types of surgery and its cost. Both type and cost will be separated by commas.
• The pharmacy method will have the charges for at least five types of medication. It will update the charges member variable. A data file will contain at least five types of medication and its cost. Both type and cost will be separated by commas
• The dayCharge method will update the days sent member variable.
• The setName method will assign the name of the patient
• Each day in the hospital costs $1,000
The program will have a menu that allows the user to enter type of surgery, enter type of medication, number of days in the hospital and check the patient out of the hospital.
When the patient checks out, the total charges will be displayed.
(LOOK AT PIC BELOW, PYTHON)

Write a program that computes a patient's bill for a hospital stay. The different-example-1

1 Answer

5 votes

here's an example implementation of the program in Python

class PatientAccount:

def __init__(self, name):

self.name = name

self.days_spent = 0

self.charges = 0

def surgery(self, surgery_type, cost):

self.charges += cost

print(f"{surgery_type} surgery added to charges.")

def pharmacy(self, medication_type, cost):

self.charges += cost

print(f"{medication_type} medication added to charges.")

def dayCharge(self):

self.days_spent += 1

print("Day charge added.")

def setName(self, name):

self.name = name

print(f"Name set to {name}.")

def getTotalCharges(self):

total_charges = self.days_spent * 1000 + self.charges

print(f"Total charges: ${total_charges}")

return total_charges

patient = PatientAccount("John Doe")

while True:

print("Hospital Bill Menu:")

print("1. Add surgery")

print("2. Add medication")

print("3. Add day charge")

print("4. Set patient name")

print("5. Check out and calculate total charges")

choice = input("Enter choice (1-5): ")

if choice == "1":

surgery_type = input("Enter type of surgery: ")

cost = float(input("Enter cost: "))

patient.surgery(surgery_type, cost)

elif choice == "2":

medication_type = input("Enter type of medication: ")

cost = float(input("Enter cost: "))

patient.pharmacy(medication_type, cost)

elif choice == "3":

patient.dayCharge()

elif choice == "4":

name = input("Enter patient name: ")

patient.setName(name)

elif choice == "5":

total_charges = patient.getTotalCharges()

break

else:

print("Invalid choice. Try again.")

print("Thank you for using the hospital bill program.")

Step-by-step explanation:

This program defines a PatientAccount class that keeps track of the patient's name, days spent in the hospital, and charges. It also includes methods to add surgery and medication charges, add day charges, and set the patient name. The getTotalCharges method calculates the total charges based on the number of days spent in the hospital and the accumulated charges.

The program uses a while loop to display a menu of options and accept user input. The user can add surgery or medication charges, add a day charge, set the patient name, or check out and calculate the total charges. The loop continues until the user chooses to check out.

User AXE Labs
by
8.2k points

No related questions found