Daniel_leinaD

6

Jun 9th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <time.h>
  5. #include <string.h>
  6. #define L 80
  7.  
  8. struct credit{
  9.     int ID;
  10.     char *surname;
  11.     char *name;
  12.     double summ;
  13.     int percent;
  14. };
  15.  
  16. void credinput(struct credit *lis,int *count){
  17.     struct credit *p;
  18.     char buff[L],buff1[L];
  19.     p = &lis[*count];
  20.     (p->ID)=*count;
  21.     *count +=1;
  22.     printf("type surname:");getchar();
  23.     fgets(buff,sizeof(buff),stdin);
  24.     buff[strlen(buff)-1] = '\0';
  25.     p->surname =(char*) malloc (strlen(buff)+1);
  26.     strcpy(p->surname,buff);
  27.     printf("type name:");
  28.     fgets(buff,sizeof(buff),stdin);
  29.     buff[strlen(buff)-1] = '\0';
  30.     p->name =(char*) malloc (strlen(buff)+1);
  31.     strcpy(p->name,buff);
  32.     printf("summ of credit:");
  33.     scanf("%lf",&(p->summ));
  34.     printf("and percent:");
  35.     scanf("%d",&(p->percent));
  36.     printf("%d\n",p->ID);getchar();
  37. }
  38.  
  39. void printcredit(struct credit *lis, int n){
  40.     struct credit *p;
  41.     printf("ID            surname                name             percent                summ\n");
  42.     printf("----------------------------------------------------------------------------------\n");
  43.      for(int i = 0; i<n;i++){
  44.         p = &lis[i];
  45.         printf("%d%20s%20s%20d%20.3lf\n",p->ID,p->surname,p->name,p->percent,p->summ);
  46.     }
  47.     printf("----------------------------------------------------------------------------------\n");
  48. }
  49.    
  50. double namesearch(struct credit *lis,char n1[L],char n2[L],int count){
  51.     struct credit *p;
  52.     double sun=0;
  53.     for(int i = 0;i<count;i++){
  54.         p = &lis[i];
  55.         if((strcmp(p->name,n1)==0)&&((strcmp(p->surname,n2)==0))){
  56.             sun += p->summ;
  57.         }
  58.     }
  59.     return sun;
  60. }
  61.  
  62. struct credit *percentsearch(struct credit *lis,int per,int count,int *newcount){
  63.     struct credit *otv,*p;
  64.     int i;
  65.     otv = (struct credit*)calloc(sizeof(struct credit),count);
  66.     for(i = 0;i < count;i++){
  67.         p = &lis[i];
  68.         if(p->percent==per){
  69.             otv[*newcount] = *p;
  70.             *newcount+=1;
  71.         }
  72.     }
  73.     return otv;
  74. }
  75.  
  76. int main(){
  77.     struct credit *mlist,*otv = NULL;
  78.     int idcount=0,n,newc=0;
  79.     char y,imya[L],familia[L];
  80.     double sum;
  81.     printf("type max number of credits:\n");
  82.     scanf("%d",&n);
  83.     mlist = (struct credit*)calloc(sizeof(struct credit),n);
  84.     do{
  85.         credinput(mlist,&idcount);
  86.         scanf("%c",&y);
  87.     }while(y == 'y');
  88.     printf("%d\n",idcount);
  89.     sum = namesearch(mlist,mlist[0].name,mlist[0].surname,idcount);
  90.     printf("%.3lf\n",sum);
  91.     otv = percentsearch(mlist,2,idcount,&newc);
  92.     printcredit(otv,newc);
  93.     free(mlist);
  94.     free(otv);
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment