Question

In: Computer Science

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves...

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves the data to a file called Patients.txt. The output should be in the following format: p#, PATIENT_NAME, BALANCE. Create a Patient class that contains fields for ID number, name, and current balance owed to the doctor’s office.

using System;
using static System.Console;
using System.IO;
class WritePatientRecords
{
static void Main()
{
// Your code here
}
}

Solutions

Expert Solution

/*C # program that prompts user to enter id ,name and balance owed to doctor .Then prompt continues until user enters 0 to stop reading. Then write the data to the file,Patients.txt . */
//WritePatientRecords.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WritePatientRecords
{
    class WritePatientRecords
    {
        static void Main(string[] args)
        {
            //string set to file name
            string filename="Patients.txt";
            //create an object,writer
            StreamWriter writer = new StreamWriter(filename);    
            //declare variables id,name and balance
            int id;
            string name;
            decimal balance;
            Console.Write ("Enter Patient #id or 0 to exit: ");
            //read id and parse to integer value
            int.TryParse (Console .ReadLine () , out id);
            /*Read data from user until id is not 0*/
            while (id!=0)
            {
                Console.Write("Enter Patient Name: ");
                name=Console.ReadLine();
                Console.Write("Enter balance: ");
                decimal.TryParse(Console.ReadLine(), out balance );
                //write the data to file
                writer.WriteLine("{0},{1},{2}", id, name, balance);
                Console.WriteLine();
                Console.Write("Enter Patient #id or 0 to exit: ");
                int.TryParse(Console.ReadLine(), out id);
            }
            //clsoe the writer object
            writer.Close();
            Console.WriteLine("Data write to file," + filename);
            Console.ReadLine();
        }
    }
}


----------------------------------------------------------------------------------------------------------------

//Patient.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WritePatientRecords
{
    //Patient class defintion
    class Patient
    {
        //instance variables
        private int pId;
        private string pName;
        private decimal pBalance;
        /*Constructor to set the values to
         this class instance variables */
        Patient(int id, string name, decimal balance)
        {
            pId = id;
            pName = name;
            pBalance = balance;
        }
        //PID property
        public int PID
        {
            set { value = pId; }
            get { return pId; }
        }
        //Name property
        public string Name
        {
            set { value = pName ; }
            get { return pName; }
        }
        //Balance property
        public decimal Balance
        {
            set { value = pBalance ; }
            get { return pBalance; }
        }
    } //end of the Patient
}

----------------------------------------------------------------------------------------------------------------

Sample Output:

Patients.txt file


Related Solutions

Create a C# application for Library that allows you to enter data for books and saves...
Create a C# application for Library that allows you to enter data for books and saves the data to a file named Books.txt. Create a Book class that contains fields for title, author, number of pages, and price of the book and ToString() method. The fields of records in the file are separated with asterisk (*). Expecting sentinel value for ending the process of writing to file is "000"
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Write a program that allows the user to enter two integers and a character If the...
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Write a Python program that allows the user to enter the total rainfall for each of...
Write a Python program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September 3.7 inches October 5.1 inches November 7.2...
# Write a function called `get_state_data` that allows you to specify a state, # then saves...
# Write a function called `get_state_data` that allows you to specify a state, # then saves a .csv file (`STATE_data.csv`) with observations from that state # This includes data about the state, as well as the counties in the state # You should use the full any.drinking dataset in this function (not just 2012) # Demonstrate that you function works by passing "Utah" to the function state_Utah <- get_state_data(Utah) ############################ Binge drinking Dataset ############################ # In this section, you will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT