Results 1 to 5 of 5
Hybrid View
-
11th May 2012 20:28 #1
.
, . , ( , ).
:
.Code:#include<windows.h> #include<iostream> #include<fstream> #include<fcntl.h> #include<string> using namespace std; struct patient { string EGN; string Name; int YoB; string Town; string DateIn; string Diagnose; int DiH; }p; int delt=0; string sDateIn; void create() { ofstream f; f.open("hospital.txt",ios::out); if(!f) { cout<<"Error!\n"; system("pause"); return; } int n=-1; while(n!=0) { cout<<"EGN:"; cin.ignore(1024,'\n'); getline(cin, p.EGN); cout<<"Ime:"; getline(cin, p.Name); cout<<"Godina na rajdane:"; cin>>p.YoB; cout<<"Mestojiweene:"; cin.ignore(1024,'\n'); getline(cin, p.Town); cout<<"Data na postypwane(den,mesecm godina nerazdeleni):"; getline(cin, p.DateIn); cout<<"Diagnoza:"; getline(cin, p.Diagnose); cout<<"Prestoj w bolnicata:"; cin>>p.DiH; f.write((const char*)&p,sizeof(struct patient)); cout<<"Now zapis: 1-da, 0-ne\n"; cin>>n; } f.close(); } void append() { ofstream f; f.open("hospital.txt",ios::app); if(!f) { cout<<"Error!\n"; system("pause"); return; } int n=-1; while(n!=0) { cout<<"EGN:"; cin.ignore(1024,'\n'); getline(cin, p.EGN); cout<<"Ime:"; getline(cin, p.Name); cout<<"Godina na rajdane:"; cin>>p.YoB; cout<<"Mestojiweene:"; cin.ignore(1024,'\n'); getline(cin, p.Town); cout<<"Data na postypwane(den,mesecm godina nerazdeleni):"; getline(cin, p.DateIn); cout<<"Diagnoza:"; getline(cin, p.Diagnose); cout<<"Prestoj w bolnicata:"; cin>>p.DiH; cin.ignore(1024,'\n'); f.write((const char*)&p,sizeof(struct patient)); cout<<"Now zapis: 1-da, 0-ne\n"; cin>>n; } f.close(); } void update() { unsigned long pos; fstream f; f.open("hospital.txt", ios::in|ios::out|ios::binary); string sEGN; cout<<"Tyrseno EGN:"; cin.ignore(1024,'\n'); getline(cin, sEGN); string newDiagnose; int newDiH; cout<<"Diagnoza:"; getline(cin, newDiagnose); cout<<"Prestoj w bolnicata:"; cin>>newDiH; if(!f) { cout<<"Error!\n"; system("pause"); return; } f.seekg(0, ios::beg); while(f.read((char*)&p, sizeof(struct patient))) { if(p.EGN==sEGN) { p.Diagnose=newDiagnose; p.DiH=newDiH; pos=f.tellg(); pos-=sizeof(struct patient); f.seekg(pos); f.write((const char*)&p, sizeof(struct patient)); } } f.close(); system("PAUSE"); } void del() { unsigned long pos; fstream f; int flag=0; struct patient temp; f.open("hospital.txt",ios::in|ios::out|ios::binary); if(!f) { cout<<"Error!\n"; system("pause"); return; } string sEGN; unsigned long pos_delete; f.seekg(0, ios::end); pos=f.tellg(); pos-=sizeof(struct patient); f.seekg(pos); pos_delete=pos; f.read((char*)&temp,sizeof(struct patient)); if(delt==1) { cout<<"Wywedi EGN za iztriwane: "; cin>>sEGN; if(temp.EGN==sEGN) { flag=1; unsigned long fd=_open("hospital.txt", 2); chsize(fd, pos_delete); } else { f.seekg(0, ios::beg); while(f.read((char*)&p, sizeof(struct patient))) { if(p.EGN==sEGN) { flag=1; pos=f.tellg(); pos-=sizeof(struct patient); f.seekg(pos); f.write((const char*)&temp, sizeof(struct patient)); unsigned long fd=_open("hospital.txt", 2); chsize(fd, pos_delete); } } } } else { if(!(delt==2)) { cout<<"Wywedi krajna data za iztriwane(den, mesecm godina nerazdeleni): "; cin>>sDateIn; } if(temp.DateIn<sDateIn) { flag=1; unsigned long fd=_open("hospital.txt", 2); chsize(fd, pos_delete); } else { f.seekg(0, ios::beg); while(f.read((char*)&p, sizeof(struct patient))) { if(p.DateIn<sDateIn) { flag=1; pos=f.tellg(); pos-=sizeof(struct patient); f.seekg(pos); f.write((const char*)&temp, sizeof(struct patient)); unsigned long fd=_open("hospital.txt", 2); chsize(fd, pos_delete); } } } } if(flag==0) cout<<"Nqma takyw pacient.\n"; system("PAUSE"); f.close(); } void maxDiH() { ifstream f; int sDiH; f.open("hospital.txt", ios::in); if(!f) { cout<<"Error!\n"; system("pause"); return; } f.read((char*)&p, sizeof(struct patient)); sDiH=p.DiH; while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; if(sDiH<p.DiH) sDiH=p.DiH; } f.seekg(0, ios::beg); while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; if(sDiH==p.DiH) { cout<<p.Name<<endl; cout<<p.Town<<endl; cout<<p.Diagnose<<endl; } } } void TownDia() { ifstream f; string sTown, sDiagnose; cout<<"Pacienti ot grad "; cin.ignore(1024,'\n'); getline(cin, sTown); cout<<"s diagnoza "; cin.ignore(1024,'\n'); getline(cin, sDiagnose); f.open("hospital.txt", ios::in); if(!f) { cout<<"Error!\n"; system("pause"); return; } while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; if((p.Town==sTown)&&(p.Diagnose==sDiagnose)) { cout<<p.Name<<endl; cout<<p.EGN<<endl; cout<<p.YoB<<endl; cout<<p.Town<<endl; cout<<p.DateIn<<endl; cout<<p.Diagnose<<endl; cout<<p.DiH<<endl<<endl; } } } float avgDiH() { ifstream f; int sDiH=0, N=0; f.open("hospital.txt", ios::in); if(!f) { cout<<"Error!\n"; system("pause"); exit(0); } while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; sDiH+=p.DiH; N++; } return sDiH/N; } void Townperc() { ifstream f; int M=0, N=0; string sTown; cout<<"Pacienti ot grad "; cin.ignore(1024,'\n'); getline(cin, sTown); f.open("hospital.txt", ios::in); if(!f) { cout<<"Error!\n"; system("pause"); return; } while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; M++; if(p.Town==sTown) { cout<<p.Name<<endl; cout<<p.EGN<<endl<<endl; N++; } } cout<<(N/M)*100<<"% ot wsichki pacienti"<<endl; } void EGNprint() { ifstream f; string sEGN; f.open("hospital.txt",ios::in); if(!f) { cout<<"Error!\n"; system("pause"); return; } cout<<"Tyrseno EGN:"; cin.ignore(1024,'\n'); getline(cin, sEGN); while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; if(p.EGN==sEGN) { cout<<"EGN:"<<p.EGN; cout<<"Ime:"<<p.Name; cout<<"Godina na rajdane:"<<p.YoB; cout<<"Mestojiweene:"<<p.Town; cout<<"Data na postypwane:"<<p.DateIn; cout<<"Diagnoza:"<<p.Diagnose; cout<<"Prestoj w bolnicata:"<<p.DiH; } } f.close(); } void print() { ifstream f; f.open("hospital.txt",ios::in); if(!f) { cout<<"Error!\n"; system("pause"); return; } while(!f.eof()) { if(!(f.read((char*)&p, sizeof(struct patient)))) break; cout<<"EGN:"<<p.EGN; cout<<"Ime:"<<p.Name; cout<<"Godina na rajdane:"<<p.YoB; cout<<"Mestojiweene:"<<p.Town; cout<<"Data na postypwane:"<<p.DateIn; cout<<"Diagnoza:"<<p.Diagnose; cout<<"Prestoj w bolnicata:"<<p.DiH; } f.close(); system("PASUE"); } int main() { int op=-1, po=-1; while(op!=0) { system("CLS"); cout<<"Izberete funkciq:\n"; cout<<"1-Syzdawane na sistemata.\n"; cout<<"2-Aktualizaciq.\n"; cout<<"3-Sprawki.\n"; cout<<"4-IZtriwane na wsichki danni.\n"; cout<<"Ostanalo-izhod.\n"; cin>>op; switch(op) { case 1: { system("CLS"); cout<<"Syzdawane na informacionnata sistema:\n"; create(); } break; case 2: { system("CLS"); cout<<"Aktualiziciq:\n"; cout<<"1-Now pacient.\n"; cout<<"2-Promqna na pacient.\n"; cout<<"3-Iztriwane po EGN.\n"; cout<<"4-Iztriwane po data.\n"; cin>>po; switch(po) { case 1: { system("CLS"); cout<<"Dobawqne na now pacient kym sistemata:\n"; append(); } break; case 2: { system("CLS"); cout<<"Promqna na dannite na pacient:\n"; update(); } break; case 3: { system("CLS"); cout<<"Iztriwane na dannite na pacient:\n"; delt=1; del(); } break; case 4: { system("CLS"); cout<<"Iztriwane na dannite na pacienti:\n"; del(); } break; } } break; case 3: { system("CLS"); cout<<"Sprawki:\n"; cout<<"1-Pacienti s maksimalen prestoj.\n"; cout<<"2-Pacienti ot grad s diagnoza.\n"; cout<<"3-Sreden prestoj w bolnicata.\n"; cout<<"4-Pacienti ot grad, procent ot wsichki.\n"; cout<<"5-Danni za pacient.\n"; cout<<"6-Wsichki danni na wsichki pacienti.\n"; cin>>po; switch(po) { case 1: { system("CLS"); cout<<"Pacientite s maksimalen presoj sa:\n"; maxDiH(); } break; case 2: { system("CLS"); TownDia(); } break; case 3: { system("CLS"); cout<<"Sredniqt prestoq w bolnicata e "<<avgDiH<<" dni"; } break; case 4: { system("CLS"); Townperc(); } break; case 5: { system("CLS"); EGNprint(); } break; case 6: { system("CLS"); cout<<"Danni za wsichki pacienti:\n"; print(); } break; } } break; case 4: { system("CLS"); delt=0; sDateIn="99999999"; del(); } break; default: exit(0); } } system("PAUSE"); return 0; }
, . system("paSUe") system("pause"). : . Notepad .
Code:9M 9M 9M 9M :M
Laa shay'a waqi'un moutlaq bale kouloun moumkine.
Nulla é reale, tutto é lecito.
-
11th May 2012 22:26 #2Registered User
Join Date: Oct:2003
Location:
Posts: 4,317
. sizeof(struct patient) . string, http://www.cplusplus.com/reference/string/string/
-
12th May 2012 23:26 #3
?
Laa shay'a waqi'un moutlaq bale kouloun moumkine.
Nulla é reale, tutto é lecito.
-
13th May 2012 09:57 #4
Join Date: Apr:2006
Location:
Posts: 8,666
locales + wfstream + wchar_t + wstring + define _UNICODE
, - ,whatever ...
_wfopen(myfilestringname, L"wt, ccs=UTF-8")Last edited by smelkomar; 13th May 2012 at 10:25.
-
13th May 2012 15:04 #5
. .
Laa shay'a waqi'un moutlaq bale kouloun moumkine.
Nulla é reale, tutto é lecito.




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in