Answer to Question #255181 in C++ for Chaz

Question #255181
Write a C++ program to help Dr Plaatje with the running of her surgery. Your program should use 3 arrays, one to store ages of patients, one to store financial data, that is fees patients paid, the last one stores file or patient Id’s. Assume array length of 100. Your program must further do the following: 1) Search the array containing the ages for youngest patient and the oldest patient and print the patient Id and the corresponding ages. 2) Traverses the financial data array to calculate total income for the day and print the total. 3) Count and prints the total number of patients seen on the day.
1
Expert's answer
2021-10-22T08:31:30-0400
#include <iostream>
#include <string>
using namespace std;




int main()
{


	//Your program should use 3 arrays, one to store ages of patients, one to store financial data, 
	//that is fees patients paid, the last one stores file or patient Id’s. 
	//Assume array length of 100. 
	int ages[100];
	float fees[100];
	int Id[100];
	int totalPatients=0;
	float totalIncome=0;
	cout<<"Enter the number of patients: ";
	cin>>totalPatients;
	for(int i=0;i<totalPatients;i++){
		cout<<"Enter age of the patient "<<(i+1)<<": ";
		cin>>ages[i];	
		cout<<"Enter fees patients paid of the patient "<<(i+1)<<": ";
		cin>>fees[i];
		cout<<"Enter id of the patient "<<(i+1)<<": ";
		cin>>Id[i];
		cout<<"\n";
	}


	//Your program must further do the following: 
	//1) Search the array containing the ages for youngest patient and the oldest patient and print the patient 
	//Id and the corresponding ages. 
	int youngestPatient=ages[0];
	int oldestPatient=ages[0];


	int youngestPatientIndex=0;
	int oldestPatientIndex=0;


	for(int i=0;i<totalPatients;i++){
		if(youngestPatient>ages[i]){
			youngestPatient=ages[i];
			youngestPatientIndex=i;
		}
		if(oldestPatient<ages[i]){
			oldestPatient=ages[i];
			oldestPatientIndex=i;
		}
		totalIncome+=fees[i];
	}
	cout<<"\nYoungest patient with id "<<Id[youngestPatientIndex]<<" is "<<ages[youngestPatientIndex]<<" years old\n";
	cout<<"Oldest patient with id "<<Id[oldestPatientIndex]<<" is "<<ages[oldestPatientIndex]<<" years old\n";
	
	//2) Traverses the financial data array to calculate total income for the day and print the total. 
	cout<<"\nTotal income: "<<totalIncome<<"\n";
	//3) Count and prints the total number of patients seen on the day.
	cout<<"The total number of patients seen on the day: "<<totalPatients<<"\n";


	cin>>totalPatients;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS