Question

Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message:

No records found for p#

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

code:

using system;

using static System.console;

using System.IO;

namespace findPatientRecords

{

class Program

{

static void Main(string[] args)

{

string patientld;

char[] splitter = new char[1] { ',' };

            //ask for user input

            Write("Enter a patients id: ");

            patientId = ReadLine();

            //read all the lines from patgients.txt

            var lines = File.ReadAllLines("patients.txt");

            bool recordFound = false;

            //iterate over all the lines

            foreach (var line in lines)

            {

                //split the line based on ,

                var patientData = line.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

               //search if patient id is as given

                if (patientData[0].Equals(patientId))

                {

                    //display the record and break the loop

                    WriteLine($"Patient Id {patientData[0]}, Name: {patientData[1]}, Bill: {patientData[2]}");

                    recordFound = true;

                    break;

                }

               

            }

            //if record not found then display the given message

            if (!recordFound)

            {

                WriteLine($"No records found for {patientId}");

            }

           

            //you can remove this line of code, this is kept to show output on screen

            ReadLine();

        }

    }

}

=========screen shot of the code========

Select copy if new or copy always option for patients.txt as highlighted below:

Output:

Add a comment
Know the answer?
Add Answer to:
Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...
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 the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

    Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message: No records found for p# using System; using static System.Console; using System.IO; class FindPatientRecords { static void Main() { // Your code here } }

  • Write a program named CheckMonth2 that prompts a user to enter a birth month and day....

    Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...

  • 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 } }

  • Write a C++ Program Write a program that prompts the user to input a number. The...

    Write a C++ Program Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: 1 Name: Your Name ID: Your ID #include <iostream> using namespace std; din main YOUR CODE HERE

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • The program prompts the user to input three words, then display them in      sorted order....

    The program prompts the user to input three words, then display them in      sorted order. Strings have to be compared with compareTo method. */ import java.util.Scanner; public class Lab4Part13{     public static void main(String[] args){         Scanner input = new Scanner(System.in);         // Write rest of the code here     } }

  • Task 1 : Write a Java program that prompts for and reads 10 integers from the...

    Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.

  • Complete the following program so it prompts the user for 3 integers and displays the smallest...

    Complete the following program so it prompts the user for 3 integers and displays the smallest of the 3 numbers. For instance, if the user provided 7 4 and 12, then the program would display 4. import java.util.Scanner; public class Program3{ public static void main(String[] args) { Scanner kb = new Scanner(System.in);

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...

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