viernes, 23 de noviembre de 2012

Cuantum en c++

#include <iostream.h>
#define limite 5
using namespace std;
void insertar(char datos[], int tiempo[], int numero){
     for(int i = 0; i < (numero); i++){
         cout<<"inserte el tiempo en el proceso ["<<datos[i]<<"]: ";
         cin>>tiempo[i];
     }
}
int quantum(int tiempo[],int numero){
    int resultado = 0;
    for(int i = 0; i < numero;++i)
      resultado += tiempo[i];
    resultado /= numero;
    return resultado;
}
void RoundRobin(char datos[], int tiempo[], int numero){
    insertar(datos,tiempo, numero);
    int Quantum = quantum(tiempo,numero);
    cout<<"El quantum es: "<< Quantum <<endl;
    int tiempoFinal = 0;
    float sumatoria = 0.0f;
    int metalera = 0;
    int i = 0;
    do{
      tiempo[i] != 0 ? tiempo[i] -= Quantum : ++i;
      if(tiempo[i] > 0)
          tiempoFinal += Quantum;
      else{
          tiempoFinal += Quantum+tiempo[i];
          sumatoria += tiempoFinal;
          cout << "el tiempo de proceso de " << datos[i] << ": "
          << tiempoFinal << endl;
          metalera++;
      }
      i < (numero - 1) ? i++ : i = 0;
    }while(metalera < numero);
    sumatoria /= numero;
    cout << "Tiempo promedio de los procesos es: "
    << sumatoria << endl;
}

int main(){
    char datos[limite] = {'a','b','c','d','e'};
    int tiempo[limite];
    RoundRobin(datos,tiempo,limite);
    cin.get();
    cin.get();
    return 0;
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication3;
import java.io.*;
/**
 *
 * @author AHMED
 */
public class JavaApplication3 {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader teclado=new BufferedReader(new InputStreamReader(System.in));
        int x[]=new int [100];
        int y[]=new int [100];
        int c[]=new int [100];
        int b[] = new int[100];
        int a[] = new int[100];
        int n,sum=0;
       
        float h,sum2=0,con=0;;
      
        System.out.println("  ALGORITMO   FCFS:  ");
        System.out.println("INGRESE CANTIDAD DE PROCESOS:  ");
        n=Integer.parseInt(teclado.readLine());

        for (int i=1;i<=5;i++)
        {
           
            System.out.print("INGRESE DURACION DEL PROCESO " + (i) + " : ");
                a[i] = Integer.parseInt(teclado.readLine());
                System.out.print("INGRESE TIEMPO DE LLEGADA DEL PROCESO " + (i) + " : ");
                b[i]= Integer.parseInt(teclado.readLine());
       
           
        sum=sum+x[i];
        y[i]=sum;
        }
        System.out.println("procesos ingresados");
       
        for (int i=1;i<=n;i++){
            c[i]=x[i];
        }
        for (int i=1;i<=n;i++){
          
           System.out.println("PROCESO"+"["+(i)+"]"+"-->"+a[i]+b[i]);
        }
        System.out.println("TIEMPO DE ESPERA");
      
           for (int i=0;i<n;i++){
                      
            System.out.println("PROCESO "+(i+1)+" :");
      
            System.out.println(y[i]);
           
            sum2=sum2+y[i];
            con=con+1;
           
            }
           System.out.println("TIEMPO DE RETORNO");
           for (int i=1;i<=n;i++){
                    
            System.out.println("PROCESO"+(i)+" :");
              
            System.out.println(y[i]);
            }
          
           h=sum2/con;
            System.out.println("TIEMPO MEDIO DE ESPERA ES :: "+(h));
           
    }
    }