Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <time.h>
- #include <string.h>
- #define L 80
- struct credit{
- int ID;
- char *surname;
- char *name;
- double summ;
- int percent;
- };
- void credinput(struct credit *lis,int *count){
- struct credit *p;
- char buff[L],buff1[L];
- p = &lis[*count];
- (p->ID)=*count;
- *count +=1;
- printf("type surname:");getchar();
- fgets(buff,sizeof(buff),stdin);
- buff[strlen(buff)-1] = '\0';
- p->surname =(char*) malloc (strlen(buff)+1);
- strcpy(p->surname,buff);
- printf("type name:");
- fgets(buff,sizeof(buff),stdin);
- buff[strlen(buff)-1] = '\0';
- p->name =(char*) malloc (strlen(buff)+1);
- strcpy(p->name,buff);
- printf("summ of credit:");
- scanf("%lf",&(p->summ));
- printf("and percent:");
- scanf("%d",&(p->percent));
- printf("%d\n",p->ID);getchar();
- }
- void printcredit(struct credit *lis, int n){
- struct credit *p;
- printf("ID surname name percent summ\n");
- printf("----------------------------------------------------------------------------------\n");
- for(int i = 0; i<n;i++){
- p = &lis[i];
- printf("%d%20s%20s%20d%20.3lf\n",p->ID,p->surname,p->name,p->percent,p->summ);
- }
- printf("----------------------------------------------------------------------------------\n");
- }
- double namesearch(struct credit *lis,char n1[L],char n2[L],int count){
- struct credit *p;
- double sun=0;
- for(int i = 0;i<count;i++){
- p = &lis[i];
- if((strcmp(p->name,n1)==0)&&((strcmp(p->surname,n2)==0))){
- sun += p->summ;
- }
- }
- return sun;
- }
- struct credit *percentsearch(struct credit *lis,int per,int count,int *newcount){
- struct credit *otv,*p;
- int i;
- otv = (struct credit*)calloc(sizeof(struct credit),count);
- for(i = 0;i < count;i++){
- p = &lis[i];
- if(p->percent==per){
- otv[*newcount] = *p;
- *newcount+=1;
- }
- }
- return otv;
- }
- int main(){
- struct credit *mlist,*otv = NULL;
- int idcount=0,n,newc=0;
- char y,imya[L],familia[L];
- double sum;
- printf("type max number of credits:\n");
- scanf("%d",&n);
- mlist = (struct credit*)calloc(sizeof(struct credit),n);
- do{
- credinput(mlist,&idcount);
- scanf("%c",&y);
- }while(y == 'y');
- printf("%d\n",idcount);
- sum = namesearch(mlist,mlist[0].name,mlist[0].surname,idcount);
- printf("%.3lf\n",sum);
- otv = percentsearch(mlist,2,idcount,&newc);
- printcredit(otv,newc);
- free(mlist);
- free(otv);
- }
Advertisement
Add Comment
Please, Sign In to add comment