Advertisement
buonaseva_fatelo

INFO_es_28_02

Feb 28th, 2024
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4. const int N = 15;
  5. //es1
  6.  
  7. struct Car {
  8.     int id;
  9.     char model[N];
  10.     float rentalRate;
  11. };
  12.  
  13. int main() {
  14.     Car cars[3];
  15.     int days;
  16.     for(int i=0; i<3; i++) {
  17.         cout << "Enter details for car " << i+1 << ":\n";
  18.         cout << "ID: ";
  19.         cin >> cars[i].id;
  20.         cout << "Model: ";
  21.         cin >> cars[i].model;
  22.         cout << "Rental Rate per day: ";
  23.         cin >> cars[i].rentalRate;
  24.     }
  25.     cout << "Enter number of days for rental: ";
  26.     cin >> days;
  27.     for(int i=0; i<3; i++) {
  28.         cout << "Total rental cost for car " << cars[i].id << " (" << cars[i].model << "): " << cars[i].rentalRate * days << "\n";
  29.     }
  30.     return 0;
  31. }
  32.  
  33.  
  34. //es2
  35.  
  36. struct Employee {
  37.     int id;
  38.     char name[N];
  39.     float salary;
  40. };
  41.  
  42. int main() {
  43.     Employee employees[3], highestSalaryEmployee;
  44.     for(int i=0; i<3; i++) {
  45.         cout << "Enter details for employee " << i+1 << ":\n";
  46.         cout << "ID: ";
  47.         cin >> employees[i].id;
  48.         cout << "Name: ";
  49.         cin >> employees[i].name;
  50.         cout << "Salary: ";
  51.         cin >> employees[i].salary;
  52.         if(i==0 || employees[i].salary > highestSalaryEmployee.salary) {
  53.             highestSalaryEmployee = employees[i];
  54.         }
  55.     }
  56.     cout << "Employee with highest salary is " << highestSalaryEmployee.name << " (ID: " << highestSalaryEmployee.id << ") with a salary of " << highestSalaryEmployee.salary << "\n";
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement