C# windows form Create an application that calculates the total cost of a hospit
ID: 3849665 • Letter: C
Question
C# windows form Create an application that calculates the total cost of a hospital stay. The daily base charge is exist350. The hospital also charges for medication, surgical fees, lab fees, and physical rehab. The application should accept the following input: The number of days spent in the hospital The amount of medication charges The amount of surgical charges The amount of lab fees The amount of physical rehabilitation charges Create and use the following value-returning methods in the application: CalcStayCharges-Calculates and returns the base charges for the hospital stay. This is computed as exist350 times the number of days in the hospital. CalcMiscCharges-Calculates and returns the total of the medication, surgical, lab, and physical rehabilitation charges. CalcTotalCharges-Calculates and returns the total charges.Explanation / Answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Hospital_Charges
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// number of days at the hospital
// medical charges as arguments and return the
// equivalent total of charges
private double CalcStayCharges(double days)
{
return days * 350.0;
}
private double CalcMiscCharges(double medical, double surgical, double lab, double rehab)
{
return (medical + surgical + lab + rehab);
}
private double CalcTotalCharges(double days, double medical, double surgical, double lab, double rehab)
{
return CalcStayCharges(days) + CalcMiscCharges(medical, surgical, lab, rehab);
}
private void calculateButton_Click(object sender, EventArgs e)
{
// to hold the number of days spent at the hospital, amount of medication, surgical, lab and rehab charges.
double days, stayTotal, medical, surgical, lab, rehab, totalFees, totalCharges;
// number of days.
if (!double.TryParse(daysTextBox.Text, out days) || days <= 0.0)
{
MessageBox.Show("Length of stay (days) is invalid. Please enter a valid number");
daysTextBox.Focus();
return;
}
// medication charges
if (!double.TryParse(medicationTextBox.Text, out medical) || medical < 0.0)
{
MessageBox.Show("Medication charges are invalid. Please enter a valid number");
medicationTextBox.Focus();
return;
}
// surgical charges
if (!double.TryParse(surgicalTextBox.Text, out surgical) || surgical < 0.0)
{
MessageBox.Show("Surgical charges are invalid. Please enter a valid number");
surgicalTextBox.Focus();
return;
}
// lab fees
if (!double.TryParse(labTextBox.Text, out lab) || lab < 0.0)
{
MessageBox.Show("Lab fees are invalid. Please enter a valid number");
labTextBox.Focus();
return;
}
// physical rehabilitation charges
if (!double.TryParse(rehabTextBox.Text, out rehab) || rehab < 0.0)
{
MessageBox.Show("Phycial rehabilitation charges are invalid. Please enter a valid number");
rehabTextBox.Focus();
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.