Question

In: Computer Science

Write a C# console program that continually asks the user "Do you want to enter a...

Write a C# console program that continually asks the user "Do you want

to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters

either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and

then get keyboard input of the name. After entering the name, display the name to the screen.

---

Create a Patient class which has private fields for patientid, lastname,

firstname, age, and email. Create public data items for each of these private fields with get and

set methods. The entire lastname must be stored in uppercase. Create a main class which

instantiates a patient object and sets values for each data item within the class. Display the

data in the object to the console window.

---

Modify the Patient class with two overloaded constructors: A new default

constructor which initializes the data items for a patient object using code within the

constructor (use any data). A second constructor with parameters to pass all the data items

into the object at the time of instantiation. Create a test main class which instantiates two

objects. Instantiate the first object using the default constructor and the second object using

the constructor with the parameters.

---

Modify the main class in the patient application to include a display

method that has a parameter to pass a patient object and display its content.

---

Modify the patient class with two overloaded methods to display a bill for a

standard visit based on age. In the first method do not use any parameters to pass in data. If

the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard

doctors office visit is $125. Build a second method where you pass in a discount rate. If the

patient is over 65, then apply the discount rate to a standard rate of $125. Create a main

method that calls both of these methods and displays the results.

-----

Create two subclasses called outpatient and inpatient which inherit from

the patient base class. The outpatient class has an additional data field called doctorOfficeID

and the inpatient class has an additional data item called hospitalID. Write a main method that

creates inpatient and outpatient objects. Sets data for these objects and display the data.

---

Modify the base class of Problem 5 to be an abstract class with an abstract

display method called displayPatient that does not implement any code. Create specific

implementations for this method in both the outpatient and inpatient subclasses

Solutions

Expert Solution

Question 1:

Application name :ConsoleApp_NameDisplay

Type of application :Console application

Language used :C#

Program.cs :

//namespace
using System;
//application namespace
namespace ConsoleApp_NameDisplay
{
class Program //C# class
{
//main() method
static void Main(string[] args)
{
Console.WriteLine("Do you want to enter a name(Y / N) ? ");
//reading user response
string userResponse = Console.ReadLine();
//using while loop
while(true)
{
//This line will ask user First name and last name
Console.Write("Enter First and Last Name:");
//reading first and last name
string firstLastName = Console.ReadLine();
//display first name and last name
Console.WriteLine(firstLastName);
//asking user whether want to continue
Console.WriteLine("Do you want to enter a name(Y / N) ? ");
//reading user response
userResponse = Console.ReadLine();
//checking firstLastName
if (userResponse.ToUpper()== "Y")
{
//when user response is Y then continue while loop
continue;
}
else
{
break;//break while loop
}
}
}
}
}
=========================================================

Output :

****************************************************

Question 2 :

Application name :ConsoleApp_Patient

Type of application :Console application

Language used :C#

Patient.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//public data items for each of these private fields with get and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
}
}
********************************

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//Object of patient class
Patient patient = new Patient();
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
patient.PatientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
patient.LastName = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
patient.FirstName = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
patient.Age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
patient.Email = Console.ReadLine();
//display patient details
Console.WriteLine(patient.PatientID+" , "+patient.LastName+" , "+patient.FirstName+" , "+patient.Age+" , "+patient.Email);
//to hold the screen
Console.ReadKey();
}
}
}
===========================================

Output :


*************************************************

Question 3 :modifications

Patient.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//default constructor
public Patient()
{
patientid = 102;
lastname = "defaultLastName";
firstname = "defaultFirstName";
age = 21;
email = "[email protected]";
}
//overloaded constructor
public Patient(int pid,string lname,string fname,int ag,string mail)
{
patientid = pid;
lastname = lname;
firstname = fname;
age = ag;
email = mail;
}
//public data items for each of these private fields with get and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
}
}
********************************************

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//Object of patient class
Patient patient = new Patient();
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
int patientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
string lastname = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
string firstname = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
int age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
string email = Console.ReadLine();
//display patient details
Console.WriteLine(patient.PatientID+" , "+patient.LastName+" , "+patient.FirstName+" , "+patient.Age+" , "+patient.Email);
//creating another object of
Patient patient1 = new Patient(patientID, lastname, firstname, age, email);
//display patient details
Console.WriteLine(patient1.PatientID + " , " + patient1.LastName + " , " + patient1.FirstName + " , " + patient1.Age + " , " + patient1.Email);
//to hold the screen
Console.ReadKey();
}
}
}
=========================================

Output :

*******************************************

Question 4 :

Patient.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//default constructor
public Patient()
{
patientid = 102;
lastname = "defaultLastName";
firstname = "defaultFirstName";
age = 21;
email = "[email protected]";
}
//overloaded constructor
public Patient(int pid,string lname,string fname,int ag,string mail)
{
patientid = pid;
lastname = lname;
firstname = fname;
age = ag;
email = mail;
}
//public data items for each of these private fields with get and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
//method to calculate bill
public double calculateBill()
{
double fee = 0;//declaring variable to store fee
//checking age
if(age>65)
{
//when age is greater than 65 then
fee = 75;
}
else
{
//If the patient is under 65, then the standard
// doctors office visit is $125.
fee = 125;
}
return fee;
}
//method to calculate bill
public double calculateBill(double discountRate)
{
double fee = 0;//declaring variable to store fee
//checking age
if (age > 65)
{
//when age is greater than 65 then
fee = 75-75* discountRate;
}
else
{
//If the patient is under 65, then the standard
// doctors office visit is $125.
fee = 125-125*discountRate;
}
return fee;
}
}
}
*******************************************

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
int patientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
string lastname = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
string firstname = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
int age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
string email = Console.ReadLine();
//creating another object of
Patient patient1 = new Patient(patientID, lastname, firstname, age, email);
//display patient details
Console.WriteLine(patient1.PatientID + " , " + patient1.LastName + " , " + patient1.FirstName + " , " + patient1.Age + " , " + patient1.Email);
//calling method and passing age
Console.WriteLine("Bill : "+patient1.calculateBill());
//asking user discount rate
Console.Write("Discount rate : ");
//double discount rate
double discountRate = double.Parse(Console.ReadLine());
//calling method and passing age
Console.WriteLine("Bill : " + patient1.calculateBill(discountRate/100));
//to hold the screen
Console.ReadKey();
}
}
}
==========================================

Output :


Related Solutions

Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
In C#, write a console-based program that asks a user to enter a number between 1...
In C#, write a console-based program that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined where you...
I need this written in C # ASAP Write a C# console program that continually asks...
I need this written in C # ASAP Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT