Advertisement
akevintg

(ALT 2) QUIZ II Operating System (SERVER)

Jan 6th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. // LINK SOAL : https://www.dropbox.com/sh/wussgfrqrmazf9g/AADnp_e-zKkHZWXyAFDQ5yJFa?dl=0
  2. // LINK TEMPLATE : http://pastebin.com/Rc7A08xG
  3.  
  4. #include <stdio.h>
  5. #include <sys/ipc.h>
  6. #include <sys/types.h>
  7. #include <sys/sem.h>
  8. #include <sys/shm.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <ctype.h>
  13.  
  14. struct data{
  15.     char nama[25];
  16.     char cc[17];
  17.     float sale;
  18. };
  19.  
  20. int main(){
  21.     struct sembuf s;
  22.     int h=shmget(123456,sizeof(struct data),IPC_CREAT|0666);
  23.     int e=semget(123456,1,IPC_CREAT|0666);
  24.     semctl(e,0,SETVAL,0);
  25.     struct data *card=(struct data *)shmat(h,NULL,0666);
  26.     printf("/=================================\\\n");
  27.     printf("|Blue Jack Card Processing System |\n");
  28.     printf("\\=================================/\n\n");
  29.     printf("Server\n------\n\n");
  30.     do{
  31.         int i=0;
  32.         s.sem_num=0;
  33.         s.sem_op=-1;
  34.         s.sem_flg=0;
  35.         semop(e,&s,1);
  36.         if(strcasecmp(card->nama,"exit")!=0){
  37.             printf("Card Transaction\nBluejack Card Network\n---------------------------------\n");
  38.             printf("Masked CC : ");
  39.             for(i=0;i<strlen(card->cc);i++){
  40.                 if(i<6)
  41.                     printf("%c",card->cc[i]);
  42.                 else if(i<12)
  43.                     printf("*");
  44.                 else
  45.                     printf("%c",card->cc[i]);
  46.             }
  47.             printf("\n");
  48.             printf("Card Holder  \t: %s\n",card->nama);
  49.             int r1,r2;
  50.             srand(time(NULL));
  51.             r1=rand()%26+(int)'A';
  52.             r2=rand()%26+(int)'A';
  53.             printf("Approval Code\t: %c%c%c%c%c%c\n",r1,r2,card->cc[12],card->cc[13],card->cc[14],card->cc[15]);
  54.             printf("Sale Amount  \t: $ %10.2f\n",card->sale);
  55.             float pf;
  56.             pf=0.03*card->sale+0.1;
  57.             printf("Processing Fee \t: $ %10.2f\n",pf);
  58.             printf("--------------------------------+\n");
  59.             printf("Total Payment  \t: $ %10.2f\n\n",pf+card->sale);
  60.         }
  61.  
  62.     }while(strcasecmp(card->nama,"exit")!=0);
  63.     shmdt(&s);
  64.     shmctl(h,IPC_RMID,0);
  65.     semctl(e,0,IPC_RMID);
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement