zoukankan      html  css  js  c++  java
  • 实验二——模拟在CPU中的进程调度(初稿)

    一、        实验目的

    通过本实验可以加深对有关进程控制块、进程队列的概念的进一步理解。

    二、        实验内容和要求

         1.进程PCB的结构体定义

         2.定义结构体

         3.输入进程序列

         4.排序(按到位时间)

         5.输出进程运行的结果

    三、        实验代码及结果测试

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 #define wait 0
     5 #define run 1
     6 #define max 100
     7  
     8 typedef struct pcb{
     9     char name[max];
    10     int cputime;
    11     char state;
    12 }pcb;
    13 
    14 void input(pcb data[],int count);
    15 
    16 main(){
    17     pcb data[max];
    18     int count;
    19     printf("input the data number:");
    20     scanf("%d",&count);
    21     input(data,count);
    22     return 0;
    23 }
    24 
    25 void input(pcb data[],int count){
    26     int i;
    27     for(i=0;i<count;i++){
    28         printf("input the %d name:
    ",i+1);
    29         scanf("%s",&data[i].name);        
    30         printf("input the %d time:
    ",i+1);
    31         scanf("%d",&data[i].cputime);
    32     }
    33     for(i=0;i<count;i++){
    34         data[i].state=wait;
    35     }
    36     printf("the data are:
    ");
    37     printf("   name     usetime     state
    ");
    38     for(i=0;i<count;i++){
    39         printf("%10s %10d %5d
    ",data[i].name,data[i].cputime,data[i].state);
    40     }
    41 }

    实验总结:

    vc不是很好用,循环体中修改了的地方要保存多次才会取消error的提示;

    用数组的方法编写需要预先留下较大的内存;

  • 相关阅读:
    过河卒 题解
    You Are the One solution
    D
    Find a way solution
    A
    入门训练 Fibonacci数列
    求平均成绩 题解
    海选女主角 题解
    子集生成和组合问题
    log4j
  • 原文地址:https://www.cnblogs.com/murasame/p/5448277.html
Copyright © 2011-2022 走看看