In: Computer Science
NEED ASAP PLEASE IF THIS CANNOT BE ANSWERED WITHIN 1 HOUR TO 1.5 HOURS MAX PLEASE DO NOT DO
I DON'T NEED PROBLEMS 1-4 PLEASE ANSWER 5-7 ONLY. ONLY LISTED 1-4 AS A REFERENCE.
This should be in
Type of application :Console application
Language used :C#
Program.cs :
Problem 1:
(15 pts)
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.
Problem 2:
(20 pts) Create a Patient class which has private fields for patientid, lastname,
firstname, age, and email. Create public properties 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.
Problem 3:
(15 pts) 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.
Problem 4:
(10 pts) Add a static display method in the main class in the patient application
that has a parameter to pass a patient object and display its content.
Problem 5:
(10 pts) 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.
Problem 6:
(20 pts) 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.
Problem 7:
( 10 pts) Modify the base class of Problem 6 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.
QUES: 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.
SOLUTION IN C++
#include <iostream>
#include <conio.h>
using namespace std;
class patient
{ char firstname[100];
char lastname[100]; // varibles declration of patient class
char email_id[100];
int patientid;
public:
void getdata()
{
cout<<"FirstName: ";
cin>>firstname;
cout<<"lastName: ";
cin>>lastname;
cout<<"email id: ";
cin>>email_id;
cout<<"patientid ";
cin>>patientid;
}
void setdata()
{
cout<<"firstname: "<<firstname<<endl;
cout<<"lastname "<<lastname<<endl;
cout<<"email_id "<<email_id<<endl;
}
};
class outpatient: public patient
{
int doctorOfficeID;
public:
void getdata()
{
patient::getdata(); //get method of patient
cout<<"doctorOfficeID.";
cin>>doctorOfficeID;
}
void setdata()
{
patient::setdata(); //set method of patient
cout<<"doctorOfficeID."<<doctorOfficeID<<endl;
}
};
class inpatient: public patient
{
int hospitalID;
public:
void getdata()
{
patient::getdata(); //get method of patient
cout<<"hospitalID ";
cin>>hospitalID;
}
void setdata()
{
patient::setdata(); //set method of patient
cout<<"hospitalID "<<hospitalID;
}
};
int main()
{
outpatient s; //need two objects because there are two derived classes
inpatient e;
cout<<"////////////////outpatient details///////////////"<<endl;
cout<<"Enter data"<<endl;
s.getdata();
cout<<endl<<"Displaying data"<<endl;
s.setdata();
cout<<endl<<"/////////////inpatient details///////////////"<<endl;
cout<<"Enter data"<<endl;
e.getdata();
cout<<endl<<"Displaying data"<<endl;
e.setdata();
return 0;
}
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.
Solution:
#include <iostream>
using namespace std;
class patient {
int age;
public:
void bill()
{
int x=75,y=125;
cout<<" enter the age of patient";
cin>>age;
if (age>65)
{
cout << "standard rate is " << "$"<<x << endl;
}
else
{
cout<<" standard doctors office visit for patient"<<"$"<<y<<endl;
}}
void bill(int dis) {
if(age>65)
cout<<"discount"<<"$"<<dis<<endl;
}
};
int main()
{
patient pd; //object of patient
// Call bill method
pd.bill();
// Call bill method passing argument
pd.bill(125);
return 0;
}
Output: