#include
#include
#include
struct Employers
{
int id;
std::string name;
std::string position;
int hours_worked;
double hourly_wage;
double salary;
};
Employers* InputNewEmployee(Employers* ptr_str, int& SIZE);
int main()
{
int SIZE = 0;
Employers* ptr_str = nullptr;
int n = -1;
while (n != 0)
{
std::cout << "1) New worker. " << std::endl
<< "2) Edit worker. " << std::endl
<< "3) Display one employee. " << std::endl
<< "4) Display all employees. " << std::endl
<< "5) Save all employees to a file. " << std::endl
<< "6) Delete all employees from the file. " << std::endl
<< "7) Sort all employees by salary. " << std::endl
<< "Enter an action - ";
std::cin >> n;
switch (n)
{
case 1: ptr_str = InputNewEmployee(ptr_str, SIZE); break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
default: break;
}
}
delete[] ptr_str; // Освобождение памяти при завершении программы
return 0;
}
Employers* InputNewEmployee(Employers* ptr_str, int& SIZE)
{
Employers* new_point = new Employers[SIZE + 1];
for (int i = 0; i < SIZE; ++i) {
new_point[i] = ptr_str[i];
}
new_point[SIZE].id = SIZE + 1;
std::cin.get(); // этот getline нужен для очищения буфера
std::cout << "Enter the employee's name - ";
std::getline(std::cin, new_point[SIZE].name);
std::cout << "Enter the employee's position - ";
std::getline(std::cin, new_point[SIZE].position);
std::cout << "Enter the number of hours worked by the employee - ";
std::cin >> new_point[SIZE].hours_worked;
std::cout << "Enter the employee's hourly rate of pay - ";
std::cin >> new_point[SIZE].hourly_wage;
new_point[SIZE].salary = new_point[SIZE].hours_worked * new_point[SIZE].hourly_wage;
if (ptr_str != nullptr) {
delete[] ptr_str;
}
++SIZE;
return new_point;
}
#include <iostream>
#include <string>
#include <fstream>
struct Employers
{
int id;
std::string name;
std::string position;
int hours_worked;
double hourly_wage;
double salary;
};
Employers* InputNewEmployee(Employers* ptr_str, int SIZE);
int main()
{
int SIZE = 0;
Employers* ptr_str = new Employers[SIZE + 1];
int n = -1;
while (n != 0)
{
std::cout << "1) New worker. " << std::endl
<< "2) Edit worker. " << std::endl
<< "3) Display one employee. " << std::endl
<< "4) Dislay all empoyer's. " << std::endl
<< "5) Save all employees to a file. " << std::endl
<< "6) Delete all employees from the file. " << std::endl
<< "7) Sort all employees by salary. " << std::endl
<< "Enter an action - ";
std::cin >> n;
switch (n)
{
case 1: ptr_str = InputNewEmployee(ptr_str, SIZE); break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
default: break;
}
}
return 0;
}
Employers* InputNewEmployee(Employers* ptr_str, int SIZE)
{
Employers* new_point = new Employers[SIZE + 1];
for (int i = 0; i < SIZE; ++i) {
new_point[i] = ptr_str[i];
}
new_point[SIZE].id = SIZE + 1;
std::cin.get();
std::cout << "Enter the employee's name - ";
getline(std::cin, new_point[SIZE].name);
std::cout << "Enter the employee's position - ";
getline(std::cin, new_point[SIZE].position);
std::cout << "Enter the number of hours worked by the employee - ";
std::cin >> new_point[SIZE].hours_worked;
std::cout << "Enter the employee's hourly rate of pay - ";
std::cin >> new_point[SIZE].hourly_wage;
new_point[SIZE].salary = new_point[SIZE].hours_worked * new_point[SIZE].hourly_wage;
if (ptr_str != nullptr) {
delete[] ptr_str;
}
ptr_str = new_point;
delete[] new_point;
++SIZE;
return ptr_str;
}