Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- #include <string.h>
- #include <iomanip>
- using namespace std;
- struct employee
- {
- char name[100];
- float salary;
- int stage;
- };
- int i = 0, n, kol;
- char filename[50]; char surname[30];
- void inputfile(employee x[])
- {
- ifstream fin;
- fin.open(filename, ios_base::in);
- if (fin.fail()) { cout << "Error! The file is not found"; _getch(); exit(0); }
- else {
- cout << "The file has been successfully opened!" << endl;
- while (!fin.eof())
- {
- fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
- strcat_s(x[i].name, " ");
- strcat_s(x[i].name, surname);
- i++;
- }
- }
- fin.close();
- n = i;
- }
- void output(employee x[])
- {
- kol = 0;
- cout << "\nThe list of employees:\n" << endl;
- for (i = 0; i < n; i++) {
- kol++;
- cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
- }
- }
- void add(employee x[]) {
- int k = 0;
- cout << "\nHow many people are going to be added? "; cin >> k;
- if (k == 0) cout << "No new employees are going to be added to the list.";
- else {
- ofstream fout;
- fout.open(filename, ios_base::app);
- if (!fout.is_open()) { cout << "\tFile Error!"; }
- else {
- for (i = n; i < n + k; i++) {
- cout << "\nEnter the name:";
- cin >> x[i].name;
- cout << " and surname:"; cin >> surname;
- strcat_s(x[i].name, " ");
- strcat_s(x[i].name, surname);
- cout << "\nSalary:";
- cin >> x[i].salary;
- cout << "\nWork experience:";
- cin >> x[i].stage;
- fout << "\n" << x[i].name << " " << x[i].salary << " " << x[i].stage;
- }
- }
- fout.close();
- ifstream fin;
- fin.open(filename, ios_base::in);
- while (!fin.eof())
- {
- fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
- strcat_s(x[i].name, " ");
- strcat_s(x[i].name, surname);
- i++;
- }
- fin.close();
- kol = 0; n += k;
- cout << "\nThe new list of employees:\n" << endl;
- for (i = 0; i < n; i++) {
- kol++;
- cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
- }
- }
- }
- void poisk(employee x[])
- {
- cout << "\nEmployees, whose stage > 10 and salary > 15 000:" << endl;
- char fl = 'L';
- kol = 0;
- for (i = 0; i < n; i++) {
- if ((x[i].stage > 10) && (x[i].salary>150000)) {
- kol++;
- cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
- }
- }
- }
- void sort(employee x[])
- {
- cout << "\nThe sorted list of employees, based on their salary:\n" << endl;
- employee temp;
- for (int m = 0; m < i - 1; m++) {
- for (int j = 0; j < i - m - 1; j++) {
- if (x[j].salary > x[j + 1].salary) {
- temp = x[j];
- x[j] = x[j + 1];
- x[j + 1] = temp;
- }
- }
- }
- kol = 0;
- for (i = 0; i < n; i++) {
- kol++;
- cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
- }
- }
- void del(employee x[]) {
- int s; i = 0; kol = 0;
- cout << "\nWhich string should be deleted? #";
- cin >> s;
- if (s == 0) cout << "None.";
- else {
- s--;
- n--;
- for (int c = s; c < n; c++)
- {
- x[c].salary = x[c + 1].salary;
- x[c].stage = x[c + 1].stage;
- for (int p = 0; p<100; p++)x[c].name[p] = x[c + 1].name[p];
- }
- i--;
- ofstream fout;
- fout.open(filename, ios_base::out | ios_base::trunc);
- for (i = 0; i < n; i++) {
- fout << x[i].name << " " << x[i].salary << " " << x[i].stage << endl;;
- }
- fout.close();
- ifstream fin;
- fin.open(filename, ios_base::in);
- while (!fin.eof())
- {
- fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
- strcat_s(x[i].name, " ");
- strcat_s(x[i].name, surname);
- i++;
- }
- fin.close();
- cout << "\nThe new list without the deleted string:" << endl;
- for (i = 0; i < n; i++) {
- kol++;
- cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
- }
- }
- }
- int _tmain(int argc, _TCHAR argv[])
- {
- employee a[20];
- cout << "File's address: ";
- cin >> filename;
- inputfile(a);
- output(a); cout << endl;
- add(a); cout << endl;
- poisk(a); cout << endl;
- sort(a); cout << endl;
- del(a); cout << endl;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement