so xd

RMAG news

main

#include <iostream>
#include “so.hpp”

int main(){
int opcion;

/*
do {

cout << “MENU” << endl;
cout << “1. Entrada de datos” << endl;
cout << “2. Calcular FIFO” << endl;
cout << “3. Calcular SJF” << endl;
cout << “4. Calcular prioridad” << endl;
cout << “5. Calcular Round-Robin” << endl;
cout << “6. Salir” << endl;
cout << “Ingrese su opcion: “;
cin >> opcion;

system(“cls”);
switch (opcion) {
case 1:
agregarProceso();
imprimirProcesos();
break;
case 2:
calcularFIFO();
break;
case 3:
calcularSJF();
break;
case 5:
float quantum;
cout<<“Ingrese el tiempo quantum: “;
cin>>quantum;
roundRobin(quantum);
break;
case 4:
cout<<“INGRESE QUANTUM: “<<endl;
cin>>quantum;
calcularPrioridad(quantum);
break;
case 6:
cout << “Saliendo del programa.” << endl;
break;
default:
cout << “Opcion invalida.” << endl;
break;
}
} while (opcion != 6);

*/

process.addProcess();

return 0;
}

so.cpp

#include “so.hpp”

process::node::node(char i, int t, int q) {
_id = i;
_time = t;
_priority = q;
_next = nullptr;
}

process::process(int c){

n = c;
s = 0;
head = nullptr;
tail = nullptr;
}

process::~process(){

while(head != nullptr) {

node *p = head;
head = head -> next();
delete p;
}
}

void process::push(char i, int t, int q){

assert(!full());
node *p = new node(i, t, q);
if(empty()) {
head = p;
tail = p;
}else{
tail -> next(p);
tail = p;
}
s++;
}

int process::pop(){

assert(!empty());
char i = head -> id();
int t = head -> tme();
int q = head -> prty();

node *p = head;
head = p -> next();
delete p;
s–;
return x;
}

void process::print(){

node *p = head;
std::cout<<“[ “;
while(p != nullptr){
std::cout << p -> data() << ” “;
p = p -> next();
}
std::cout << “]” << std::endl;
}

void process::addProcess() {
int n;
cout<<“Ingrese el número total de procesos: “;
cin>>n;

for(int i = 0; i < n ; i++){
node *p = new node();
cout << “ID: “;
cin >> p->id;
cout << “Tiempo: “;
cin >> p->tme;
cout << “Prioridad: “;
cin >> p->prty;
if (empty()) {
head = p;
tail = p;
}else{
tail -> next(p);
tail = p;
}
s++;
cout << “Proceso agregado.” << endl;
}
}

so.hpp

#ifndef so_hpp
#define so_hpp

#include <iostream>
#include <assert.h>
using namespace std;

class process {

class node {

char _id;
int _time;
int _priority;
node *_next;

public:

node(char i, int t, int q);

char id() const { return _id; } //cual es el id
int tme() const { return _time; } //cual es el tiempo
int prty() const { return _priority; } //cual es la prioridad
node *next() const { return _next; } // cual es el siguiente apuntador
void next(node *p) { _next = p; } // cambia el siguiente ap
};

int n; // Capacity of process
int s; // Size of process

node *head; // First item in queue
node *tail; // Last item in queue

public:

process(int);
~process();

void push(int);
int pop(void);

int capacity() const { return n; }
int size() const { return s; }

bool full() const { return s==n; }
bool empty() const { return s==0; }

void print();

void addProcess();

};

#endif /* so_hpp */

Leave a Reply

Your email address will not be published. Required fields are marked *