Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SOAL
- =========================================================================================================================
- Input :
- No Handphone [10-12], depan harus 08, kalo ketik exit dia keluar
- Pilih provider [XL || Telkomsel || Indosat] case TIDAK sensitif
- pilih pulsa [10000 || 25000 || 50000 || 100000]
- Masukan CAPTCHA (*) case sensitive
- Output:
- Detail pemesanan
- ==================
- No HP : no hp dengan sensor 3 no terkahir
- Provider : pilihan provider//sudah di HURUF BESARKAN SEMUA
- Pulsa : Rp. pilihan pulsa,00
- No transaksi : [2 kata pertama merk Provider]+[3 digit no hp terakhir]+[2 kata pertama dari CAPTCHA di huruf kecilkan]
- //format captca adalah random 2 huruf+no terakhir di no hp+2kata pertama provider HURUF BESAR
- Contoh accepted input :
- No HP : 087840094200
- Provider : telKomsEL
- Pulsa : 50000
- Captcha (GF200XL) : GF200TE
- Output :
- No HP : 087840094***
- Provider : TELKOMSEL
- Pulsa : Rp. 50000,00
- No Transaksi : TE200gf
- PENJELASAN :
- input ->captcha, GF dari random 2 huruf, 200 dari 3 no belakang hp, XL kode provider
- output -> no hp di sensor 3 paling belakang
- provider di huruf besarkan semuanya
- pulsa ditambahkan Rp. ,00
- No transaksi, TE dari telkomsel, 200 3 no belakang, gf randomnya dikecilin hurufnya
- *hint, ASCII A-Z itu 65-92;
- */
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <time.h>
- #include <unistd.h>
- #include <stdlib.h>
- struct data {
- char no[15];
- char provider[10];
- int pulsa;
- char captcha[10];
- };
- int main(){
- struct data cust;
- pid_t pFork;
- int pipes[2],i,j,flag;
- char cpt[10];
- if(pipe(pipes)<0){
- printf("Error Pipe");
- exit(1);
- }
- int r1,r2;
- pFork=fork();
- if(pFork==0){
- printf("\nChild Process\n=========================\n\n");
- do{
- flag=0;
- printf("No Handphone [10...12][08xxxxxx][exit to close]: ");
- scanf("%s",cust.no);getchar();
- if(strlen(cust.no)<10||strlen(cust.no)>12)
- flag=1;
- if(cust.no[0]!='0'||cust.no[1]!='8')
- flag=1;
- for(j=0;j<strlen(cust.no);j++){
- if(!isdigit(cust.no[j]))
- flag=1;
- }
- if(strcasecmp(cust.no,"exit")==0){
- printf("Program is Quiting\n");
- exit(1);
- }
- }while(flag==1);
- do{
- flag=0;
- printf("Pilih Provide [XL || Telkomsel || Indosat]: ");
- scanf("%s",cust.provider);getchar();
- if(strcasecmp(cust.provider,"xl")!=0&&strcasecmp(cust.provider,"telkomsel")!=0&&strcasecmp(cust.provider,"indosat"))
- flag=1;
- }while(flag==1);
- do{
- flag=0;
- printf("Pilih Pulsa [10000 || 25000 || 50000 || 100000]: ");
- scanf("%d",&cust.pulsa);getchar();fflush(stdin);
- if(cust.pulsa!=10000&&cust.pulsa!=25000&&cust.pulsa!=50000&&cust.pulsa!=100000)
- flag=1;
- }while(flag==1);
- srand(time(NULL));
- r1=rand()%26+65;
- r2=rand()%26+65;
- cpt[0]=r1;
- cpt[1]=r2;
- cpt[2]=cust.no[strlen(cust.no)-3];
- cpt[3]=cust.no[strlen(cust.no)-2];
- cpt[4]=cust.no[strlen(cust.no)-1];
- cpt[5]=toupper(cust.provider[0]);
- cpt[6]=toupper(cust.provider[1]);
- cpt[7]='\0';
- do{
- flag=0;
- printf("Masukan Captcha (%s)[case sensitive]: ",cpt);
- scanf("%s",cust.captcha);getchar();
- if(strcmp(cust.captcha,cpt)!=0)
- flag=1;
- }while(flag==1);
- close(pipes[0]);
- write(pipes[1],(struct data*)&cust,sizeof(cust));
- }
- else if(pFork>0){
- close(pipes[1]);
- read(pipes[0],(struct data*)&cust,sizeof(cust));
- printf("\nParent Process\n=========================\n\n");
- char noTemp[10];
- strncpy(noTemp,cust.no,strlen(cust.no)-3);
- printf("No HP : %s***\n",noTemp);
- printf("Provider : ");
- for(j=0;j<strlen(cust.provider);j++)
- printf("%c",toupper(cust.provider[j]));
- printf("\nPulsa : Rp. %d,00\n",cust.pulsa);
- printf("No Transaksi : %c%c%c%c%c%c%c\n",toupper(cust.provider[0]),toupper(cust.provider[1]),
- cust.no[strlen(cust.no)-3],cust.no[strlen(cust.no)-2],cust.no[strlen(cust.no)-1],
- tolower(cust.captcha[0]),tolower(cust.captcha[1]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement