Question

In: Computer Science

Please write with structure, not class! Add comments for clear understanding. Write code without using scope...

Please write with structure, not class! Add comments for clear understanding. Write code without using scope resolution operators.

Write an ADT to represent a doctor's medical registration number (a non-negative integer), number of patients (a non-negative integer), and income (non-negative, in euros).
A doctor's information should be represented by a structure with 3 fields: medical_reg and num_patients of type int, and income of type float.
Your ADT should define four interface functions to carry out the following operations:

· Construct a new doctor, given input arguments for medical registration number, number of patients, and income. This function should not do any error-checking on its inputs.
· Print out to the screen the values of medical registration number, number of patients, and income for a specified doctor.
· Add two doctors to return a new ‘doctor' by adding the values of the corresponding number of patients and income fields, inserting a dummy value for the medical registration number of the new ‘doctor'. A dummy value is something that could not be a valid value; you must decide what an appropriate dummy value is in this case.
· Compare 2 doctors to determine which of them is "greater", according to these rules: the doctor with the higher income is greater; if the 2 doctors have the same income, the doctor with more patients is greater; if both income and number of patients are the same, the 2 doctors are equal. This function does not return a value, but prints out the values for the "greater" doctor or that the doctors are equal, as appropriate.

Write a main function which tests each aspect of your work:
ask the user for the values of medical registration number, number of patients, and income for 2 doctors;
print out each doctor's values;
then print out the values for the addition of these 2 doctors, and determine which of them (if either) is "greater".
You may assume that the user enters valid values for each doctor's fields from the keyboard.

So you should write three files:
· A header file to hold the structure definition and the prototypes of the interface functions
· A C++ source file to hold the implementations of the interface functions
· Another C++ source file to hold the main program

Solutions

Expert Solution

Answer:-

Hello, I have written the required program in CPP. Please find it below. I have included all the 3 required files code.

Doctor.h

struct Doctor
{
   int medical_reg;
   int num_patients;
   float income;  
};
Doctor constructDoctor(int, int, float);
void displayDoctorInfo(Doctor);
Doctor addDoctor(Doctor, Doctor);
void compareDoctor(Doctor,Doctor);

Doctor.cpp

#include<iostream>
#include "Doctor.h"
using namespace std;

Doctor constructDoctor(int m,int n, float i)
{
   Doctor d1 = {m,n,i};
   return d1;
}

void displayDoctorInfo(Doctor d)
{
   cout<<"Medical Registration Number is "<<d.medical_reg<<endl;
   cout<<"Number of Patients is "<<d.num_patients<<endl;
   cout<<"Income is "<<d.income<<endl;
}

Doctor addDoctor(Doctor d1, Doctor d2)
{
Doctor d3 ={-1, d1.num_patients+d2.num_patients,d1.income+d2.income};
   return d3;  
}

void compareDoctor(Doctor d1,Doctor d2)
{
   if(d1.income>d2.income)
   {
   displayDoctorInfo(d1);  
   }
   else if(d1.income<d2.income)
   {
   displayDoctorInfo(d2);  
   }
   else
   {
   if(d1.num_patients>d2.num_patients)
   {
   displayDoctorInfo(d1);  
   }
   else if(d1.num_patients<d2.num_patients)
   {
   displayDoctorInfo(d2);  
   }
   else
   {
       cout<<"Doctors are equal";
       }  
   }
}

Source.cpp

#include<iostream>
#include "Doctor.cpp"
using namespace std;

int main()
{
   int medical_reg,num_patients;
   float income;
   cout<<"Enter details for first Doctor\nEnter Medical Registration Number";
   cin>>medical_reg;
   cout<<"Enter the number of patients ";
   cin>>num_patients;
   cout<<"Enter Income";
   cin>>income;
   Doctor d1 = {medical_reg, num_patients, income};
   cout<<"Enter details for Second Doctor\nEnter Medical Registration Number";
   cin>>medical_reg;
   cout<<"Enter the number of patients ";
   cin>>num_patients;
   cout<<"Enter Income";
   cin>>income;
   Doctor d2 = {medical_reg, num_patients, income};
   cout<<"Information for First Doctor\n";
   displayDoctorInfo(d1);
   cout<<"Information for Second Doctor\n";
   displayDoctorInfo(d2);
   cout<<"Information for Third Doctors by adding these two Doctors\n";
   displayDoctorInfo(addDoctor(d1,d2));
   cout<<"Information for greater Doctor\n";
   compareDoctor(d1,d2);
}

Screenshot of Code:-

Please refer to the screenshot of the code for properly understanding the indentation of the code.

Doctor.h

Doctor.cpp

Source.cpp

OUTPUT:-

Note:- Here, in the addDoctor() function, I have used a dummy value for medical registration number of a doctor which is -1.

I hope it would help.

Thanks!


Related Solutions

Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just need help understanding the code, don't need to modify it. The purpose of the code is to count the frequency of words in a text file, and return the most frequent word with its count. It uses two algorithms: Algorithm 1 is based on the data structure LinkedList. It maintains a list for word frequencies. The algorithm runs by scanning every token in the...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803 This assignment involves extension to the single source-single destination shortest path problem. The Program Your program should: 1. Read the name of a text file from the console. (Not the command line) 2. Read an undirected graph from the file. 3. Find the shortest path between the start and goal vertices specified in the file. 4. Print out the vertices on the path, in...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT