Results 1 to 4 of 4
Thread: C/C++
Hybrid View
-
30th December 2010 13:43 #1Registered User
Join Date: Dec:2010
Location:
Posts: 1
C/C++
:
) ( 30): ,
, , , .
() .
) 2 ,
( )
.
) -
. .
- , , . ?Code:#include<iostream.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> struct students { char name[15]; char familia[15]; long double fn; float uspeh; int godini; int pol; }arr[30],arm[30],arj[30],temp[30],tempj[30]; void input(); void pz(); void nm(); void load(); void save(); int i=0; int k; int p; int br=0; void main() { int i; load(); do { cout<<"\n *****MENU*****"<<endl; cout<<"\n 1.Vavejdane na inforfmaciq za student"<<endl; cout<<"\n 2.Prezapisvane v 2 otdelni masiva[maje-jeni]"<<endl; cout<<"\n 3.Opredelqne na nai-mladata studentka i sortirane po vazrast"<<endl; cout<<"\n 4.Zapisvane vav fail"<<endl; cout<<"\n 5.Izhod"<<endl; cin>>i; if(i>0 || i<5) { switch(i) { case 1:input();break; case 2:pz();break; case 3:nm();break; case 4:save();break; } } else cout<<"\n Nevalidna funkciq"<<endl; } while(i!=5); } void input() { cout<<"\n Vuvedete broj studenti:"; cin>>br; if(br<1||br>30) cout<<"\n Maksimalniqt broi studenti e 30!"<<endl; else for(i=0;i<br;i++) { cout<<"\n Ime: "; cin>>arr[i].name; cout<<"\n Familia: "; cin>>arr[i].familia; cout<<"\n Fakulteten nomer: "; cin>>arr[i].fn; cout<<"\n Uspeh: "; cin>>arr[i].uspeh; cout<<"\n Vuzrast: "; cin>>arr[i].godini; cout<<"\n Pol (1=maj/2=jena): "; cin>>arr[i].pol; cout<<"-----------------"<<endl; fflush(stdin); } cout<<"\n Tekushto sadarjanie:"<<endl; cout<<" --------------------"<<endl; for(i=0;i<br;i++) { cout<<"Ime: "<<arr[i].name<<endl; cout<<"Familiq: "<<arr[i].familia<<endl; cout<<"F.N.: "<<arr[i].fn<<endl; cout<<"Uspeh: "<<arr[i].uspeh<<endl; cout<<"Godini: "<<arr[i].godini<<endl; cout<<"Pol (1=maj/2=jena): "<<arr[i].pol<<endl; cout<<" --------------"<<endl; } } void pz() { int t; float srm=0; float srj=0; for(i=0;i<br;i++) { if(arr[i].pol==1) { arm[k]=arr[i];k++;t++; } else { arj[p]=arr[i];p++; } } cout<<"\n Maje:"<<endl; for(i=0;i<k;i++) { cout<<"Ime: "<<arm[i].name<<endl; cout<<"Familiq: "<<arm[i].familia<<endl; cout<<"F.N.: "<<arm[i].fn<<endl; cout<<"Uspeh: "<<arm[i].uspeh<<endl; cout<<"Godini: "<<arm[i].godini<<endl; cout<<"Pol (1=maj/2=jena): "<<arm[i].pol<<endl; cout<<" --------------"<<endl; srm+=arm[i].godini; } cout<<"\n Sredna vazrast maje:"<<srm/k<<endl; cout<<"\n Jeni:"<<endl; for(i=0;i<p;i++) { cout<<"Ime: "<<arj[i].name<<endl; cout<<"Familiq: "<<arj[i].familia<<endl; cout<<"F.N.: "<<arj[i].fn<<endl; cout<<"Uspeh: "<<arj[i].uspeh<<endl; cout<<"Godini: "<<arj[i].godini<<endl; cout<<"Pol (1=maj/2=jena): "<<arj[i].pol<<endl; cout<<" --------------"<<endl; srj+=arj[i].godini; } cout<<"\n Sredna vazrast jeni:"<<srj/p<<endl; } void nm() { int i; char x; int j; for(i=0;i<br-1;i++) for(j=i+1;j<br;j++) if(arr[i].godini>arr[j].godini) { temp[x]=arr[i]; arr[i]=arr[j]; arr[j]=temp[x]; } for(i=0;i<p-1;i++) for(j=i+1;j<p;j++) if(arj[i].godini>arj[j].godini) { tempj[x]=arj[i]; arj[i]=arj[j]; arj[j]=tempj[x]; } cout<<"\n Nai-mlada studentka:"<<endl; cout<<"Ime: "<<arj[0].name<<endl; cout<<"Familiq: "<<arj[0].familia<<endl; cout<<"F.N.: "<<arj[0].fn<<endl; cout<<"Uspeh: "<<arj[0].uspeh<<endl; cout<<"Godini: "<<arj[0].godini<<endl; cout<<"Pol (1=maj/2=jena): "<<arj[0].pol<<endl; cout<<" --------------"<<endl; cout<<"\n Vazhodqsht spisak po godini:"<<endl; for(i=0;i<br;i++) { cout<<"Ime: "<<arr[i].name<<endl; cout<<"Familiq: "<<arr[i].familia<<endl; cout<<"F.N.: "<<arr[i].fn<<endl; cout<<"Uspeh: "<<arr[i].uspeh<<endl; cout<<"Godini: "<<arr[i].godini<<endl; cout<<"Pol (1=maj/2=jena): "<<arr[i].pol<<endl; cout<<" --------------"<<endl; } } void load() { FILE *fp; int i; if((fp=fopen("students.dat","rb"))==NULL) { cout<<"\n File not found";return;; } for(i=0;i<br;i++) if(fread(&arr[i],sizeof(arr[i]),1,fp)!=1) { cout<<"\n Error reading students";exit(1); } fclose(fp); } void save() { FILE *fp; int i; if((fp=fopen("students.dat","wb"))==NULL) { cout<<"\n File error";exit(1); } for(i=0;i<br;i++) if(fwrite(&arr[i],sizeof(arr[i]),1,fp)!=1) { cout<<"\n Error writing struct";exit(1); } fclose(fp); }
-
31st December 2010 22:34 #2br?Code:
for(i=0;i<br;i++) if(fread(&arr[i],sizeof(arr[i]),1,fp)!=1) { cout<<"\n Error reading students";exit(1); }Have no fear ike iz here.
CPU Cx486DLC@40MHz, RAM 4MB, VGA Trident 512KB, HDD Conner 160MB, Monitor 14" Color
-
3rd January 2011 22:07 #3Registered User
Join Date: Jun:2009
Location: Kazanlyk
Posts: 72
, . , / / for,do-while,while, . , , - -.
. .Code:while ((ch=getc(fp))!=EOF) /*Prochitane znak po znak*/ { if (ch=='\n') (*br_red)++; //Proverka za nov red if (ch=='"' && ch1!=39 && ch1!='\\' && f1+f2==0) f3++; /*Proverka za nizovi konstanti*/ if (f3%2) goto znaci; //Chetene do kraq na nizovata konstanta if (ch=='/' && ch1=='/' && !((f3%2)+f1+f2)) {f1=1;goto znaci;} //nachalo na komentar ot tipa (//) if (ch=='*' && ch1=='/' && !((f3%2)+f1+f1)) {f2=1;goto znaci;} //nachalo na komentar ot tipa (/*) if (f1 && ch=='\n' && !f2) {f1=0;(*br_kom)++;} //kraj na komentar ot tipa (//) if (ch=='/' && ch1=='*' && f2) {f2=0;(*br_kom)++;} //kraj na komentar ot tipa (/*) if (f1+f2) goto znaci; //Chetene do kraq na komentara if (strchr(razdelitel,ch)!=NULL) { if (ch1=='o' && ch2=='d' && (strchr(razdelitel,ch3)!=NULL)) { (*br_do)++; goto znaci; } if (ch1=='r' && ch2=='o' && ch3=='f' && (strchr(razdelitel,ch4)!=NULL)) { (*br_for)++; goto znaci; } if (ch1=='e' && ch2=='l' && ch3=='i' && ch4=='h' && ch5=='w' && (strchr(razdelitel,ch6)!=NULL)) (*br_while)++; } znaci:{ ch6=ch5; ch5=ch4; ch4=ch3; ch3=ch2; ch2=ch1; ch1=ch; } } (*br_while)-=(*br_do);Last edited by Oteca; 3rd January 2011 at 23:25.
Intel C2D E8200,3400MHz,Gigabyte GA-P35C-DS3R,2x1GB A-Data DDR2-960(4-4-4-12),Seagate 320GB+Samsung F3 1TB, 8600 GTS,PSU Black Diamond 500W,LiteOn DH20A4P
Asus N56VZ
-
6th January 2011 22:24 #4




Reply With Quote

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