Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <fstream>
- #include <stdlib.h>
- /*
- Popescu Viorel Constantin 7.90
- Ion Ana Diana 9.00
- Pop Mircea 6.50
- Separ numele, prenumele si media!
- */
- using namespace std;
- struct pers
- {
- char nume[30],prenume[30];
- float medie;
- } a[100];
- int n;
- int continecifre(char *p)
- {
- int i;
- for(i=0; i<strlen(p); i++)
- if(p[i]>='0'&&p[i]<='9')
- return 1;
- return 0;
- }
- void citire()
- {
- int i,ok=0;
- char s[200],*p,pren[200];
- ifstream f("fis.in");
- while(f.getline(s,200))
- {
- //separ cuvintele//
- p=strtok(s," ");
- n++;
- strcpy(pren,"");
- ok=0;
- while(p!=NULL)
- {
- if(ok==0)
- {
- //extrag numele de familie//
- strcpy(a[n].nume,p);
- ok=1;
- }
- else if(continecifre(p))
- a[n].medie=atof(p);
- else
- {
- strcat(pren,p);
- strcat(pren," ");
- }
- p=strtok(NULL," ");
- }
- strcpy(a[n].prenume,pren);
- }
- }
- void afis()
- {
- int i;
- for(i=1; i<=n; i++)
- cout<<a[i].prenume<<" "<<a[i].nume<<" "<<a[i].medie<<"\n";
- }
- int main()
- {
- citire();
- afis();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement