Good day! Help write a function. The question of life and death. There is a database in which to add a function. The function should determine the firm that has acted as the plaintiff the greatest number of times. I think that you first need to sort out the companies that acted as the plaintiff, and then among them find a company that has acted as the plaintiff the largest number of times, that is, the maximum element. I don’t know how to write all this into the code.

Here is the database structure:

enter image description here

Code:

#include <iostream> #include <stdlib.h> #include <fstream> #include <cstdio> #include <string.h> #include <stdio.h> #include <cstdlib> #include <cstring> using namespace std; struct DATA{ int day; int month; int year; }; struct vidp { int telefon; char nazvFirm[15]; }; struct sprava{ DATA data; char predmet[20]; vidp v; vidp obv; }; sprava* array_of_sprava=new sprava[50]; FILE* Fs; int nzap=0; int i=0,h=0,g=0; int reading()//чтение; { if ((Fs=fopen("my.dat","rb"))==NULL) { cout<<("Не можу відкрити файл\n"); return 0; } do { fread(&array_of_sprava[nzap],sizeof(sprava),1,Fs); nzap++; if (feof(Fs)) break; } while(1); nzap--; cout<<"Зчитування закінчено\n"; fclose(Fs); // Закрываем файл system("pause"); return 0; } int outp_to_file(){ // Вывод в файл FILE* Fs; if ((Fs=fopen("my.dat","wb"))==NULL) { cout<<("Файл не створений!\n"); return 0; } for (int i=0;i<nzap;i++) fwrite(&array_of_sprava[i],sizeof(sprava),1,Fs); cout<<("Файл створений!"); fclose(Fs); system("pause"); } int input_in_array(){//ввод в масив; int q=1; while (q!=0) { cout<<"\nВведіть день справи: "; cin>>array_of_sprava[nzap].data.day; cout<<"\nВведіть місяц справи: "; cin>>array_of_sprava[nzap].data.month; cout<<"\nВведіть рік справи: "; cin>>array_of_sprava[nzap].data.year; cout<<"\nВведіть придмет справи: "; cin>>array_of_sprava[nzap].predmet; cout<<"\nВведіть телефон позивача: "; cin>>array_of_sprava[nzap].v.telefon; cout<<"\nВведіть фірму позивача: "; cin>>array_of_sprava[nzap].v.nazvFirm; cout<<"\nВведіть телефон обвинувачуваного: "; cin>>array_of_sprava[nzap].obv.telefon; cout<<"\nВведіть фірму обвинувачуваного: "; cin>>array_of_sprava[nzap].obv.nazvFirm; nzap++; cout<<"\nВведіть 0 для закінчення запису або будь-яке число для продовження: "; cin>>q; cout<<"\n"; } } int VivEkran()// Вывод на экран {system("cls"); for(int i=0;i<nzap;i++) { cout<<"Запис №"<<i+1<<"\n"; cout<<"\ День справи: "<<array_of_sprava[i].data.day<<"\n"; cout<<"\ Місяць справи: "<<array_of_sprava[i].data.month<<"\n"; cout<<"\ Рік справи: "<<array_of_sprava[i].data.year<<"\n"; cout<<"\ Предмет справи: "<<array_of_sprava[i].predmet<<"\n"; cout<<"\ Телевон позивача: "<<array_of_sprava[i].v.telefon<<"\n"; cout<<"\ Фірма позивача: "<<array_of_sprava[i].v.nazvFirm<<"\n"; cout<<"\ Телефон обвинувачуваного: " <<array_of_sprava[i].obv.telefon<<"\n"; cout<<"\ Фірма обвинувачуваного: "<<array_of_sprava[i].obv.nazvFirm<<"\n"; } system("pause"); return 0; } int newbase()// создать новую базу данных { system("cls"); cout<<"База даних\n"; string v; cout<<"Введіть назву нової бази даних\n"; cin>>v; FILE* Fs; if ((Fs=fopen(v.c_str(),"wb"))==NULL) { cout<<("Файл не створений\n"); system("pause");return 0; } for (int i=0;i<nzap;i++) fwrite(&array_of_sprava[nzap],sizeof(sprava),1,Fs); cout<<("Файл створений\n"); system("pause"); fclose(Fs); return 0; } void poisk(){ // поиск cout<<"Введіть рік справи: "; int y; cin >> y; bool not_found = true; for (int i=0;i<nzap;i++) { if (array_of_sprava[i].data.year==y) { cout<<"Запис №"<<i+1<<"\n"; cout<<"\ День справи: "<<array_of_sprava[i].data.day<<"\n"; cout<<"\ Місяць справи: "<<array_of_sprava[i].data.month<<"\n"; cout<<"\ Рік справи: "<<array_of_sprava[i].data.year<<"\n"; cout<<"\ Предмет справи: "<<array_of_sprava[i].predmet<<"\n"; cout<<"\ Телевон позивача: "<<array_of_sprava[i].v.telefon<<"\n"; cout<<"\ Фірма позивача: "<<array_of_sprava[i].v.nazvFirm<<"\n"; cout<<"\ Телефон обвинувачуваного: "<<array_of_sprava[i].obv.telefon<<"\n"; cout<<"\ Фірма обвинувачуваного: " <<array_of_sprava[i].obv.nazvFirm<<"\n"; system("pause"); not_found = false; } } if (not_found) { cout<<"Дані за цей рік не знайдені\n"; system("pause"); } } int main()// меню {setlocale(LC_CTYPE, "Ukr"); system("chcp 1251"); int rez=1; while(rez!=0) { system("cls"); cout<<"База даних\n"; cout<<"Меню\n"; cout<<"1 - Додати дані ;\n"; cout<<"2 - Введення даних в файл;\n"; cout<<"3 - Зчитати дані з файлу;\n"; cout<<"4 - Вивести всі дані на екран;\n"; cout<<"5 - Пошук по року;\n"; cout<<"6 - Фірма яка найчастіше була позивачем;\n"; cout<<"7 - Створеня нової бази даних;\n"; cout<<"0 - Вихід;\n"; cout<<nzap<<":"; cin>>rez; switch(rez) { case 1:input_in_array();break; case 2:outp_to_file();break; case 3:reading();break; case 4:VivEkran();break; case 5:poisk();break; // case 6:фирма которая чаще была истцом();break; case 7:newbase();break; case 0: outp_to_file();exit(0);break; default :break; }} } 
  • If the database - use SQL. - Vladimir Martyanov
  • I don't know what SQL is. - Artyr Gaidyk
  • I have to add a function to c ++, but I don’t have a clue how to write it. - Artyr Gaidyk
  • Thank you for your help! I wrote everything myself! - Artyr Gaidyk

0