6 Replies - 752 Views - Last Post: 04 January 2013 - 10:13 AM Rate Topic: -----

#1 SoOona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 13

Problem in disck scheduling algorithms

Posted 04 January 2013 - 08:46 AM

helo,
I cloudn't make my program work in C++; it is even make my system crash when i was try to solve the problem ,

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
//#include<time.h>
int request[100],st,cylinders,n;
//time_t t;
void random(void )
{
   
    for(int i=0;i<n;i++)
    {
       //srand(request[(rand()%n)]);
       request[i]=rand()%cylinders+1;
    }  
}   

void display(void )
{
     cout<<"\nThe requests are : \n";
     for(int i=0;i<n;i++)
        cout<<" "<<request[i]<<" ";
}
    
           
   
int main()
{
   int choice;
   void fcfs(void );
   void scan(void );
   cout<<"\nEnter no. of cylinders in hard disk and starting cylinder : ";
   cin>>cylinders>>st;
  
  
   cout<<"\npress 0 to generate random disk requests and any other no. to give your own requests : ";
   cin>>choice;
   if(choice==0)
   {
       cout<<"\nEnter no. of requests to generate randomly : ";
       cin>>n;
       random();
   }
   else
   {
       cout<<"\nEnter the cylinders requested (0 to break): \n";
       while(1)
       {
          cin>>request[n++];
          if(request[n-1]==0||n==100)
          {
              n--;
              break;
            
          }  
        
       }      
   }
  
   cout<<"\nEnter the scheduling algo that you want to implement(0:FCFS,1:Scan) : ";               
   cin>>choice;
   switch(choice)
   {
      case 0:
           fcfs();
           break;     
      case 1:
           scan();
           break;   
      default:
         break;
   }
  
   getch();
   return 0;
}       
            
void fcfs(void )
{
     int total=0,i;              //no of cylinders traversed
     display();
     cout<<"\n\n The traversal is shown below : \n\n"<<st;
     for(i=0;i<n;i++)
     {
         cout<<"-->"<<request[i];
         total=total+abs(request[i]-st);
         st=request[i];    
     }
     cout<<"\n\nNo. of cylinders traversed : "<<total;
}                      

void scan(void )
{
     int total=0,i,j,temp;
     display();
     for(i=0;i<n;i++)
        for(j=0;j<n-1-i;j++)
        {
            if(request[j]>request[j+1])
            {
               temp=request[j];
               request[j]=request[j+1];
               request[j+1]=temp;
            }
        }
     display();
    
     cout<<" \nThe traversal is shown below : \n\n"<<st;
    
     if(st<request[0])
     {
        for(i=0;i<n;i++)
        {
           cout<<"-->"<<request[i];
           total+=abs(request[i]-st);
           st=request[i];
        }
     }
     else
     {
        
         i=0;
         temp=0;
         while(st>request[i++])
            temp++;
         for(i=temp;i<n;i++)
         {
           
                   
          
               cout<<"-->"<<request[i];
               total+=abs(request[i]-st);
               st=request[i];
   
               if(i==n-1)
               {
                 
                  total=total+2*cylinders-request[i];
                  st=0;
                  i=0;
                  n=temp;
                  if(st!=cylinders)
                  {
                     cout<<"-->"<<cylinders;
                     cout<<"-->"<<1;
                  }
               }
          }     
                    
       }               
        
       cout<<"\nTotal cylinders traversed : "<<total; 
    
}             







I'll be thankfull if someone tell me the problem

This post has been edited by Skydiver: 04 January 2013 - 08:54 AM
Reason for edit:: Put code in code tags. Do it yourself in the future.


Is This A Good Question/Topic? 0
  • +

Replies To: Problem in disck scheduling algorithms

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,433
  • Joined: 25-December 09

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 09:28 AM

Your major problem is that you are using such an old outdated compiler but the problem with your code is that you are trying to create your own random() function, there is already a standard function with that name. Rename your random() function and your program may work. But I suggest you find an new compiler that supports the current standards.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 SoOona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 13

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 10:02 AM

Oh great thank u So much,
What type of compiler u suggest I need????
if u could give me an example of code work as my code that will be great,
i realy want to understand how disck scheduling work ,

Is it same as consumer and producer or it is a different ???
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,461
  • Joined: 05-May 12

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 10:04 AM

To learn how disk scheduling works, you don't even need to write a program. All you need a pencil and paper, and some dice.

As for a compiler, try Visual Studio Express or Code::Blocks.
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,433
  • Joined: 25-December 09

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 10:06 AM

Since you seem to be familiar with Dev-C++ you may want to consider Orwell-dev-c++ or Code::Blocks or Visual C++.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 SoOona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 13

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 10:08 AM

I rename it but it sitll not work >>>!
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,433
  • Joined: 25-December 09

Re: Problem in disck scheduling algorithms

Posted 04 January 2013 - 10:13 AM

Just saying it doesn't work doesn't tell us anything.

Did you change the name of the function everywhere in your code, including the function calls?

Post your current code and state exactly why the program isn't working.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1