Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Job Scheduling

Source Code:

#include<iostream.h>
#include<conio.h>

void job(int*,int*,int,int);
void main()
{clrscr();
 cout<<"Program created by Tarun Rawat Job Scheduling\n\n";


 int profit[20],dead[20],n,i,j,maxdead;


 cout<<"Enter number of element : ";
 cin>>n;
 cout<<"Enter profit in descending order: \n";
 for(i=0;i<n;i++)
 {cin>>profit[i];
 }
 cout<<"Enter deadline according to profit value typed above : \n";
 for(i=0;i<n;i++)
 {cin>>dead[i];
 }
 cout<<"Enter maximum deadline : ";
 cin>>maxdead;
 job(profit,dead,n,maxdead);
getch();
}

void job(int profit[],int dead[],int n,int maxdead)
{  int result[20],total=0,x=0;
   for(int i=0;i<maxdead;i++)
      {result[i]=0;
      }
 for( i=0;i<n;i++)
     {       if(result[dead[i]-1]==0)
          {result[dead[i]-1]=profit[i];
           total=total+profit[i];
          }
       else
         { for(int j=dead[i]-1;j>=0;j--)
          {if(result[j]==0)
             {result[j]=profit[i];
              total=total+profit[i];
             }
          }
          }

     }
 cout<<"Total profit is " <<total;
 cout<<"\nOutput array is : \n";
 for(i=0;i<maxdead;i++)
 {cout<<"At index "<<i+1<<" "<<result[i]<<"\n"; ///Tarun rawat
 }
}

No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)