Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <cstring>
- using namespace std;
- const int kolichestvo = 2;
- const int D = 3;
- const int n = 2;
- struct ZNAK {
- char name[20];
- char surname[30];
- string znak;
- int date[D];
- };
- void meny(int &n);
- void fank2(int *A);
- void search(ZNAK *m, char file_name[],const int kolichestvo);
- void output( ZNAK *m, char file_name[], const int kolichestvo, const int n);
- void fillstruct(ZNAK *m,char file_name[], const int kolichestvo, const int D);
- void showstruct(ZNAK *m,char file_name[], const int kolichestvo, const int D);
- int main(){
- setlocale(LC_ALL, "rus");
- cout<<"Enter file name:"<<endl;
- char file_name[50];
- cin.getline(file_name, 20);
- int choice = 0;
- ZNAK m[kolichestvo];
- while (choice != 4) {
- meny(choice);
- if (choice == 1) {
- fillstruct(m, file_name, kolichestvo, D);
- }
- if (choice == 3) {
- output(m, file_name, kolichestvo, n);
- }
- if (choice == 2) {
- search(m, file_name, kolichestvo);
- system ("pause");
- }
- if (choice == 4) break;
- }
- cout << "Завершение программы...";
- }
- void meny(int &n) {
- system("cls");
- cout << setw(15) << "****Меню****"<<endl<<endl;
- cout << setw(3) << "1) Ввести данные" << endl;
- cout << setw(3) << "2) найти человека " << endl;
- cout << setw(3) << "3) Вывести данные" << endl;
- cout << setw(3) << "4) Выход" << endl;
- cin >> n;
- }
- void fillstruct(ZNAK *m, char file_name[],const int kolichestvo, const int D){
- ofstream file(file_name, ios::binary | ios::out);
- for (int i = 0; i < kolichestvo; i++){
- cout << "input name and surname: ";
- cin >> m[i].name;
- cin >> m[i].surname;
- cout << "input Zodiac sign: ";
- cin >> m[i].znak;
- cout << "input date: ";
- fank2(m[i].date);
- file.write(reinterpret_cast<char*> (&m), sizeof(ZNAK));
- }
- cout<<"File is made"<<endl;
- file.close();
- }
- void fank2(int *A) {
- for (int i=0; i < 3; i++) {
- cin >> A[i];
- }
- }
- void search(ZNAK *m, char file_name[],const int kolichestvo){
- char surname1[20];
- ifstream file(file_name, ios::binary | ios::in);
- for ( int l = 0; l < 20; l++ )
- surname1[l]=NULL;
- cout<<"Enter needed surname: ";
- cin >> surname1;
- bool r = false;
- for ( int k = 0; k < kolichestvo; k++ )
- {
- file.read(reinterpret_cast<char*> (&m), sizeof(ZNAK));
- bool b = true;
- int l = 0;
- while ( surname1[l] != NULL)
- { if (surname1[l] != m[k].surname[l]) b = false; l++;
- }
- if (surname1[l] != m[k].surname[l]) b = false;
- if ( b == true )
- {
- cout << m[k].name << " " << m[k].surname << endl << m[k].znak << endl;
- for (int j = 0; j < 3; j++){
- cout << m[k].date[j] << " ";
- }
- cout << endl;
- cout<<"--------------------------------------------------"<<endl;
- r = true;
- }
- file.close();
- }
- if ( r == false ) cout<<"No match person"<<endl;
- file.close();
- system("pause");
- }
- void output( ZNAK *m, char file_name[], const int kolichestvo, const int n){
- ifstream file(file_name, ios::binary | ios::in);
- file.read(reinterpret_cast<char*> (&m), sizeof(ZNAK));
- for (int i = 0; i < n; i++) {
- cout << m[i].name << " ";
- cout << m[i].surname << " "<<endl;
- cout << m[i].znak << endl;
- for (int j = 0; j < 3; j++) {
- cout << m[i].date[j] << " ";
- }
- cout << endl;
- }
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement