int main() { int time,cust,i,k; float avg_time_spent=0; struct queue A,B,C,D; A.front=B.front=C.front=D.front=0; A.rear=B.rear=C.rear=D.rear=-1; int entry_time[NUMOFCUST]={0,0,1,0,1,4}; int duration[NUMOFCUST] = {2,5,7,6,4,4}; int time_spent[NUMOFCUST]; printf("time\t tellers\n\tA B C D\n"); for(time=0;time<TIMEDURATION;++time) { for(cust=0;cust<NUMOFCUST;++cust) { if(entry_time[cust]==time) { switch(shortline(&A,&B,&C,&D)) { case 1: time_spent[cust]=duration[cust]+sizeofq(&A); for(k=0;k<duration[cust];++k) insertq(&A,cust+1); break; case 2: time_spent[cust]=duration[cust]+sizeofq(&B); for(k=0;k<duration[cust];++k) insertq(&B,cust+1); break; case 3: time_spent[cust]=duration[cust]+sizeofq(&C); for(k=0;k<duration[cust];++k) insertq(&C,cust+1); break; default: time_spent[cust]=duration[cust]+sizeofq(&D); for(k=0;k<duration[cust];++k) insertq(&D,cust+1); break; } } } printf("\n%2d\t",time); if(sizeofq(&A)!=0) printf("%d ",removeq(&A)); else printf("- "); if(sizeofq(&B)!=0) printf("%d ",removeq(&B)); else printf("- "); if(sizeofq(&C)!=0) printf("%d ",removeq(&C)); else printf("- "); if(sizeofq(&D)!=0) printf("%d ",removeq(&D)); else printf("- "); } for(i=0;i<NUMOFCUST;i++) { printf("\nCustomer %d spends %d min(s)",i+1,time_spent[i]); avg_time_spent+=time_spent[i]; } avg_time_spent/=6; printf("\nAn average customer spends %.2f min(s) in the bank\n",avg_time_spent); return 0; }
void main() { // VARIABLE DECLARATIONS int i=0,j=0,a,front=-1,rear=-1; char ch,ch1; int item; // FUNCTION PROTOTYPE DECLARATIONS void show(); void slidebar(int *rear,int *front); void showqueuesize(); void slidebar(); void cpoiters(); void drawq(); void moveptrs(int *rear,int *front); void insertq(int *rear,char c); void deleteq(int *front); void qdelete(int q[],int rear,int front); void hidequeueinfo(); void shownumbers(int x1,int y1,int x2,int y2); int initmouse(); void getmousepos(int *button,int *x,int *y); void showmouseptr(); void restrictmouseptr(int a,int b,int c,int d); void exitbutton(int x1,int y1,int x2,int y2,int e_x,int e_y,int xit_x,int xit_y); void zoomin(); // CHECKING THE GRAPHICS DRIVER int gd=DETECT,gm,maxx,maxy,x,y,button; initgraph(&gd,&gm,"c:\\TC"); // GET THE MAXIMUM X AND Y CO ORDINATES maxx=getmaxx(); maxy=getmaxy(); // DRAW THE BORDER FOR THE WINDOW rectangle(0,0,maxx,maxy); // SET THE AREA WITHIN THE SCREEN WHERE GRAPHICAL O/P DISPLAYED setviewport(1,1,maxx-1,maxy-1,1); // WRITE THE HEADDING gotoxy(150,1); settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); setcolor(WHITE); setbkcolor(216); settextjustify(0,2); outtextxy(220,2," LINEAR QUEUE "); setcolor(RED); settextstyle(8,HORIZ_DIR,3); outtextxy(40,35,"DEVELOPED IN 'C' : IT'S A KVSM PRODUCT"); settextstyle(0,HORIZ_DIR,0); // INITIALIZE MOUSE,IF IT DOESN'T GET INITIALIZED CLOSE GRAPHICS MODE if (initmouse()==0) { closegraph(); restorecrtmode(); printf("\nMouse Driver not installed"); exit(1); } // IF MOUSE DRIVER INITIALISED THEN // RESTRICT THE MOUSE POINTER WITHIN THE COORDINATES GIVEN GIVEN BELOW restrictmouseptr(1,57,maxx-1,maxy-1); // SHOW THE MOUSE POINTER showmouseptr(); // SET THE TEXT COLOR TO WHITE setcolor(WHITE); line(0,70,getmaxx(),70); line(0,400,getmaxx(),400); setcolor(14); outtextxy(65,115,"QUEUE OPERATIONS QUEUE STATUS"); outtextxy(140,440,"Press the Key that is Highlighted or use Mouse."); setcolor(CYAN); line(65,125,190,125); line(368,125,464,125); // CALL THE SHOW FUNCTION TO DRAW THE VARIOUS BUTTONS show(); // DRAW THE QUEUE drawq(); // DRAW THE POINTERS THAT IS FRONT AND REAR moveptrs(&rear,&front); // SET THE LABEL M THAT WILL BE USED LATER FOR UNCONDITIONAL JUMP m: // GO ON CHECKING WHETHER A KEY IS PRESSED OR NOT while (i==0) { if (kbhit()) { ch=getche(); // CHECK IF THE KEY PRESSED IS E OR e switch(ch) { case 'e': case 'E': { // CALL THE FUNCTION THAT WILL BE FOR EXIT zoomin(); } reset: case 'R': case 'r': { // CALL THE RESET QUEUE FUNCTION hidequeueinfo(); // CALL THE PROGRESSBAR slidebar(&rear,&front); // AGAIN DRAW THE QUEUE drawq(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } queueinfo: case 'A' : case 'a': { // CALL THE FUNCTION TO GIVE INFORMATION ABOUT QUEUE hidequeueinfo(); showqueuesize(); goto m; } delet: case 'D': case 'd': { // CALL THE DELETE QUEUE OPERATIONS hidequeueinfo(); deleteq(&front); // CHECK IF QUEUE IS EMPTY, IF SO PRINT THE MESSAGE if(rear==-1 || front==5 ||rear<front) { // CLEAR THE INFO, THERE IN INFORMATION PART hidequeueinfo(); // DISPLAY THE TEXT IN THE INFORMATION PART outtextxy(200,430,"Queue is empty, you can't delete"); } else { front=front+1; moveptrs(&rear,&front); } goto m; } ins: case 'I': case 'i': { // HERE IS THE OPERATIONS FOR INSERTING AN ELEMENT hidequeueinfo(); if(rear==4) { hidequeueinfo(); outtextxy(200,430,"Queue is full, you can't insert"); goto m; } // SHOWS THE NUMBERS AND CANCEL BUTTON shownumbers(20,430,60,470); // CHECK FOR WHAT KEY PRESSED n: while(j==0) { if (kbhit()) { ch1=getche(); if(front==-1) { front=front+1; } switch(ch1) { cancel: case 'C': case 'c': { hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } zero: case '0': { insertq(&rear,'0'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } one: case '1': { insertq(&rear,'1'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } two: case '2': { insertq(&rear,'2'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } three: case '3': { insertq(&rear,'3'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } four: case '4': { insertq(&rear,'4'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } five: case '5': { insertq(&rear,'5'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } six: case '6': { insertq(&rear,'6'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } seven: case '7': { insertq(&rear,'7'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } eight: case '8': { insertq(&rear,'8'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } nine: case '9': { insertq(&rear,'9'); rear=rear+1; moveptrs(&rear,&front); hidequeueinfo(); restrictmouseptr(1,57,maxx-1,maxy-1); goto m; } default : hidequeueinfo(); outtextxy(200,430,"Invalid Key Pressed ! Press a valid key"); delay(550); hidequeueinfo(); shownumbers(20,430,60,470); goto n; } } else { //write code here to press the 0-----9 and cancel getmousepos(&button,&x,&y); if((button & 1)==1) { if(front==-1) { front=front+1; } } if( (x>500 && x<getmaxx()-10 && y>445 && y<470) && (button & 1)==1) { goto cancel; } if( (x>20 && x<60 && y>430 && y<470) && (button & 1)==1) { goto zero; } if( (x>60 && x<100 && y>430 && y<470) && (button & 1)==1) { goto one; } if( (x>100 && x<140 && y>430 && y<470) && (button & 1)==1) { goto two; } if( (x>140 && x<180 && y>430 && y<470) && (button & 1)==1) { goto three; } if( (x>180 && x<220 && y>430 && y<470) && (button & 1)==1) { goto four; } if( (x>220 && x<260 && y>430 && y<470) && (button & 1)==1) { goto five; } if( (x>260 && x<300 && y>430 && y<470) && (button & 1)==1) { goto six; } if( (x>300 && x<340 && y>430 && y<470) && (button & 1)==1) { goto seven; } if( (x>340 && x<380 && y>430 && y<470) && (button & 1)==1) { goto eight; } if( (x>380 && x<420 && y>430 && y<470) && (button & 1)==1) { goto nine; } } } } default : hidequeueinfo(); outtextxy(220,420,"Please Press a Valid Key"); goto m; } } // ELSE CONDITION FOR THE IF AFTER THE FIRST WHILE else { getmousepos(&button,&x,&y); if( (x>50 && x<200 && y<370 && y>350) && (button & 1)==1) { //exit button click zoomin(); } if( (x>50 && x<200 && y>150 && y<170) && (button & 1)==1) { //clicked the queueinfo button goto queueinfo; } if( (x>50 && x<200 && y>200 && y<220) && (button & 1)==1) { //clicked the insert button goto ins; } if( (x>50 && x<200 && y>250 && y<270) && (button & 1)==1) { //clicked the delete button delay(500); goto delet; } if( (x>50 && x<200 && y>300 && y<320) && (button & 1)==1) { //clicked the reset button goto reset; } } } getche(); }
asmlinkage long sys_sock_tcp_recv_k(unsigned long sockid, unsigned char *buffer, unsigned long size) { int message_size = 0; int index; int count; unsigned long dport = 0x0 ; unsigned long dsockid = 0xFFFF0000 ; unsigned long dlength; unsigned char *data_to_process; int ret; unsigned long buffer_bytes = 0; unsigned long flag_copied_buffer = 0; //spark_print("\nsys_sock_tcp_recv_k\n"); for(index=0; index<MAX_OPEN_PORTS; index++) if(active_ports[index].sock_id == sockid) break; /* No one listening on this port. Nothing to return */ if(index==MAX_OPEN_PORTS) return ERROR_NO_PORT_LISTENING; /* else : see what u can get from comm partition : see what u have enqueued in the buffer for this port index now holds the pointer to the port-information of the port */ //spark_print("Query SockID\t"); //spark_printLong(sockid); //spark_print("Listening Port\t"); //spark_printLong(active_ports[index].sock_id); /* IPC message comes with 16 byte header:callid, port, length, sockid */ message_size = sys_receiveMQ_k(SOCKET_TCP_RECV_CHANNEL1, tcp_recv_data, size + 16); //spark_print("\n message_size"); //spark_printLong(message_size); if(message_size != 0) { if(message_size != (size + 16)) message_size = sys_receiveMQ_k(SOCKET_TCP_RECV_CHANNEL1, tcp_recv_data, message_size); data_to_process = tcp_recv_data; while(message_size != 0) { //spark_print("\nIPC message_size"); //spark_printLong(message_size); dport = *(unsigned long *)(data_to_process + 4); dsockid = *(unsigned long *)(data_to_process + 12); //spark_print("Destination Port\t"); //spark_printLong(dport); //spark_print("Destination Socket id\t"); //spark_printLong(dsockid); //spark_print("Queried Port_Sockid\t"); //spark_printLong(sockid); dlength = *(unsigned long *)(data_to_process + 8); //spark_print("Destination Length\t"); //spark_printLong(dlength); if((dport == sockid) || (dsockid == sockid)) { ////spark_print("TCP DATA FOR GIVEN PORT : YES : NEW\n"); memcpy(buffer, &(data_to_process[16]), dlength); #if 0 spark_print("\nData\n"); for(count=0; count<dlength; count++) spark_printLong(buffer[count]); #endif flag_copied_buffer = 1; buffer_bytes = dlength; } else { /* Store in buffer for appropriate buffer */ ////spark_print("TCP DATA FOR GIVEN PORT : NO\n"); ////spark_print("TCP DATA FOR SOME OTHER PORT : YES\n"); /* If u have some old packets in buffer give them to app layer */ if(!isempty(&(active_ports[index].port_buffer_mon))) { ////spark_print("OLD PACKET FOUND FOR THIS PORT : YES\n"); ret = removeq(&(active_ports[index].port_buffer_mon), buffer); size = active_ports[index].length[ret]; active_ports[index].length[ret] = 0; flag_copied_buffer = 1; #if 0 spark_print("\nData\n"); for(count=0; count<size; count++) spark_printLong(buffer[count]); #endif } else { ////spark_print("OLD PACKET FOUND FOR THIS PORT : NO\n"); size = 0; } /* enqueue the packet in the buffer of target port */ for(index=0; index<MAX_OPEN_PORTS; index++) if((active_ports[index].sock_id == dport) || (active_ports[index].sock_id == dsockid)) break; //spark_print("Enqueuing packet for \t"); //spark_printLong(active_ports[index].sock_id); /* No one listening on this port. Discard the packet */ if(index==MAX_OPEN_PORTS) { //spark_print("Packet for client port may be\t"); //spark_printLong(dport); spark_print("\n*********Discarding as of now********\n"); buffer_bytes = flag_copied_buffer?buffer_bytes:0; } else { ret = insertq(&(active_ports[index].port_buffer_mon), &(data_to_process[16]), dlength); //spark_print("index =\t"); //spark_printLong(index); //spark_print("ret =\t"); //spark_printLong(ret); active_ports[index].length[ret] = dlength; //spark_print("active_ports[index].length[ret] =\t"); //spark_printLong(active_ports[index].length[ret]); buffer_bytes = flag_copied_buffer?size:0; } } data_to_process += (16 + dlength); message_size -= (16 + dlength); } } else { //spark_print("index =\t"); //spark_printLong(index); /* If u have some old packets in buffer give them to app layer */ if(!isempty(&(active_ports[index].port_buffer_mon))) { ////spark_print("TCP DATA FOR GIVEN PORT : YES : OLD\n"); ret = removeq(&(active_ports[index].port_buffer_mon), buffer); size = active_ports[index].length[ret]; #if 0 spark_print("\nData\n"); for(count=0; count<size; count++) spark_printLong(buffer[count]); #endif //spark_print("ret =\t"); //spark_printLong(ret); //spark_print("active_ports[index].length[ret] =\t"); //spark_printLong(active_ports[index].length[ret]); active_ports[index].length[ret] = 0; return size; } else { ////spark_print("TCP DATA FOR GIVEN PORT : NO\n"); return 0; } } return buffer_bytes; }