Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <locale.h>
- #define SIZE 3
- enum MSG {
- SHEET_ERROR,
- SHEET_NUMBER,
- SHEET_SURNAME,
- SHEET_TIME,
- SHEET_PAYMENT
- };
- typedef struct {
- char number[17], surname[25], time[6], payment[6];
- } SHEET;
- typedef SHEET* PSHEET;
- void msg(enum MSG command) {
- switch (command) {
- case SHEET_ERROR:
- while (getchar() != '\n');
- printf("Ошибка!\n");
- break;
- case SHEET_NUMBER: printf("Номер страховки: "); break;
- case SHEET_SURNAME: printf("Фамилия: "); break;
- case SHEET_TIME: printf("Количество отработанных часов: "); break;
- case SHEET_PAYMENT: printf("Почасовая оплата: "); break;
- default: printf("Входная команда функции msg(enum MSG command) не реализована!\n");
- }
- }
- void input(PSHEET psheet, int size) {
- for (int i = 0; i != size; ++i) {
- printf("\n\t Введите данные о %d-ой графе\n", i + 1);
- msg(SHEET_NUMBER);
- while (!scanf_s("%s", psheet[i].number, _countof(psheet[i].number))) {
- msg(SHEET_ERROR);
- msg(SHEET_NUMBER);
- }
- msg(SHEET_SURNAME);
- while (!scanf_s("%s", psheet[i].surname, _countof(psheet[i].surname))) {
- msg(SHEET_ERROR);
- msg(SHEET_SURNAME);
- }
- msg(SHEET_TIME);
- while (!scanf_s("%s", psheet[i].time, _countof(psheet[i].time))) {
- msg(SHEET_ERROR);
- msg(SHEET_TIME);
- }
- msg(SHEET_PAYMENT);
- while (!scanf_s("%s", psheet[i].payment, _countof(psheet[i].payment))) {
- msg(SHEET_ERROR);
- msg(SHEET_PAYMENT);
- }
- }
- }
- void swap(PSHEET a, PSHEET b) {
- SHEET tmp;
- strcpy_s(tmp.number, _countof(tmp.number), a->number);
- strcpy_s(tmp.surname, _countof(tmp.surname), a->surname);
- strcpy_s(tmp.time, _countof(tmp.time), a->time);
- strcpy_s(tmp.payment, _countof(tmp.payment), a->payment);
- strcpy_s(a->number, _countof(a->number), b->number);
- strcpy_s(a->surname, _countof(a->surname), b->surname);
- strcpy_s(a->time, _countof(a->time), b->time);
- strcpy_s(a->payment, _countof(a->payment), b->payment);
- strcpy_s(b->number, _countof(b->number), tmp.number);
- strcpy_s(b->surname, _countof(b->surname), tmp.surname);
- strcpy_s(b->time, _countof(b->time), tmp.time);
- strcpy_s(b->payment, _countof(b->payment), tmp.payment);
- }
- void bubble(PSHEET psheet, int size) {
- for (int i = size - 1; i >= 0; --i) {
- for (int j = 0; j < i; ++j) {
- int cmp = strcmp(psheet[j].number, psheet[j + 1].number);
- if (cmp > 0) swap(&psheet[j], &psheet[j + 1]);
- }
- }
- }
- void output(PSHEET psheet, int size) {
- const char* line = "---------------------------------------------------------------------------------\n";
- const char* format = "|%-17s|%-25s|%-19s|%-15s|\n";
- printf(line);
- printf("|%44s%37s", "Ведомость", "|\n");
- printf(line);
- printf("| Номер страховки | Фамилия работника | Отработанные часы | Оплата |\n");
- //printf("| Номер страховки | Фамилия | Количество отработанных часов | Почасовая оплата |\n");
- printf(line);
- for (int i = 0; i < size; i++) {
- printf(format, psheet[i].number, psheet[i].surname, psheet[i].time, psheet[i].payment);
- printf(line);
- }
- }
- int main(void) {
- PSHEET psheet = (PSHEET)malloc(SIZE * sizeof(SHEET));
- system("chcp 1251");
- system("cls");
- setlocale(LC_ALL, "Russian");
- if (psheet != NULL) {
- input(psheet, SIZE);
- bubble(psheet, SIZE);
- output(psheet, SIZE);
- free(psheet);
- } else {
- puts("Недостаточно памяти!");
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement