Untitled
unknown
plain_text
2 years ago
6.7 kB
14
Indexable
//queuing system #include<stdio.h> #include<conio.h> int main() { float l,m,e; float p,et; printf("Enter Inter arrival time of customers per hours:"); scanf("%f",&l); printf("\nEnter The average time spent by cutomers per hour:"); scanf("%f",&m); p=1-l/m; e=l/(m-l); et=1/(m-l); et=et*60; printf("\nThe probability That a customer wont't have to wait at counter:%f ",p); printf("\n\nExpected number of customer: %f",e); printf("\n\nExpected time to be spent in bank: %f minutes",et); getch(); return 0; } ---------------------------------------------------------------------------------------- //poission distribution #include<stdio.h> #include<conio.h> #include<math.h> int main() { float l,m,p[16],pr,x,a,i; int j; printf("Enter arrival rate per hours:"); scanf("%f",&l); for(x=0;x<16;x++) { a=1; for(i=1;i<=x;i++) { a=a*i; } pr= (pow(2.71,-l)*pow(l,x))/a; printf("\nP(X=%f) = %f\n",x,pr); } getch(); return 0; } //Write a C program to generate Poisson distribution for x = 0,1,2, …. 15. #include<stdio.h> #include<conio.h> #include<math.h> int main() { float l,m,p[16] ,pr ,a, i; int j, x; printf("Enter arrival rate perhours:"); scanf("%f",&l); for(x=0;x<16;x++) { a=1; for(i=1;i<=x;i++) { a=a*i; } pr=(pow(2.71,-l)*pow(l,x))/a; printf("P(X=%d) = %f\n",x,pr); } getch(); return 0; } ------------------------------------------------------------------------------------------ //markov chain #include<stdio.h> #include<conio.h> int main() { float transMat[2][2]={0.9,0.1,0.5,0.5},vect[1][2]={1,0},result[1][2]; int i,j,k; for(i=0;i<2;i++) { for(j=0;j<2;j++) { result[i][j]=0; for(k=0;k<2;k++) { result[i][j]+=vect[i][k]*transMat[k][j]; } } } printf("\nWeather of next day using markov chain\n\n"); for(i=0;i<1;i++) { for(j=0;j<2;j++) { printf("%f\t",result[i][j]); } printf("\n"); } getch(); return 0; } ----------------------------------------------------------------------------------------- //random no generation(linearcongurance) #include<stdio.h> #include<conio.h> #define SIZE 100 int main() { int x[SIZE],i; int m=100,a=5,c=13; x[0]=11; for(i=0;i<100;i++) { x[i+1]=(a*x[i]+c)%m; } printf("\nGeneration of random numbers using linear congruential method\n"); for(i=0;i<100;i++) { printf("%d\t",x[i]); } getch(); return 0; } //Write a program in C to generate 100 random numbers using Multiplicative Congruential Method where X0 = 13, m = 1000, a = 15, and c = 7. #include<stdio.h> #include<conio.h> #define SIZE 100 int main() { int x[SIZE],i; int m=1000,a=15,c=7; x[0]=13; for(i=0;i<100;i++) { x[i+1]=(a*x[i])%m; } printf("\nGeneration of random numbers using the linear congruential method"); for(i=0;i<100;i++) { printf("%d\t",x[i]); } getch(); return 0; } ------------------------------------------------------------------------------------------------------------------- //GPSS Q.1. Microprocessor arrive at the test station of a manufacturing plant every 1 to 5 minutes and the testing time per microphone was found to be 2 to 8 minutes. The service is a queue whenever the facility is busy. Assuming that the inter arrival time and service times are uniformly distributed. Simulate the processing of 1000 microprocessor at the test station. SIMULATE GENERATE 3, 2 QUEUE 1, 1 SEIZE TST DEPART 1, 1 ADVANCE 5, 3 RELEASE TST TERMINATE 1 START 1000 Q.2.The shop contains 1 barber and 1 barber’s chair opens for 8 hours in 1 day. Customers arrive on average every 18 minutes with arrival time varying between 12 and 24 minutes. If the barber is busy, the customer will wait in queue. Once the barber is free the next customer will have a haircut. Each haircut taken between 12 and 18 minutes with average 15 minutes. Once the haircut is done the customer will leave the shop. SIMULATE GENERATE 18, 6 QUEUE 2 SEIZE 3 DEPART 2 ADVANCE 15,3 RELEASE 3 TERMINATE 0 GENERATE 480 TERMINATE 1 START 1 --------------------------------------------------------------------------------- //ks test #include<iostream> #include<conio.h> #include<iomanip> using namespace std; class KS { private: float numbers[20]; float D,tabulatedD; float Dplusmax,Dminusmax; float Dplus[20],Dminus[20]; float ratio[20],ratiominus[20]; int i,j,n; public: void getdata() //to get the random numbers { cout<<"How many numbers?:"<<endl; cin>>n; cout<<"Enter "<<n<<" numbers"<<endl; for(i=0;i<n;i++) { cout<<"Enter "<<i+1<<" number:"<<endl; cin>>numbers[i]; } } float BubbleSort() // arrange the number in increasing order { int i,j; float temp; for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(numbers[j]>numbers[j+1]) { temp=numbers[j]; numbers[j]=numbers[j+1]; numbers[j+1]=temp; } } } cout<<"The numbers in ascending order is:"<<endl; for(i=0;i<n;i++) { cout<<setprecision(2)<<numbers[i]<<" "; } } void calculate() // find D+, D- { for(i=0;i<n;i++) { int j; j=i+1; ratio[i]=(float)j/n; ratiominus[i]=(float)i/n; Dplus[i]=ratio[i]-numbers[i]; Dminus[i]=numbers[i]-ratiominus[i]; } } void display() // display the tabulated format and find D { cout<<endl; cout<<endl; cout<<setw(10)<<"i"; for(i=1;i<=n;i++) { cout<<setw(10)<<i; } cout<<endl; cout<<setw(10)<<"R(i)"; for(i=0;i<n;i++) { cout<<setw(10)<<numbers[i]; } cout<<endl; cout<<setw(10)<<"i/n"; for(i=0;i<n;i++) { cout<<setw(10)<<setprecision(2)<<ratio[i]; } cout<<endl; cout<<setw(10)<<"D+"; for(i=0;i<n;i++) { cout<<setw(10)<<setprecision(2)<<Dplus[i]; } cout<<endl; cout<<setw(10)<<"D-"; for(i=0;i<n;i++) { cout<<setw(10)<<setprecision(2)<<Dminus[i]; } cout<<endl; Dplusmax=Dplus[0]; Dminusmax=Dminus[0]; for(i=1;i<n;i++) { if(Dplus[i]>Dplusmax) { Dplusmax=Dplus[i]; } if(Dminus[i]>Dminusmax) { Dminusmax=Dminus[i]; } } cout<<"D+ max: "<<Dplusmax<<endl; cout<<"D- max: "<<Dminusmax<<endl; cout<<"D =max("<<Dplusmax<<", "<<Dminusmax<<") ="; if(Dplusmax>Dminusmax) { D=Dplusmax; } else { D=Dminusmax; } cout<<D; cout<<endl; } void conclusion() // asking tabulated D and comparing it with D(calculated) { cout<<"Enter the tabulated value:"<<endl; cin>>tabulatedD; if(D<tabulatedD) { cout<<"The test is accepted."<<endl; } else { cout<<"The test is rejected."<<endl; } } }; int main() //main function { KS ks1; //object of KS class ks1.getdata(); //function calls ks1.BubbleSort(); ks1.calculate(); ks1.display(); ks1.conclusion(); getch(); return(0); }
Editor is loading...