Лабораторная работа вариант. Файзиматов у hsm-206 Проверила: Хайдарова М


Download 1.27 Mb.
bet2/2
Sana18.06.2023
Hajmi1.27 Mb.
#1558264
TuriЛабораторная работа
1   2
Bog'liq
прог лаб 1 Файзиматов У

2-способ.
#include
#include

using namespace std;

class Employee {
private:
string firstName;
string lastName;
string middleName;
string jobTitle;
double salary;
int birthYear;
public:
void input(Employee obj[], int n);
void outputYoungest(Employee obj[], int n);
};

void Employee::input(Employee obj[], int n) {
for(int i = 0; i < n; i++) {
cout << "Enter the first name of employee " << i + 1 << ": ";
cin >> obj[i].firstName;
cout << "Enter the last name of employee " << i + 1 << ": ";
cin >> obj[i].lastName;
cout << "Enter the middle name of employee " << i + 1 << ": ";
cin >> obj[i].middleName;
cout << "Enter the job title of employee " << i + 1 << ": ";
cin >> obj[i].jobTitle;
cout << "Enter the salary of employee " << i + 1 << ": ";
cin >> obj[i].salary;
cout << "Enter the birth year of employee " << i + 1 << ": ";
cin >> obj[i].birthYear;
cout << endl;
}
}

void Employee::outputYoungest(Employee obj[], int n) {
int youngestIndex = 0;
for(int i = 0; i < n; i++) {
if(obj[i].birthYear > obj[youngestIndex].birthYear) {
youngestIndex = i;
}
}
cout << "The youngest employee is " << obj[youngestIndex].firstName << " " << obj[youngestIndex].lastName << endl;
cout << "Job title: " << obj[youngestIndex].jobTitle << endl;
cout << "Salary: " << obj[youngestIndex].salary << endl;
cout << "Birth year: " << obj[youngestIndex].birthYear << endl;
}

int main() {
Employee employees[100];
int n;
cout << "Enter the number of employees: ";
cin >> n;
cout << endl;
employees[0].input(employees, n);
employees[0].outputYoungest(employees, n);

return 0;
}



3-способ.
#include
#include

using namespace std;

class Employee {
public:
string lastName;
string firstName;
string middleName;
string profession;
int salary;
int birthYear;

void input() {
cout << "Last name: "; cin >> lastName;
cout << "First name: "; cin >> firstName;
cout << "Middle name: "; cin >> middleName;
cout << "Profession: "; cin >> profession;
cout << "Salary: "; cin >> salary;
cout << "Birth year: "; cin >> birthYear;
}

void output() {
cout << "Last name: " << lastName << endl;
cout << "First name: " << firstName << endl;
cout << "Middle name: " << middleName << endl;
cout << "Profession: " << profession << endl;
cout << "Salary: " << salary << endl;
cout << "Birth year: " << birthYear << endl;
}
};

int main() {
int n = 3; // количество сотрудников
Employee employees[n]; // массив объектов класса Employee

// ввод данных о сотрудниках
for (int i = 0; i < n; i++) {
cout << "Employee #" << i + 1 << endl;
employees[i].input();
cout << endl;
}

// поиск самого молодого сотрудника
Employee youngestEmployee = employees[0];
for (int i = 1; i < n; i++) {
if (employees[i].birthYear > youngestEmployee.birthYear) {
youngestEmployee = employees[i];
}
}

// вывод информации о самом молодом сотруднике
cout << "The youngest employee is: " << endl;
youngestEmployee.output();

return 0;
}

Download 1.27 Mb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling