Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Dynamic.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <clocale>
- #include <conio.h>
- using namespace std;
- typedef struct Passport {
- char * Surname;
- char * Name;
- char * Address;
- };
- bool CharCompare( char * A, char * B );
- Passport StructInit( Passport p );
- char * StructOut( Passport p );
- void CheckNames( Passport * p, int n );
- int main( )
- {
- setlocale( LC_ALL, "Russian" );
- int n, MenuChoice;
- char * C = new char[16];
- cout << "Введите количество паспортов: ";
- cin >> n;
- Passport *p = new Passport[n];
- char * Choice = new char[2];
- strcpy_s( Choice, strlen( Choice ), "Y" );
- while ( Choice[0] == 'Y' )
- {
- cout << endl << "1. Ввести паспорта. " << endl;
- cout << "2. Вывести паспорта на экран. " << endl;
- cout << "3. Проверить, есть ли паспорта с одинаковыми именами. " << endl;
- cout << "4. Очистить экран. " << endl;
- cout << "5. Выход. " << endl;
- cout << endl << "Ваш выбор: ";
- for ( ;;)
- {
- cin >> MenuChoice;
- if ( MenuChoice >= 1 && MenuChoice <= 5 ) { break; }
- else { cout << endl << "Повторите ввод: "; continue; }
- }
- switch ( MenuChoice )
- {
- case 1:
- for ( int i = 0; i < n; i++ )
- {
- getchar( );
- p[i] = StructInit( p[i] );
- }
- break;
- case 2:
- for ( int i = 0; i < n; i++ )
- {
- cout << StructOut( p[i] ) << endl;
- }
- break;
- case 3:
- CheckNames( p, n );
- break;
- case 4:
- system( "CLS" );
- break;
- case 5:
- system( "EXIT" );
- return 0;
- break;
- }
- }
- _getch( );
- return 0;
- }
- bool CharCompare( char * A, char * B )
- {
- if ( strlen( A ) == strlen( B ) )
- {
- for ( int i = 0; i < strlen( A ); i++ )
- {
- if ( A[i] == B[i] ) { continue; }
- else { return false; }
- }
- }
- else
- {
- return false;
- }
- return true;
- }
- Passport StructInit( Passport p )
- {
- char * buff = new char[128];
- cout << "Введите фамилию: ";
- gets_s( buff, 127 );
- p.Surname = new char[strlen( buff ) + 1];
- strcpy_s( p.Surname, strlen( p.Surname ), buff );
- delete [] buff;
- buff = new char[128];
- cout << "Введите имя: ";
- gets_s( buff, 127 );
- p.Name = new char[strlen( buff ) + 1];
- strcpy_s( p.Name, strlen( p.Name ), buff );
- delete [] buff;
- buff = new char[128];
- cout << "Введите адрес: ";
- gets_s( buff, 127 );
- p.Address = new char[strlen( buff ) + 1];
- strcpy_s( p.Address, strlen( p.Address ), buff );
- delete [] buff;
- return p;
- }
- char * StructOut( Passport p )
- {
- char * Result = new char[512];
- strcpy_s( Result, 511, "" );
- strcat_s( Result, 511, "Фамилия: " );
- strcat_s( Result, 511, p.Surname );
- strcat_s( Result, 511, "; Имя: " );
- strcat_s( Result, 51, p.Name );
- strcat_s( Result, 511, "; Адрес: " );
- strcat_s( Result, 511, p.Address );
- return Result;
- }
- void CheckNames( Passport * p, int n )
- {
- for ( int i = 0; i < n; i++ )
- {
- for ( int j = 0; j < n; j++ )
- {
- if ( i == j ) { continue; }
- if ( CharCompare( p[i].Name, p[j].Name ) )
- {
- cout << StructOut( p[i] ) << endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement