Лаб. 7 ОП (Ваиант 20)
.docx
#include <stdio.h>
#include <clocale>
#include <iostream>
#include <cstring>
#include <iomanip>
#define N 999
#define L 21
#define DAY 9
#define MON 1
#define YEAR 2023
using namespace std;
struct fio{
char* surname;
char* name;
char* patronymic;
};
struct date{
int day;
char* month;
int year;
};
struct datete{
int day;
char* month;
int mon;
int year;
};
struct credit{
int account_number;
struct fio clientt;
struct date open;
double sum;
int percent;
struct datete close;
};
const char* mass_months[12] = {"январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"};
int menu() {
int x;
printf("Выберите команду, введя её номер:\n");
printf("1. Добавить новый счет\n");
printf("2. Информация о счёте\n");
printf("3. Показать все счета и общую сумму кредитов клиента\n");
printf("4. Определить всех клиентов с заданным процентом по кредиту\n");
printf("5. Определить всех клиентов с просроченными платежами\n");
printf("6. Выход из программы\n-> ");
cin >> x;
cout << "\n";
return x;
}
void new_account(struct credit client[], struct fio fioo[], struct date datee[], struct datete dateet[]) {
char buff[L];
int c;
cout << "Введите номер счёта: ";
cin >> c;
if (c < 1 || c > 999) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите номер счёта: ";
cin >> c;
} while (c < 1 || c > 999);
}
client[c].account_number = c;
cout << "Введите фамилию клиента: ";
cin >> buff;
fioo[c].surname = new char[strlen(buff) + 1];
strcpy_s(fioo[c].surname, strlen(buff) + 1, buff);
client[c].clientt.surname = fioo[c].surname;
cout << "Введите имя клиента: ";
cin >> buff;
fioo[c].name = new char[strlen(buff) + 1];
strcpy_s(fioo[c].name, strlen(buff) + 1, buff);
client[c].clientt.name = fioo[c].name;
cout << "Введите отчество клиента: ";
cin >> buff;
fioo[c].patronymic = new char[strlen(buff) + 1];
strcpy_s(fioo[c].patronymic, strlen(buff) + 1, buff);
client[c].clientt.patronymic = fioo[c].patronymic;
int d;
cout << "Введите год взятия кредита (1407-2022): ";
cin >> d;
if (d > 2022 || d < 1407) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите год взятия кредита (1407 - 2022): ";
cin >> d;
} while (d > 2022 || d < 1407);
}
datee[c].year = d;
client[c].open.year = d;
//int k=0;
int f = 5;
//cout << "Введите месяц взятия кредите (строчными буквами): ";
//cin >> buff;
/*for (int i = 0; i < 12; i++) {
k++;
if (strcmp(mass_months[i], buff) != 0) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите месяц взятия кредита (строчными буквами): ";
cin >> buff;
} while (strcmp(mass_months[i], buff) != 0);
}
if (strcmp(mass_months[i], buff) == 0) {
break;
}
}
*/
int k;
do {
k = 0;
cout << "Введите месяц взятия кредита (строчными буквами): ";
cin >> buff;
for (int i = 0; i < 12; i++) {
k++;
if (strcmp(mass_months[i], buff) == 0) {
f = 1;
//cout << "k: " << k << "\n";
break;
}
}
if (f != 1) {
cout << "Недопустимое значение!" << "\n";
}
} while (f != 1);
datee[c].month = new char[strlen(buff) + 1];
strcpy_s(datee[c].month, strlen(buff) + 1, buff);
client[c].open.month = datee[c].month;
int h;
if (k == 2 && d % 4 == 0) {
cout << "Введите число взятия кредита (1-29): ";
cin >> h;
if (h < 1 || h>29) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число взятия кредита (1-29): ";
cin >> h;
} while (h < 1 || h>29);
}
}
if (k == 2 && d % 4 != 0) {
cout << "Введите число взятия кредита (1-28): ";
cin >> h;
if (h < 1 || h>28) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число взятия кредита (1-28): ";
cin >> h;
} while (h < 1 || h>28);
}
}
if (k == 4 || k==6 || k==9 || k==11) {
cout << "Введите число взятия кредита (1-30): ";
cin >> h;
if (h < 1 || h>30) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число взятия кредита (1-30): ";
cin >> h;
} while (h < 1 || h>30);
}
}
if (k == 1 || k == 3 || k == 5 || k == 7 || k==8 || k==10 || k==12) {
cout << "Введите число взятия кредита (1-31): ";
cin >> h;
if (h < 1 || h>31) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число взятия кредита (1-31): ";
cin >> h;
} while (h < 1 || h>31);
}
}
datee[c].day = h;
client[c].open.day = h;
double s;
cout << "Введите сумму кредита: ";
cin >> s;
if (s < 0 || s > 999999999999999999) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите сумму кредита: ";
cin >> s;
} while (s < 0 || s > 999999999999999999);
}
client[c].sum = s;
int p;
cout << "Введите процент по кредиту: ";
cin >> p;
if (p < 0 || p>100) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите процент по кредиту: ";
cin >> p;
} while (p < 0 || p > 100);
}
client[c].percent = p;
int dd;
cout << "Введите год закрытия кредита("<<d<<" - 2062): ";
cin >> dd;
if (dd > 2062 || dd<1407) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите год закрытия кредита(" << d << " - 2062): ";
cin >> dd;
if (dd < d) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите год закрытия кредита(" << d << " - 2062): ";
cin >> dd;
} while (dd < d);
}
} while(dd > 2062 || dd < 1407);
}
if (dd <= 2062 && dd >= 1407) {
if (dd < d) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите год закрытия кредита(1407-2062): ";
cin >> dd;
} while (dd < d);
}
}
dateet[c].year = dd;
client[c].close.year = dd;
//cout << "Введите месяц закрытия кредита (строчными буквами): ";
int ff = 5;
int kk;
/*cin >> buff;
int kk = 0;
for (int i = 0; i < 12; i++) {
kk++;
if (strcmp(mass_months[i], buff) != 0) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите месяц закрытия кредита (строчными буквами): ";
cin >> buff;
} while (strcmp(mass_months[i], buff) != 0);
}
if (strcmp(mass_months[i], buff) == 0) {
if (dd == d && kk < k) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите месяц закрытия кредита (строчными буквами): ";
cin >> buff;
} while (dd == d && kk < k);
}
if ((dd == d || dd > d) && (kk == k || kk > k)) {
break;
}
}
}
*/
do {
kk = 0;
cout << "Введите месяц закрытия кредита (строчными буквами): ";
cin >> buff;
for (int i = 0; i < 12; i++) {
kk++;
if (strcmp(mass_months[i], buff) == 0) {
if (dd > d) {
ff = 1;
//cout << "kk: " << kk << "\n";
break;
}
if (dd = d && kk >= k) {
ff = 1;
//cout << "kk: " << kk << "\n";
break;
}
}
}
if (ff != 1) {
cout << "Недопустимое значение!" << "\n";
}
} while (ff != 1);
dateet[c].month = new char[strlen(buff) + 1];
strcpy_s(dateet[c].month, strlen(buff) + 1, buff);
client[c].close.month = dateet[c].month;
client[c].close.mon = kk;
int hh;
if (kk == 2 && dd % 4 == 0) {
cout << "Введите число закрытия кредита (1-29): ";
cin >> hh;
if (hh < 1 || hh>29) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-29): ";
cin >> hh;
if (kk == k && dd== d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-29): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
} while (hh < 1 || hh>29);
}
if (hh >= 1 || hh<=29) {
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-29): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
}
}
if (kk == 2 && dd % 4 != 0) {
cout << "Введите число взятия кредита (1-28): ";
cin >> hh;
if (hh < 1 || hh>28) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число взятия кредита (1-28): ";
cin >> hh;
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-28): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
} while (hh < 1 || hh>28);
}
if (hh >= 1 || hh<=28) {
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-28): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
}
}
if (kk == 4 || kk == 6 || kk == 9 || kk == 11) {
cout << "Введите число взятия кредита (1-30): ";
cin >> hh;
if (hh < 1 || hh>30) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-30): ";
cin >> hh;
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-30): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
} while (hh < 1 || hh>30);
}
if (hh >= 1 || hh<=30) {
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-30): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
}
}
if (kk == 1 || kk == 3 || kk == 5 || kk == 7 || kk == 8 || kk == 10 || kk == 12) {
cout << "Введите число взятия кредита (1-31): ";
cin >> hh;
if (hh < 1 || hh>31) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-31): ";
cin >> hh;
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-31): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
} while (hh < 1 || hh>31);
}
if (hh >= 1 || hh<=31) {
if (kk == k && dd == d && hh < h) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите число закрытия кредита (1-31): ";
cin >> hh;
} while (kk == k && dd == d && hh < h);
}
}
}
dateet[c].day = hh;
client[c].close.day = hh;
cout << "\n";
}
void two(struct credit client[], struct fio fioo[], struct date datee[], struct datete dateet[]) {
int c;
cout << "Введите номер счёта, о котором хотите узнать информацию: ";
cin >> c;
if (c < 1 || c > 999) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите номер счёта, о котором хотите узнать информацию: ";
cin >> c;
} while (c < 1 || c > 999);
}
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
if (c > 0 && c < 10) {
printf(" Номер счёта: %d |\n", c);
}
if (c > 9 && c < 100) {
printf(" Номер счёта: %d |\n", c);
}
if (c > 99 && c < 1000) {
printf(" Номер счёта: %d |\n", c);
}
if (c > 999 && c < 10000) {
printf(" Номер счёта: %d |\n", c);
}
if (c > 9999 && c < 100000) {
printf(" Номер счёта: %d |\n", c);
}
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Фамилия клиента |");
cout << setw(L) << client[c].clientt.surname << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Имя клиента |");
cout << setw(L) << client[c].clientt.name << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Отчество клиента |");
cout << setw(L) << client[c].clientt.patronymic << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("День открытия счёта|");
cout << setw(L) << client[c].open.day << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Месяц откртия счёта|");
cout << setw(L) << client[c].open.month << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Год открытия счёта |");
cout << setw(L) << client[c].open.year << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Сумма кредита |");
cout << setw(L) << client[c].sum << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Процент по кредиту |");
cout << setw(L) << client[c].percent << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("День закрытия счёта|");
cout << setw(L) << client[c].close.day << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Месяц закртия счёта|");
cout << setw(L) << client[c].close.month << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
printf("Год закрытия счёта |");
cout << setw(L) << client[c].close.year << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
cout << "\n";
}
void three(struct credit client[], struct fio fioo[], struct date datee[], struct datete dateet[]) {
char buff[L];
char* ssurname;
char* nname;
char* pp;
cout << "Введите фамилию клиента: ";
//fgets(buff, L, stdin);
cin >> buff;
ssurname = new char[strlen(buff) + 1];
strcpy_s(ssurname, strlen(buff) + 1, buff);
cout << "Введите имя клиента: ";
//fgets(buff, L, stdin);
cin >> buff;
nname = new char[strlen(buff) + 1];
strcpy_s(nname, strlen(buff) + 1, buff);
cout << "Введите отчество клиента: ";
//fgets(buff, L, stdin);
cin >> buff;
pp = new char[strlen(buff) + 1];
strcpy_s(pp, strlen(buff) + 1, buff);
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
//printf(" %s |\n", *ssurname);
//printf(" %s |\n", *nname);
//for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
double ssum = 0;
for (int i = 0; i < N; i++) {
if (client[i].account_number == i && (strcmp(client[i].clientt.surname, ssurname) == 0) && (strcmp(client[i].clientt.name, nname) == 0) && (strcmp(client[i].clientt.patronymic, pp) == 0)) {
printf("Номер счёта |");
cout << setw(L) << client[i].account_number << "|" << "\n";
for (int i = 0; i < L; i++) printf("_ "); printf("\n");
printf("Cумма кредита |");
cout << setw(L) << client[i].sum << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
ssum += client[i].sum;
}
}
printf("Общая сумма |");
cout << setw(L) << ssum << "|" << "\n";
for (int i = 0; i < L * 2; i++) printf("_"); printf("\n");
cout << "\n";
delete ssurname;
delete nname;
}
void four(struct credit client[], struct fio fioo[], struct date datee[], struct datete dateet[]) {
int perc;
cout << "Введите процент по кредиту: ";
cin >> perc;
if (perc < 0 || perc>100) {
do {
cout << "Недопустимое значение!" << "\n";
cout << "Введите процент по кредиту: ";
cin >> perc;
} while (perc < 0 || perc >100);
}
for (int i = 0; i < L * 3+5; i++) printf("_"); printf("\n");
if (perc > 0 && perc < 10) {
printf(" Процент по кредиту: %d |\n", perc);
}
if (perc > 9 && perc < 100) {
printf(" Процент по кредиту: %d |\n", perc);
}
for (int i = 0; i < L * 3 + 5; i++) printf("_"); printf("\n");
for (int i = 1; i < N; i++) {
if (i == client[i].account_number && perc == client[i].percent) {
cout << setw(3) << client[i].account_number << "|";
cout << setw(L) << client[i].clientt.surname;
cout << setw(L) << client[i].clientt.name;
cout << setw(L) << client[i].clientt.patronymic << "|" << "\n";
for (int i = 0; i < L * 3 + 4; i++) printf("_"); printf("\n");
}
}
cout << "\n";
}
void five(struct credit client[], struct fio fioo[], struct date datee[], struct datete dateet[]) {
for (int i = 0; i < L * 3+4; i++) printf("_"); printf("\n");
for (int i = 1; i < N + 1; i++) {
if (i== client[i].account_number && client[i].close.year < YEAR) {
cout << setw(4) << client[i].account_number << "|";
cout << setw(L) << client[i].clientt.surname;
cout << setw(L) << client[i].clientt.name;
cout << setw(L) << client[i].clientt.patronymic << "|" << "\n";
for (int i = 0; i < L * 3+4; i++) printf("_"); printf("\n");
}
if (i == client[i].account_number && client[i].close.year == YEAR && client[i].close.mon < MON) {
cout << setw(4) << client[i].account_number << "|";
cout << setw(L) << client[i].clientt.surname;
cout << setw(L) << client[i].clientt.name;
cout << setw(L) << client[i].clientt.patronymic << "|" << "\n";
for (int i = 0; i < L * 3+4; i++) printf("_"); printf("\n");
}
if (i == client[i].account_number && client[i].close.year == YEAR && client[i].close.mon == MON && client[i].close.day<DAY) {
cout << setw(4) << client[i].account_number << "|";
cout << setw(L) << client[i].clientt.surname;
cout << setw(L) << client[i].clientt.name;
cout << setw(L) << client[i].clientt.patronymic << "|" << "\n";
for (int i = 0; i < L * 3+4; i++) printf("_"); printf("\n");
}
//if(i == client[i].account_number && client[i].close.year > YEAR) {
// cout << setw(L*3) << "Таковые клиенты отсутствуют" << "|" << "\n";
// for (int i = 0; i < L * 3; i++) printf("_"); printf("\n");
//}
}
cout << "\n";
}
/*
void save_work(struct credit* client[]){
credit* tw;
FILE* pf;
if ((pf = fopen("data.txt", "w")) == NULL) {
perror("Ошибка открытия файла");
}
for (tw = client[N]; tw < client[N]; tw++) {
fprintf(pf, "%s\n", tw->clientt.surname);
fprintf(pf, "%s\n", tw->clientt.name);
fprintf(pf, "%s\n", tw->clientt.patronymic);
}
fclose(pf);
}
*/
void main() {
setlocale(LC_ALL, "Russian");
system("chcp 1251");
//struct credit ma[N];
//struct fio ffiioo[N];
//struct date ddaattee[N];
//struct datete datetete[N];
credit* mass = (credit*)malloc(N * sizeof(credit));
fio* mfio = (fio*)malloc(N * sizeof(fio));
date* mdate = (date*)malloc(N * sizeof(date));
datete* mdatete = (datete*)malloc(N * sizeof(datete));
int C = 0;
do {
int x = menu();
switch (x) {
case 1:
new_account(mass, mfio, mdate, mdatete);
break;
case 2:
two(mass, mfio, mdate, mdatete);
break;
case 3:
three(mass, mfio, mdate, mdatete);
break;
case 4:
four(mass, mfio, mdate, mdatete);
break;
case 5:
five(mass, mfio, mdate, mdatete);
break;
case 6:
exit(0);
default:
printf("Команды под данным номером не существует\n");
break;
}
} while (C != 1);
free(mass);
free(mfio);
free(mdate);
free(mdatete);
}