Tuesday 20 December 2011

Program to find average waiting and turn over time after sorting array


#include<iostream>
using namespace std;
class avg
{
 int a[10];
float w,tt,s,t,n;
public:
void read();
void display();
void awt();
void att();
void sort();
};
void avg::read()
{
        cout<<"enter no of members at theatre counter \n";
        cin>>n;
        cout<<"enter number of tickets want to purchase \n";
        for(int i=0;i<n;i++)
        {
        cout<<"a["<<i<<"]=";
        cin>>a[i];
        }
}
void avg::sort()
{
int x;
cout<<"before sorting\n";
        for(int i=0;i<n;i++)
        cout<<"a["<<i<<"]="<<a[i]<<"\t";
        cout<<"after sorting\n";
        for(int j=0;j<n-1;j++)
        {
        for(int i=0;i<n-j-1;i++)
        {
                if(a[i]>a[i+1])
                {
                x=a[i];
                a[i]=a[i+1];
                a[i+1]=x;
                }
        }
}
for(int i=0;i<n;i++)
        cout<<"a["<<i<<"]="<<a[i];
}
void avg::awt()
{       s=0;t=0;
        for(int i=0;i<n-1;i++)
        {
                s=s+a[i];
                t=t+s;
        }
cout<<"sum of awt is="<<t<<"\n";
        w=t/n;
}
void avg::att()
{
        t=0;s=0;
        for(int i=0;i<n;i++)
        {
                t=t+a[i];
                s=s+t;
        }
cout<<"sum of att is="<<s<<"\n";

        tt=s/n;
}
void avg::display()
{
        cout<<"no of tickets each person will purchase \n";
        for(int i=0;i<n;i++)
        cout<<"a["<<i<<"]="<<a[i];
cout<<"average waiting time is"<<w<<"\n";
        cout<<"average turn over time is"<<tt<<"\n";
}
int main()
{
        avg ob;
        ob.read();
        ob.sort();
        ob.awt();
        ob.att();
        ob.display();
return 0;
}

No comments:

Post a Comment