Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Fila{
- int fim;
- int ciclo;
- int CicloSoma;
- int PID;
- int Ativ;
- char Proc[30];
- } Lista;
- Lista List[8];
- int i = 0;
- void Operacoes();
- void Escalonar();
- void Creditos();
- void CriaProc();
- void DelProc();
- void AlterProc();
- void ListaProc();
- int main(){
- int num;
- while (num != 0){
- system("clear");
- printf("\n---------- Tarefa Zem Processos ---------\n\n");
- printf(" 1 - Operacoes na Tabela de Processos \n 2 - Escalonar Processos \n 3 - Créditos \n 0 - Encerrar \n");
- scanf("%d",&num);
- fflush(stdin);
- if (num == 0) break;
- else if (num == 1) Operacoes();
- else if (num == 2) Escalonar();
- else if (num == 3) Creditos();
- else printf("AVISO : Comando Invalido");
- }
- }
- void Operacoes(){
- int op;
- while (op != 0 ){
- system("clear");
- printf("\n---------- Operacoes na Tabela de Processos---------\n\n");
- printf(" 1 - Criar Processo \n 2 - Remover Processo \n 3 - Alterar Processo \n 4 - Listar Tabela \n 0 - Retornar ao menu Anterior \n");
- scanf("%d",&op);
- fflush(stdin);
- if (op == 0) break;
- else if (op == 1) CriaProc();
- else if (op == 2) DelProc();
- else if (op == 3) AlterProc();
- else if (op == 4) ListaProc();
- else printf("AVISO : Comando Invalido");
- }
- }
- void Escalonar(){
- int fim = 0, atual = 1;
- if (i!= 0){
- while(atual != 8){
- if (List[atual].Ativ == 1)
- List[atual].CicloSoma = List[atual].ciclo;
- atual ++;
- }
- atual = 1;
- while(fim != i){
- if (List[atual].Ativ == 1){
- if (List[atual].CicloSoma != 0){
- List[atual].CicloSoma --;
- atual ++;
- }
- else {
- if (List[atual].fim == 0){
- fim ++;
- List[atual].fim = fim;
- }
- else atual ++;
- }
- }
- else atual ++;
- if (atual == 8) atual = 1;
- }
- ListaProc();
- }else{
- printf("Não Foi encontrado nenhum registro\n");
- getchar();
- getchar();
- }
- }
- void Creditos(){
- system("clear");
- printf("\n----------------------------------Créditos----------------------------------\n");
- printf("Erick Domingos Modenez - Engenharia da Computação - 201710299\n");
- printf("Vinicios Nery Helal - Engenharia da Computação - 201710280\n");
- printf("Patricia M. Gambaro - Engenharia da Computação - \n");
- printf("Nathan de Oliveira Fonseca - Engenharia da Computação - 201710598\n");
- getchar();
- getchar();
- }
- void CriaProc(){
- i++;
- int num = 1;
- system("clear");
- if (i < 8){
- while (num != 8){
- if(List[num].Ativ == 0){
- printf("Digite o nome:\n");
- fflush(stdin);
- getchar();
- fgets(List[num].Proc,30,stdin);
- printf("Digite o numero de Ciclos:\n");
- scanf("%d",&List[num].ciclo);
- fflush(stdin);
- List[num].PID = 100 + num;
- List[num].Ativ = 1;
- break;
- }
- else num ++;
- }
- }else printf("Limite Atingido");
- getchar();
- }
- void DelProc(){
- int deleta, proc = 0, acha = 0;
- system("clear");
- printf("Digite o PID que deseja Deletar:\n");
- scanf("%d",&deleta);
- while (proc != 8){
- proc ++;
- if (List[proc].PID == deleta){
- List[proc].Ativ = 0;
- acha = 1;
- i --;
- }
- }
- if (acha == 0)
- printf("Não Foi encontrado nenhum registro\n");
- getchar();
- getchar();
- }
- void AlterProc(){
- int alt, proc = 0, acha;
- system("clear");
- printf("Digite o PID que deseja Alterar:\n");
- scanf("%d",&alt);
- while (proc != 8){
- proc ++;
- if (List[proc].PID == alt){
- printf("Digite o nome:\n");
- fflush(stdin);
- getchar();
- fgets(List[proc].Proc,30,stdin);
- printf("Digite o numero de Ciclos:\n");
- scanf("%d",&List[proc].ciclo);
- fflush(stdin);
- acha = 1;
- }
- }
- if (acha == 0)
- printf("Não Foi encontrado nenhum registro\n");
- getchar();
- getchar();
- }
- void ListaProc(){
- int lis = 0;
- system("clear");
- if (i != 0){
- printf("--------------------------------------------------------------");
- while (lis < 8){
- if (List[lis].Ativ == 1){
- printf("\nNome -> %s",List[lis].Proc);
- printf("Ciclos -> %d\n",List[lis].ciclo);
- printf("PID -> %d\n",List[lis].PID);
- if (List[lis].fim != 0) {
- printf("Posicao -> %d°\n",List[lis].fim);
- List[lis].fim = 0;
- }
- printf("--------------------------------------------------------------");
- lis ++;
- }
- else lis ++;
- }
- }
- else printf("Nao foi encontrado nenhum registro");
- printf("\n");
- getchar();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement