Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- class Patient {
- string name;
- string birthday;
- int numberOfVisits_forYear;
- public:
- Patient::Patient(string name_input, string birthday_input, int numberOfVisits_forYear_input)
- {
- name = name_input;
- birthday = birthday_input;
- numberOfVisits_forYear = numberOfVisits_forYear_input;
- }
- //get functions, защото член променливите са private, а ни трябват във функции извън класа (ония двете с fors)
- int getNumberOfVisits_forYear()
- {
- return numberOfVisits_forYear;
- }
- string getName()
- {
- return name;
- }
- string getBirthday()
- {
- return birthday;
- }
- };
- double getAverageVisits(Patient theDoctorsPatients[], const int numberOfPatients)
- {
- int totalVisitsOfAllPatients = 0; //
- for (int i = 0; i < numberOfPatients; i++) //за всеки пациент
- {
- totalVisitsOfAllPatients = totalVisitsOfAllPatients + theDoctorsPatients[i].getNumberOfVisits_forYear(); //вземи колко пъти е ходил до доктора и го добави към totalVisitsOfAllPatients
- }
- double average = double(totalVisitsOfAllPatients) / numberOfPatients; // double(totalVisits) защото иначе ако average e 4.2 ще си го закръгли на 4;
- return average;
- }
- void showPatientsWithVisitsMoreThanAverage(Patient theDoctorsPatients[], const int numberOfPatients) //хубаво име
- {
- double averageVisits = getAverageVisits(theDoctorsPatients, numberOfPatients);
- for (int i = 0; i < numberOfPatients; i++) //за всеки пациент
- {
- if (theDoctorsPatients[i].getNumberOfVisits_forYear() > averageVisits) {
- cout << theDoctorsPatients[i].getName() << " " << theDoctorsPatients[i].getBirthday() << " " << theDoctorsPatients[i].getNumberOfVisits_forYear() << endl;
- }
- }
- }
- void main()
- {
- Patient baba_1("Penka", "30/02/1930", 10);
- Patient baba_2("Sijka", "31/11/1930", 15);
- Patient dqdo_1("Pesho", "31/09/1914", 0); //може и да е на лошо нулата...
- Patient dqdo_2("Steven", "31/06/1928", 5);
- const int brojPensioneri = 4; //иска да е const, защото представлява брой на елементи в масив
- Patient pensionerite[brojPensioneri] = { baba_1, baba_2, dqdo_1, dqdo_2 };
- double averageVisitsCount = getAverageVisits(pensionerite, brojPensioneri);
- cout << "Average visits to the doctor: " << averageVisitsCount << endl;
- cout << "Patients with visits, higher than average: " << endl;
- showPatientsWithVisitsMoreThanAverage(pensionerite, brojPensioneri);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement