
Опытный
 
Профиль
Группа: Участник
Сообщений: 794
Регистрация: 12.7.2006
Репутация: 10 Всего: 23
|
Код | //#include "stdafx.h" #include "iomanip.h" #include "iostream.h" #include "conio.h" #include "stdio.h" #include "string.h" #include "dos.h" #include "stdlib.h" #include "fstream.h"
int sz=0;
int sort_function( const void *a, const void *b ) { return( strcmp((char *)a, (char *)b) ); }
struct PERSONAL { char FIO[20]; int date[3]; char doljnosti[20]; double sr_zarabotok; } spisok[8];
void menu(); void writee(); void readd(); void delet(); void alfavit(); void vivod();
void staj();
int recsize = 20+4+4+4+20+8;
fstream potok;
int main() { int i; char filename[81];
//cout<<"\t\tVvedite imya faila: >>> "; cin.getline(filename,80); potok.open( ".\\a.dat", ios::binary | ios::in | ios::out ); if(!potok) { cout << "\aFail " << filename << " ne bil uspershno otkrit"; return -1; } menu(); potok.close(); return 0; }
void menu() { int choice; system ("cls"); cout << "\n\n\t\t|Zapic ------ 1|"; cout << "\n\n\t\t|Chtenie ------ 2|"; cout << "\n\n\t\t|Udalenie ------ 3|"; cout << "\n\n\t\t|Korrekt ------ 4|"; cout << "\n\n\t\t|Po alfavity ------ 5|"; cout << "\n\n\t\t|Staj>= insert ------ 6|"; cout << "\n\n\t\t|Vivod na ekran ------ 7|"; cout << "\n\n\t\t|Vixod ------ 8|"; cout << "\n\n\n\t\t\t\tVash vibor >>> "; cin >> choice; switch(choice) { case 1: writee(); break; case 2: readd(); break; case 3: delet(); break; case 4: writee(); break; case 5: alfavit(); break; // case 6: staj();break; // case 7: vivod(); break; case 8: exit(0); default: cout<<"\aNe verno!!! "; menu(); } }
void writee() { int n=0; char choice='y';
potok.clear(); potok.seekp( 0, ios::beg );
do { system("cls"); cout << "\n\t\t\t nomer dla zapici >>> " << n+1; cout<< "\n\t\t\tvvedite familiyu \n>>> "; //cin.ignore(); cin.get( spisok[n].FIO, 20 ); //potok.write(spisok[n].FIO,20);
cout<<"\n\t\t\tVvedite daty postypleniya na raboty: ";
cout<<"\nVvedite god >>> "; cin >> spisok[n].date[0]; //potok.write(reinterpret_cast<char*> (&spisok[n].date[0]),sizeof(char)); cout << "\nVvedite mesac >>> "; cin >> spisok[n].date[1]; //potok.write(reinterpret_cast<char*> (&spisok[n].date[1]),sizeof(char));
cout<<"\nVvedite deni >>> "; cin>>spisok[n].date[2]; //potok.write(reinterpret_cast<char*> (&spisok[n].date[2]),sizeof(char));
cout << "\n\t\t\tVvedite zanimaemuyu doljnosti\n>>> "; cin.ignore(); cin.get( spisok[n].doljnosti, 20 ); //potok.write(spisok[n].doljnosti,20); cout<<"\n\t\t\tVvedite srednii zarabotok\n>>> "; cin>>spisok[n].sr_zarabotok; //potok.write(reinterpret_cast<char*>(&spisok[n].sr_zarabotok),sizeof(char)); potok.write(reinterpret_cast<char*>(&spisok[ n ]), sizeof(spisok[ 0 ]));
cout<<"\n\t\t\t-----------------------------\n"; cout << "\n\t\t\tProdoljiti? (y/n) "; cin >> choice; //
//potok.seekp( 0, ios::end ); ++n;
} while(choice != 'n'); //
sz=n; menu(); }
void readd() { char output[1]; int l,i,p=0; char fam[20],dolj[20]; int d1,d2,d3; double zar;
for(i=0;i<8;i++) { potok.seekg(i*recsize); potok.read(output,1); if(output[0]!=0)p++; output[0]=0; potok.clear(); } system("cls");
for(l=0;l<p;l++) { potok.seekg(l*recsize); // potok.read(fam,20); // potok.read(reinterpret_cast<char*>(&d1),4); potok.read(reinterpret_cast<char*>(&d2),4); potok.read(reinterpret_cast<char*>(&d3),4); potok.read(dolj,20); potok.read(reinterpret_cast<char*>(&zar),8); // potok.clear();
printf("\n------------------------------------------------------"); printf("\n\tFIO <<< %s",fam); printf("\n\n\t\t Data postupleniy: "); printf("\n\n\t\t God <<< %d",d1); printf("\n\n\t\t Mesac <<< %d",d2); printf("\n\n\t\t Deni <<< %d",d3); printf("\n\n\t\t\t Doljnosti <<< %s",dolj); printf("\n\n\t\t\t\t Srednii zar <<< %.2f",zar);
for(i=0;i<20;i++) {fam[i]=0; dolj[i]=0;} d1=0; d2=0; d3=0; zar=0; } printf("\n\n-------------------------------------------"); printf("\nNajmite chto-nibudi "); getch(); menu(); }
void delet() { char output[1],g[60]; int l,i,p=0,n; char fam[20],dolj[20]; int d1,d2,d3; double zar; char choice ='y';
for(i=0;i<60;i++) {g[i]=0;}
for(i=0;i<8;i++) { potok.seekg(i*recsize); potok.read(output,1); if(output[0]!=0)p++; output[0]=0; potok.clear(); }
do { system("cls"); cout << "\n\tVvedite nomer zapici dla udaleniya >>> "; cin >> n; // for(l=n;l<=p;l++) { potok.seekg(l*recsize); // potok.read(fam,20); // potok.read(reinterpret_cast<char*>(&d1),4); potok.read(reinterpret_cast<char*>(&d2),4); potok.read(reinterpret_cast<char*>(&d3),4); potok.read(dolj,20); potok.read(reinterpret_cast<char*>(&zar),8); // potok.clear(); if(l==p) // { potok.seekg((l-1)*recsize); potok.write(g,60); potok.clear(); break; } else { potok.seekg((l-1)*recsize); potok.write(fam,20); // potok.write(reinterpret_cast<char*>(&d1),4); potok.write(reinterpret_cast<char*>(&d2),4); potok.write(reinterpret_cast<char*>(&d3),4); potok.write(dolj,20); potok.write(reinterpret_cast<char*>(&zar),8); // potok.clear(); } } cout << "\n\t\t\tProdoljiti? (y/n) >>> "; cin >> choice; }while(choice != 'n'); menu(); }
void alfavit() { int i, j; PERSONAL X; char manuf[ 8 ][ 20 ];
potok.clear(); potok.seekg( 0, ios::beg );
for( i=0; i<sz; i++ ) { potok.read( (char*)&X, sizeof(spisok[ 0 ]) ); memcpy( &manuf[ i ], X.FIO, sizeof(X.FIO) ); memset( &X, 0, sizeof(PERSONAL) ); }
qsort( (void *)manuf, sz, sizeof(manuf[ 0 ]), sort_function );
potok.clear(); potok.seekg( 0, ios::beg );
for( i=0; i<sz; ++i ) { for( j=0; j<sz; ++j ) if( stricmp( manuf[ j ], spisok[ i ].FIO )==0 ) { memcpy( &X, &spisok[ j ], sizeof(spisok[ 0 ]) ); memcpy( &spisok[ j ], &spisok[ i ], sizeof(spisok[ 0 ]) ); memcpy( &spisok[ i ], &X, sizeof(spisok[ 0 ]) ); break; } potok.write(reinterpret_cast<char*>(&spisok[ i ]), sizeof(spisok[ 0 ])); }
for( i=0; i<sz; i++ ) cout << "F.I.O " << spisok[ i ].FIO << endl << "Date: " << spisok[ i ].date[ 0 ] << "." << spisok[ i ].date[ 1 ] << "." << spisok[ i ].date[ 2 ] << endl << "doljnosti " << spisok[ i ].doljnosti << endl << "zarabotok " << spisok[ i ].sr_zarabotok << endl << "---------------------------------------" << endl;
cout << "============================" << endl;
return; }
void vivod() { int i;
potok.clear(); potok.seekg( 0, ios::beg );
for( i=0; i<sz; ++i ) potok.read( (char*)&spisok[ i ], sizeof(spisok[ 0 ]) );
for( i=0; i<sz; i++ ) cout << "F.I.O " << spisok[ i ].FIO << endl << "Date: " << spisok[ i ].date[ 0 ] << "." << spisok[ i ].date[ 1 ] << "." << spisok[ i ].date[ 2 ] << endl << "doljnosti " << spisok[ i ].doljnosti << endl << "zarabotok " << spisok[ i ].sr_zarabotok << endl << "---------------------------------------" << endl;
return; }
|
этот код еще дорабатыватьи дорабатывать
--------------------
Мои руки из дуба, голова из свинца ну и пусть ...
|