Advertisement
Guest User

Untitled

a guest
May 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct Fila{
  6. int fim;
  7. int ciclo;
  8. int CicloSoma;
  9. int PID;
  10. int Ativ;
  11. char Proc[30];
  12. } Lista;
  13. Lista List[8];
  14.  
  15. int i = 0;
  16. void Operacoes();
  17. void Escalonar();
  18. void Creditos();
  19. void CriaProc();
  20. void DelProc();
  21. void AlterProc();
  22. void ListaProc();
  23.  
  24. int main(){
  25. int num;
  26. while (num != 0){
  27. system("clear");
  28. printf("\n---------- Tarefa Zem Processos ---------\n\n");
  29. printf(" 1 - Operacoes na Tabela de Processos \n 2 - Escalonar Processos \n 3 - Créditos \n 0 - Encerrar \n");
  30. scanf("%d",&num);
  31. fflush(stdin);
  32. if (num == 0) break;
  33. else if (num == 1) Operacoes();
  34. else if (num == 2) Escalonar();
  35. else if (num == 3) Creditos();
  36. else printf("AVISO : Comando Invalido");
  37. }
  38. }
  39.  
  40. void Operacoes(){
  41. int op;
  42. while (op != 0 ){
  43. system("clear");
  44. printf("\n---------- Operacoes na Tabela de Processos---------\n\n");
  45. printf(" 1 - Criar Processo \n 2 - Remover Processo \n 3 - Alterar Processo \n 4 - Listar Tabela \n 0 - Retornar ao menu Anterior \n");
  46. scanf("%d",&op);
  47. fflush(stdin);
  48. if (op == 0) break;
  49. else if (op == 1) CriaProc();
  50. else if (op == 2) DelProc();
  51. else if (op == 3) AlterProc();
  52. else if (op == 4) ListaProc();
  53. else printf("AVISO : Comando Invalido");
  54. }
  55. }
  56.  
  57. void Escalonar(){
  58. int fim = 0, atual = 1;
  59. if (i!= 0){
  60. while(atual != 8){
  61. if (List[atual].Ativ == 1)
  62. List[atual].CicloSoma = List[atual].ciclo;
  63.  
  64. atual ++;
  65. }
  66. atual = 1;
  67. while(fim != i){
  68. if (List[atual].Ativ == 1){
  69. if (List[atual].CicloSoma != 0){
  70. List[atual].CicloSoma --;
  71. atual ++;
  72. }
  73. else {
  74. if (List[atual].fim == 0){
  75. fim ++;
  76. List[atual].fim = fim;
  77. }
  78. else atual ++;
  79. }
  80. }
  81. else atual ++;
  82. if (atual == 8) atual = 1;
  83. }
  84. ListaProc();
  85. }else{
  86. printf("Não Foi encontrado nenhum registro\n");
  87. getchar();
  88. getchar();
  89. }
  90. }
  91.  
  92. void Creditos(){
  93. system("clear");
  94. printf("\n----------------------------------Créditos----------------------------------\n");
  95. printf("Erick Domingos Modenez - Engenharia da Computação - 201710299\n");
  96. printf("Vinicios Nery Helal - Engenharia da Computação - 201710280\n");
  97. printf("Patricia M. Gambaro - Engenharia da Computação - \n");
  98. printf("Nathan de Oliveira Fonseca - Engenharia da Computação - 201710598\n");
  99. getchar();
  100. getchar();
  101. }
  102.  
  103. void CriaProc(){
  104. i++;
  105. int num = 1;
  106. system("clear");
  107. if (i < 8){
  108. while (num != 8){
  109. if(List[num].Ativ == 0){
  110. printf("Digite o nome:\n");
  111. fflush(stdin);
  112. getchar();
  113. fgets(List[num].Proc,30,stdin);
  114. printf("Digite o numero de Ciclos:\n");
  115. scanf("%d",&List[num].ciclo);
  116. fflush(stdin);
  117. List[num].PID = 100 + num;
  118. List[num].Ativ = 1;
  119. break;
  120. }
  121. else num ++;
  122. }
  123. }else printf("Limite Atingido");
  124. getchar();
  125. }
  126.  
  127. void DelProc(){
  128. int deleta, proc = 0, acha = 0;
  129. system("clear");
  130. printf("Digite o PID que deseja Deletar:\n");
  131. scanf("%d",&deleta);
  132. while (proc != 8){
  133. proc ++;
  134. if (List[proc].PID == deleta){
  135. List[proc].Ativ = 0;
  136. acha = 1;
  137. i --;
  138. }
  139. }
  140. if (acha == 0)
  141. printf("Não Foi encontrado nenhum registro\n");
  142. getchar();
  143. getchar();
  144. }
  145.  
  146. void AlterProc(){
  147. int alt, proc = 0, acha;
  148. system("clear");
  149. printf("Digite o PID que deseja Alterar:\n");
  150. scanf("%d",&alt);
  151. while (proc != 8){
  152. proc ++;
  153. if (List[proc].PID == alt){
  154. printf("Digite o nome:\n");
  155. fflush(stdin);
  156. getchar();
  157. fgets(List[proc].Proc,30,stdin);
  158. printf("Digite o numero de Ciclos:\n");
  159. scanf("%d",&List[proc].ciclo);
  160. fflush(stdin);
  161. acha = 1;
  162. }
  163. }
  164. if (acha == 0)
  165. printf("Não Foi encontrado nenhum registro\n");
  166. getchar();
  167. getchar();
  168. }
  169.  
  170. void ListaProc(){
  171. int lis = 0;
  172. system("clear");
  173. if (i != 0){
  174. printf("--------------------------------------------------------------");
  175. while (lis < 8){
  176. if (List[lis].Ativ == 1){
  177. printf("\nNome -> %s",List[lis].Proc);
  178. printf("Ciclos -> %d\n",List[lis].ciclo);
  179. printf("PID -> %d\n",List[lis].PID);
  180. if (List[lis].fim != 0) {
  181. printf("Posicao -> %d°\n",List[lis].fim);
  182. List[lis].fim = 0;
  183. }
  184. printf("--------------------------------------------------------------");
  185. lis ++;
  186. }
  187. else lis ++;
  188. }
  189. }
  190. else printf("Nao foi encontrado nenhum registro");
  191. printf("\n");
  192. getchar();
  193. getchar();
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement