Advertisement
Guest User

Untitled

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 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 - 201710287 \n");
  98. printf("Nathan de Oliveira Fonseca - Engenharia da Computação - 201710598\n");
  99. getchar();
  100. getchar();
  101. }
  102.  
  103. void CriaProc(){
  104. int num = 1, acha = 0;
  105. system("clear");
  106. if (i < 8){
  107. while (num != 8){
  108. if(List[num].Ativ == 0){
  109. i++;
  110. acha=1;
  111. printf("Digite o nome:\n");
  112. fflush(stdin);
  113. getchar();
  114. fgets(List[num].Proc,30,stdin);
  115. printf("Digite o numero de Ciclos:\n");
  116. scanf("%d",&List[num].ciclo);
  117. fflush(stdin);
  118. List[num].PID = 100 + num;
  119. List[num].Ativ = 1;
  120. break;
  121. }
  122. else num ++;
  123. }
  124. }if (acha == 0) printf("Limite Atingido");
  125. getchar();
  126. }
  127.  
  128. void DelProc(){
  129. int deleta, proc = 0, acha = 0;
  130. system("clear");
  131. printf("Digite o PID que deseja Deletar:\n");
  132. scanf("%d",&deleta);
  133. while (proc != 8){
  134. proc ++;
  135. if (List[proc].PID == deleta){
  136. List[proc].Ativ = 0;
  137. acha = 1;
  138. i --;
  139. }
  140. }
  141. if (acha == 0)
  142. printf("Não Foi encontrado nenhum registro\n");
  143. getchar();
  144. getchar();
  145. }
  146.  
  147. void AlterProc(){
  148. int alt, proc = 0, acha = 0;
  149. system("clear");
  150. printf("Digite o PID que deseja Alterar:\n");
  151. scanf("%d",&alt);
  152. while (proc != 8){
  153. proc ++;
  154. if (List[proc].PID == alt){
  155. printf("Digite o nome:\n");
  156. fflush(stdin);
  157. getchar();
  158. fgets(List[proc].Proc,30,stdin);
  159. printf("Digite o numero de Ciclos:\n");
  160. scanf("%d",&List[proc].ciclo);
  161. fflush(stdin);
  162. acha = 1;
  163. }
  164. }
  165. if (acha == 0)
  166. printf("Não Foi encontrado nenhum registro\n");
  167. getchar();
  168. getchar();
  169. }
  170.  
  171. void ListaProc(){
  172. int lis = 0;
  173. system("clear");
  174. if (i != 0){
  175. printf("--------------------------------------------------------------");
  176. while (lis < 8){
  177. if (List[lis].Ativ == 1){
  178. printf("\nNome -> %s",List[lis].Proc);
  179. printf("Ciclos -> %d\n",List[lis].ciclo);
  180. printf("PID -> %d\n",List[lis].PID);
  181. if (List[lis].fim != 0) {
  182. printf("Posicao -> %d°\n",List[lis].fim);
  183. List[lis].fim = 0;
  184. }
  185. printf("--------------------------------------------------------------");
  186. lis ++;
  187. }
  188. else lis ++;
  189. }
  190. }
  191. else printf("Nao foi encontrado nenhum registro");
  192. printf("\n");
  193. getchar();
  194. getchar();
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement