【良心出品】第三讲 结构体习题
(完整版)结构体与联合体习题与参考答案

(完整版)结构体与联合体习题与参考答案第八章结构体与联合体选择题1、若程序中有以下的说明和定义:struct abc{ int x;char y; } 花括号后少了分号。
struct abc s1,s2;则会发生的情况是______。
A) 编译时错B) 程序将顺序编译、连接、执行C) 能顺序通过编译、连接、但不能执行D) 能顺序通过编译、但连接出错2、有以下程序段struct st{ int x; int *y;}*pt;int a[]={1,2};b[]={3,4};struct st c[2]={10,a,20,b};pt=c;以下选项中表达式的值为11的是A) *pt->y B) pt->x C) ++pt->x D) (pt++)->x3、有以下说明和定义语句struct student{ int age; char num[8];};struct student stu[3]={{20,"200401"},{21,"200402"},{19,"200403"}};struct student *p=stu;以下选项中引用结构体变量成员的表达式错误的是______。
A) (p++)->num B) p->num C) (*p).num D) stu[3].age4、设有如下枚举类型定义enum language{Basic=3,Assembly=6,Ada=100,COBOL,Fortran};枚举量Fortran的值为______。
A) 4 B) 7 C) 102 D) 1035、以下叙述中错误的是_________。
A)可以通过typedef增加新的类型B)可以用typedef将已存在的类型用一个新的名字来代表C)用typedef定义新的类型名后,原有类型名仍有效D)用typedef可以为各种类型起别名,但不能为变量起别名6、有以下程序段typedef struct NODE{ int num; struct NODE *next;} OLD;以下叙述中正确的是A)以上的说明形式非法B) NODE是一个结构体类型C) OLD是一个结构体类型D) OLD是一个结构体变量7、以下选项中不能正确把cl定义成结构体变量的是______。
(完整word版)数据结构复习题-第3章答案2014-6-16(word文档良心出品)

第3章栈和队列答案:一、选择题1-5 BCBCB 6-10BCCDD 11-15 BDBBD16-20CCBDB16题解释:一般只需修改队头指针,不过当队列里面只有一个结点时,需要同时修改队尾指针。
二、判断题1-5 ×√×√√6-10 √√√√×11-16√√√××√三、填空题1.栈顶、栈底2. 入栈、出栈3. 队列、先进先出4.栈5.队列6.先进先出7. (R-P+N) % N8. n-1 牺牲一个存储单元、设标记栈底、两栈顶指针相邻(即值之差的绝对值为1)1.没有、一2. 数据域、指针域3. 前驱4.前驱、后继5.前驱、后继6.头结点7.循环链表8. n-19. 栈后进先出10.SXSSXSXX 11.3,1,2 12.牺牲一个存储单元设标记 13.栈底两栈顶指针相邻(即值之差的绝对值为1)四、简答题(每小题5分,共10分)1.简述队列和栈这两种数据类型的相同点和差异处。
答:队列和栈都是操作受限的线性表,都属于线性表的逻辑结构。
区别在于,队列的插入是在队尾端进行,删除是在队头端进行;而栈的插入和删除都只能在栈顶端进行。
2.简述栈和线性表的差别。
答:栈是操作受限的线性表,栈的插入和删除操作都只能在栈顶端进行,因而相应的称为“入栈”和“出栈”。
3.说明线性表、栈与队列的异同点。
答:相同点:都是线性结构;不同点:队列和栈都是操作受限的线性表,队列的插入是在队尾端进行,删除是在队头端进行;而栈的插入和删除都只能在栈顶端进行,而线性表的插入、删除则不受限制,可以在任何位置进行。
4.链栈中为何不设置头结点?答:链栈不需要在头部附加头结点,因为栈都是在头部进行操作的,如果加了头结点,等于要对头结点之后的结点进行操作,反而使算法更复杂,所以只要有链表的头指针就可以了。
5.什么是循环队列?答:用常规意义下顺序存储结构的一维数组表示队列,由于队列的性质(队尾插入和队头删除),容易造成“假溢出”现象,即队尾已到达一维数组的最高下标,不能再插入,然而队中元素个数小于队列的长度(容量)。
数据结构第三章习题

第三章习题1.按图3.1(b)所示铁道(两侧铁道均为单向行驶道)进行车厢调度,回答:⑴如进站的车厢序列为123,则可能得到的出站车厢序列是什么?⑵如进站的车厢序列为123456,能否得到435612和135426的出站序列,并说明原因。
(即写出以“S”表示进栈、以“X”表示出栈的栈操作序列)。
2.设队列中有A、B、C、D、E这5个元素,其中队首元素为A。
如果对这个队列重复执行下列4步操作:(1)输出队首元素;(2)把队首元素值插入到队尾;(3)删除队首元素;(4)再次删除队首元素。
直到队列成为空队列为止,得到输出序列:(1)A、C、E、C、C (2) A、C、E(3) A、C、E、C、C、C (4) A、C、E、C3.给出栈的两种存储结构形式名称,在这两种栈的存储结构中如何判别栈空与栈满?4.按照四则运算加、减、乘、除和幂运算(↑)优先关系的惯例,画出对下列算术表达式求值时操作数栈和运算符栈的变化过程:A-B*C/D+E↑F5.试写一个算法,判断依次读入的一个以@为结束符的字母序列,是否为形如‘序列1&序列2’模式的字符序列。
其中序列1和序列2中都不含字符’&’,且序列2是序列1的逆序列。
例如,‘a+b&b+a’是属该模式的字符序列,而‘1+3&3-1’则不是。
6.假设表达式由单字母变量和双目四则运算算符构成。
试写一个算法,将一个通常书写形式且书写正确的表达式转换为逆波兰式。
7.假设以带头结点的循环链表表示队列,并且只设一个指针指向队尾元素结点(注意不设头指针),试编写相应的队列初始化、入队列和出队列的算法。
8.要求循环队列不损失一个空间全部都能得到利用, 设置一个标志域tag , 以tag为0或1来区分头尾指针相同时的队列状态的空与满,请编写与此结构相应的入队与出队算法。
9.简述以下算法的功能(其中栈和队列的元素类型均为int):(1)void proc_1(Stack S){ int i, n, A[255];n=0;while(!EmptyStack(S)){n++; Pop(&S, &A[n]);} for(i=1; i<=n; i++)Push(&S, A[i]);}(2)void proc_2(Stack S, int e) { Stack T; int d;InitStack(&T);while(!EmptyStack(S)){ Pop(&S, &d);if (d!=e) Push( &T, d);}while(!EmptyStack(T)){ Pop(&T, &d);Push( &S, d);}}(3)void proc_3(Queue *Q){ Stack S; int d;InitStack(&S);while(!EmptyQueue(*Q)){DeleteQueue(Q, &d);Push( &S, d);}while(!EmptyStack(S)){ Pop(&S, &d);EnterQueue(Q,d)}}实习题1.回文判断。
【良心出品】化合价练习题

化合价练习题姓名:1、标出下列各组物质中加点元素的化合价:(1)H2S. S. S.O2 Na2S.O3 H2S.O4(2)M.nO2 M.nCl2 M.n CaM.nO4 KM.nO42.用元素符号和相应的数字表示:①3个水分子;②2个硫原子;③+2价的镁元素;④2个镁离子;⑤m个硫酸根离子; +5价的磷元素; 4个氯化氢分子;氖气 , 保持氯气化学性质的微粒;五氧化二磷; 2个镁原子;3.用元素符号和相应的数字表示: ①3个水分子;②2个硫原子;③+2价的镁元素;④2个镁离子;⑤m个硫酸根离子。
4.将下列符号中“2”所表示的意义写在横线上:2Hg ; 2SO3; N2+2Cu O ; SO42-;5.有H、S、O、Na四种元素, 按下列要求写出由它们组成物质的化学式。
(1)组成的单质的化学式(四种);(2)组成的化合物的化学式(四种以上)。
6.A原子和B原子在形成化合物时, 每个A原子得到2个电子, 形成A离子, 每个B原子失去3个电子, 成为B离子。
写出A离子的符号是__B离子的符号是__, 在化合物中, A 的化合价是__, B元素的化合价是__, 两者构成的化合物的化学式是______。
7. 下列关于化合价的说法正确的是()A.化合物中, 氧元素一定显-2价B.化合物中, 非金属元素一定显负价C.氢气中氢元素的化合价为+1价D.化合物中正负化合价的代数和一定为零8、下列说法正确的是()A.在化合物中原子正负化合价代数和等于零B.单质的化合价为零C.单质分子的化合价为零 D、单质里元素的化合价为零9、下列说法中不正确的是()A.在H2中氢元素的化合价是+1价B.在HCl中氢元素的化合价是+1价C.在H2O中氧元素的化合价是-2价D.Fe有可变价+2价和+3价, 但在Fe2O3中铁元素显+3价10、下列化合物中, 原子团化合价为“-2”价的是()A.(NH4)2SB.Ca(OH)2C.CaCO3D.KNO311.下列物质中硫元素化合价最高的是()A. SB. K2SO4C. SO2D. H2S12.下列物质的化学式书写正确的是()A. 氖气Ne2B. 氧化铁FeOC. 硫酸钠Na2SO4D. 硝酸钙CaNO313.A.B.C 三种元素的化合价分别为+1.+2.-2, 这三种元素组成的化合物分子式可能是( ) A.ABC4 B.A4BC3 C.A2BC3 D.A3BC314、我国最新研制的高温超导材料氮化硼, 经测定该材料中两种元素的原子个数比为1∶1。
C#结构体、枚举类型及例题解析

C#结构体、枚举类型及例题解析结构体 ~struct定义:结构体⼀般定义在Main函数上⾯,位于Class下⾯,作为⼀个类;⼀般情况Struct定义在Main函数前⾯,Main函数⾥⾯的地⽅都可以使⽤,参数前⾯加上public代表公⽤变量。
格式:struct +结构体的名称{public int+变量名;public double+变量名;public string+变量名;}以上就是定义⼀个结构体的格式,⾥⾯包含许多种数据类型,如整形int,字符串string,带⼩数点decimal等;⽤法:(1)在Main函数外⾯定义了⼀个student类型的结构体,在Main主函数中使⽤:(2)然后为⾥⾯的每个元素赋值,结构体名+点+结构体⾥⾯变量名称=值。
(3)赋值之后完成之后进⾏打印。
枚举类型~Enum....{E}定义:枚举元素的默认基础类型为int。
默认情况下,第⼀个枚举数的值为0,后⾯每个枚举数的值依次递增1。
⽤法:枚举也可以指定数据类型,⼀般不指定。
在定义枚举类型时,可以选择基类型,但可以使⽤的基类型仅限于long、int、short和byte。
例题:1、定义⼀个结构体,存放关于车辆的⼏个信息将所有车的信息都放⼊集合中车型号价格(W)轴距(mm)油耗(L/100km)宝马320Li 38 2920 6.9宝马520Li 43 3108 7.2宝马730Li 89 3210 6.3奥迪A4L35TFSI 31 2869 6.2奥迪A6L30TFSI 43 3012 7.6奥迪A8L45TFSI 89 3122 8.1奔驰C200L 35 2920 6.1奔驰E260L 48 3014 6.7奔驰S320L 93 3165 8结构体:struct car{public string xinghao;public double jia;public double zhou;public double you;}ArrayList al = new ArrayList();car car1 = new car();car car2 = new car();car car3 = new car();car car4 = new car();car car5 = new car();car car6 = new car();car car7 = new car();car car8 = new car();car car9 = new car();car1.xinghao = "宝马320Li";car1.jia = 38;car1.zhou = 2920;car1.you = 6.9;al.Add(car1);car2.xinghao = "宝马520Li";car2.jia = 43;car2.zhou = 3108;car2.you = 7.2;al.Add(car2);car3.xinghao = "宝马730Li";car3.jia = 89;car3.zhou = 3210;car3.you = 6.3;al.Add(car3);car4.xinghao = "奥迪A4L35TFSI";car4.jia = 31;car4.zhou =2869;car4.you = 6.2;al.Add(car4);car5.xinghao = "奥迪A6L30TFSI";car5.jia = 43;car5.zhou = 3012;car5.you = 7.6;al.Add(car5);car6.xinghao = "奥迪A8L45TFSI";car6.jia = 89;car6.zhou = 3122;car6.you = 8.1;al.Add(car6);car7.xinghao = "奔驰C200L";car7.jia = 35;car7.zhou = 2920;car7.you = 6.1;al.Add(car7);car8.xinghao = "奔驰E260L";car8.jia = 48;car8.zhou = 3014;car8.you = 6.7;al.Add(car8);car9.xinghao = "奔驰S320L";car9.jia = 93;car9.zhou = 3165;car9.you = 8;al.Add(car9);1、现在想买⼀辆价格在50万以内的车,请给出车的型号以及价格 #regionfor (int i = 0; i < al.Count; i++){car c = (car)al[i];if (c.jia < 50){Console.WriteLine("型号:{0},价格{1}",c.xinghao,c.jia);}Console.ReadLine();#endregion2、买得起豪车,可是很关⼼油耗,给查⼀下油耗最低的三辆车的型号以及油耗情况#regionfor (int i = 0; i < al.Count; i++){for (int j = i; j < al.Count - 1; j++){car a = (car)al[i];car b = (car)al[j+1];if (a.you > b.you){object zhong = al[i];al[i] = al[j + 1];al[j + 1] = zhong;}}}for (int i = 0; i < 3; i++){car c = (car)al[i];Console.WriteLine("油耗最低的第{0}辆车的型号是{1},油耗为{2}",i+1,c.xinghao,c.you);}Console.ReadLine();#endregion3、买了车之后后座会经常坐⼈,所有我现在想要轴距⼤⼀些的车,前三名即可。
第三讲 结构体习题

}
A)12B)23C)14D)32
二、填空题
1.有如下定义:*
struct {int x; int y; }s[2]={{1,2},{3,4}},﹡p=s;
则:表达式++p->x的结果是。
表达式++p->x的结果是。
} std[3],* p=std;
下面各输入语句中错误的是。*
A) scanf("%d",&(*p).age);
B) scanf("%s",&);
C) scanf("%c",&std[0].sex);
D) scanf("%c",&(p->sex))
10.设有以下说明语句,则下面的叙述中不正确的是。*
则以下引用方式不正确的是。*
A)work.noB)(﹡p).noC)p->noD)work->no
3.有如下定义:
struct date { int year, month, day; };
struct worklist { char name[20]; char sex;
struct date birthday; }person;
STUDENT{ int num;
{ int num; float age;
float age; }std1; }std1;
C)structD)struct
{ int num; { int num;
float age; float age; } student;
(完整word版)数学分析复习题及答案(word文档良心出品)

数学分析复习题及答案一.单项选择题1. 已知, 则=()A. B. C. D.2. 设, 则()A. B. C. D.3. ()A. B. C. D.4. 下列函数在内单调增加的是()A. B. C. D.二、填空题1. 设函数2.3.在处连续, 则三、判断题1. 若函数在区间上连续, 则在上一致连续。
()2. 实轴上的任一有界无限点集至少有一个聚点。
()3.设为定义在上的单调有界函数, 则右极限存在。
()四、名词解释1. 用的语言叙述函数极限的定义2. 用的语言叙述数列极限的定义五、计算题1. 根据第四题第1小题证明2. 根据第四题第2小题证明3. 设, 求证存在, 并求其值。
4.证明:在上一致连续, 但在上不一致连续。
5. 证明: 若存在, 则6. 证明: 若函数在连续, 则与也在连续, 问: 若在或在上连续, 那么在上是否必连续。
一、1.D 2.C 3.B 4.C二、1. 2. 3.三、1.× 2.√ 3.√四、1.函数极限定义: 设函数在点的某个空心邻域内有定义, 为定数。
, , 当时, , 则。
2.数列极限定义:设为数列, 为定数, , , 当时, 有, 则称数列收敛于。
五、1.证明:, , 当时, ;得证。
2.证明:令, 则, 此时, ,, , 当时,3.证明:⑴,⑵)1)(1(1111111----+++-=+-+=-n n n n n n n n n n x x x x x x x x x x 而, 由数学归纳法可知, 单调增加。
综合⑴, ⑵可知存在,设, 则由解得=A 215+(负数舍去)4.证明: 先证在上一致连续。
, 取, 则当且有时, 有 []δ•''+'≤''-'''+'=''-'x x x x x x x f x f ))(()()(εε<+⋅++≤)(2)1(2b a b a故2)(x x f =在[]b a ,上一致连续。
(完整word版)操作系统英文版课后习题答案整理(word文档良心出品)

1.1What are the three main purposes of an operat ing system?⑴ In terface betwee n the hardware and user;(2) man age the resource of hardware and software;(3) abstracti on of resource;Answer;•Tb provide an environment ksr a computer user to execute programs on computer h日rchvare in n convenient and efficient manner.•Tb allocate the separate resources of the computer as needed to st)ke the problem given.The allcxation prtxzess should b? as fair and efficient as possible.•Asa control program it serves two major functions; (1) supervision of the execution 由user programs to prevent errors and improper use of the computer, and (2) management of the operatioji and control of I/O devices.1.2 List the four steps that are necessary to run a program on a completely dedicated machine. Preprocessing > Process ing > Linking > Executi ng.Answer:乩Reserxe machine time*b* Manually load program into memory.u Load starting address and begin exe匚Lition.cL Monitor and control execution of program fr(im console.b. In teractivec. Time shar ingd. Real timee. Networkf. DistributedAnswera” Batch, Jobs w计h similar reeds are batched together and run through the computer as a group by ^r\operator or automatic jc)b s^quenc^r. [^rformanct? i$ incr^a^ed by atteiTipting to keep CPU 3nd I/O devices busv 311 timesi through buffering, off-line operation^ spooling, and multiprogramming. Batch is good for executing 】arge jobs thjit need little interacticm; it can be submitted and piuked up later.b. Interactive. This system is cumpofied of m^nv short transactions where the results of thenext transactiiin may be unpredictablen Respond time needs tn be short (sectwids) since the user submits and waik for the result.u Time sharing. This systems u 船呂匚Pl sch<*duling ^nd multi programming to pmvidu eConoiniCcil interactive use of 蛊system. The CPL switches rapidly iri>m one user tn another Instead of having a job defined by spcxiled card images^ each program readsits next control card from the terminab and output is normally printed immediately to the screen.(_L Real time. Often tisvci in a dedicated application, this system reads information from sensors and must respond within a fixed amount of time to ensure correct performance.work.f.Distributed .This system distributes computation among several physical processors” TheprtKessors do not share menion- or a clock. Instead, each pnxzessor has its own kxzalmemory. They communicate with each other through various communication lines f such asa high-speed bus or telephone line.1.7 Wehave stressed the need for an operating system to make efficient use of the computing hardware. When is it appropriate for the operating system to forsake this principle and to waste ” resources? Why is such a system not really wasteful?Answer Single-user systems should maximize use of the system for the user A GUImight "xvastc * GPL' cycles, but it optimizes the user T s interaction with the system.2.2 How does the distinction between monitor mode and user mode function as a rudimentary form of protecti on (security) system?Answer: By establishing a set of privileged instructions that can be executed only when in tlie m(snitnr mt)de f the tiperating system is assured of controlling the entire system at all times.2.3 What are the differences between a trap and an interrupt? What is the use of eachfun cti on?Answer An interrupt is a ha rd \ v a re-^en era ted change-of-flow within the system. An interrupt handler is summoried to deal with the cause oF the interrupt; control is then re turned to the interrupted context and instruction. A trap is a software-j;enerated interrupt. An interrupt can be uwd to signal the compJrtio n “f an I/O obviate the nevd for polling. A trap can be used ti> call operating svstem routines or to catch arithmetic errors.2.5 Which of the follow ing in structi ons should be privileged?a. Set value of timer.b. Read the clock.c. Clear memory.d. Turn off interrupts.e. Switch from user to monitor mode.3OS Exercise BookClass No. NameAnswer: The following instructions should be privileged:Set value of timer,b.Clear memory.Jc.Turn off interrupts.d.Switch from user to monitor mode*2.8 Protecting the operating system is crucial to ensuring that the computer system operates correctly. Provision of this protection is the reason behind dual-mode operation, memory protection, and the timer. To allow maximum flexibility, however, we would also like to place mini mal con stra ints on the user.The following is a list of operations that are normally protected. What is the minimal setof in structi ons that must be protected?a. Change to user mode.b. Change to mon itor mode.c. Read from mon itor memory.d. Write into mon itor memory.e. Fetch an instruction from monitor memory.f. Tur n on timer in terrupt.g. Turn off timer interrupt.Answer: The minimal 5et of instructions that must be protected are:a.Change to monitor mtxle.b.Read from moni tor memory*c.Write into monitor me mor v.Jd.Turn off timer interrupt3.6 List five services provided by an operat ing system. Explain how each provides convenience to the users. Explain also in which cases it would be impossible for user-level programs to provide these services.Answer;«Program execution. The operating system loads thv contents (or sections) of a file into menidry and begins its execution. A user-level program could not be trusted to properly allocate CPU time.•I/O operations. Disks, tapes, serial lines;and other devices must be communicated with ata very low level. The user need only specify the dev ice and the operation to perform (in it,while the system converts that request into <ie\r ict^ or contr<i11er-spec i fit commands.User-level pnjgrams cannot be trusted to only access devices they should have access to and to only access them when they otherwise unused.«File-system manipulation, fhere are manv details in file creation, deletion/ alkKation, and naming that users should not have to perform. Blocks of disk space are used by files and must be tracked, deleting a file requires remo\ ing the name file information and freeing the <ilkx:ated blocky I^ratections must also be checked to assure proper file access. User prc^grams could neither ensure adherence to protect]on methcxis nor be trusted to allocate only free block吕and deallocate bkxzks on file deletion.J•Communications. Message passing between systems requires messages be turned into packets of information, sent to the network controller, trannmitted across a community tk>ns medium, and reassembled by the destination system.卩acket ordering and data correction must take place. Again, user program吕might not c(sordinate ac cess to the network dev ice, or they might receive packets destined tor other processes^»Error detection. Error detection (occurs at both the hardware and soFtwart? levels. At tlie hardware level, all data transfers must be inspected to ensure that data hax e not beencorrupted in transit All data on media must be checked to be sure they have not changed since they uritten to the media. At the software level, media must bechecked for data ccnsistencj^; for instance, do the number of allocated and unallocated blocks of storage match the total number on the device. There, errors are frequently pnxzess-independent (for instance, the 匚omiption of data on a disk)5 sc there must be a global program (the operating system) that handles all h pes of errors. Also, by having errors pmc essed by the operating system, processes need not contain code to catch and ccjrrect all the ernjrs possible on a system.3.7 What is the purpose of system calls?Answer; Sv>ttn'. dlltnv ustr-levtl lu request str\ ices nt 11 it? uperating svs-tem.3.10 What is the purpose of system programs?J V USWCE Svstcm programs can be thought of as bundle!ti of useful system oils. Thev r provide bcisic functidcaliU users and sci users do not need to wnte their cwn programs to s<>k r e comnicMi problems,4.1 MS-DOS provided no means of con curre nt process ing. Discuss three major complicati onsthat con curre nt process ing adds to an operat ing system.5OS Exercise BookClass No. NameAnswer:*A method of time sharing must be implemented to allow each of several prcxzesses to have access to the system. This method involves the preemption of processes that do notvoluntarily give up the CPU (by using a system ca1]r for instance) and the kernel being reentrant (so more than one prtxzess may be executing kernel code concurrently).・[Vocesses and system resources must have protections and must be protected from each other. Any given process must be limited in the amount of memory it can use and tlie ope Mt ions 让can perform on devices like di^ks.•Care must be taken in the kernel to prevent deadkxzks between prucesses, so processesaren*t waiting for each other's allocated rest>urces,4.6 The correct producer —consumer algorithm in Section 4.4 allows only n-1 buffers to befull at any one time. Modify the algorithm to allow all buffers to be utilized fully.Answer: No answer.5.1 Provide two program ming examples of multithread ing givi ng improve performa nee overa sin gle-threaded soluti on.Answer (1) A Web server that services each request in a separate Lliread. (2) A parallelized application such as matrix multiplication where different parts of the matrix may be worked on in parallel. (3) An intEivictin GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third thread monitors performance.5.3 What are two differences between user-level threads and kernel-level threads? Underwhat circumsta nces is one type better tha n the other?Answer: Context switching between user threads is quite sinniliir to switching between kernel threads, although it is dependent on the threads library and how it maps user threads to kernel threads. In general, context switching between user threads involves taking a user thread of its LWP and replacing it with another thread. This act typically involves saving and restoring the stttte of the registers.6.3 Consider the following set of processes, with the length of the CPU-burst time given inmillisec on ds:Process Burst Time PriorityP1103P211P323F414P552The processes are assumed to have arrived in the order P l, F2, F3, F4, P5, all at time 0.a.Draw four Gantt charts illustrati ng the executi on of these processes using FCFS, SJF, a non preemptive priority (a smaller priority n umber implies a higher priority), and RR (qua ntum = 1) scheduli ng.b.What is the turnaround time of each process for each of the scheduling algorithms in part a?c.What is the waiting time of each process for each of the scheduling algorithms in part a?d.Which of the schedules in part a results in the minimal average waiting time (over all processes)?An swer:Answer;a.The four Gantt charts areb.Turnaround timeFCFS RR SJF Priority101919 16112 1 113 741814421919149 6 匚Waiting time (turnaround time minus burst time)FCFS RR SJF Priority卩】0996Pz10100心115216P*133118Ps14941d. Shortest Job First6.4 Suppose that the following processes arrive for execution at the times indicated. Eachprocess will run the listed amou nt of time. In an sweri ng the questi ons, use non preemptive scheduling and base all decisions on the information you have at the time the decisionmust be made.PtXKCSS Ai ri\ al Time Burst Time0.087OS Exercise BookClass No. NameP20.44l.D1a. What is the average turnaround time for these processes with the FCFS scheduling algorithm?b. What is the average turnaround time for these processes with the SJF scheduling algorithm?c. The SJF algorithm is supposed to improve performa nee, but no tice that we chose to run process P1 at time0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is leftidle for the first 1 un it and the n SJF scheduli ng is used. Remember that processes P1 and P2 are wait ing dur ing this idle time, so their wait ing time may in crease. Thisalgorithm could be known as future-k no wledge scheduli ng.Answera.10.53b.9.53c.6,86Remember that turnaround time LS finishing time minus arrival time, so have to subtract the arrival tinier to compute thu turnaround times. FCFS is 11 if you forget to subtract arrival time.6.10 Explain the differences in the degree to which the following scheduling algorithms discrim in ate in favor of short processes:a.FCFSb.RRc.Multilevel feedback queuesAnswer:a.FCFS—discriminates against short jobs since any short jobs arriving after long jobs willhave a longer waiting time.b.RR一treats all jobs equally (giving them equal bursts of CPU time) so short jobs will beable to leave the system faster since they will finish first.c.Multilevel feedback queues—work similar to the RR algorithm—thev discriminatefa^r i>rably toward slusrt jobs.7.7 Show that, if the wait and sig nal operati ons are not executed atomically,then mutual exclusi on may be violated.Answer No answer.7.8 The Sleepi ng-Barber Problem. A barbershop con sists of a wait ing room with n chairs and the barber room containing the barber chair. If there are no customers to be served,the barber goes to sleep. If a customer en ters the barbershop and all chairs are occupied,then the customer leaves the shop .If the barber is busy but chairs are available, the nthe customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coord in ate the barber and the customers.Answer: Please refer to the support ing Web s its for source code solution,8.2 Is it possible to have a deadlock involving only one single process? Explain your answer.Answer Ncx I'his folknvs directly from the hold-and-wait condition.8.4 Con sider the traffic deadlock depicted in Figure 8.11.a. Show that the four n ecessary con diti ons for deadlock in deed hold in this example.b. State a simple rule that will avoid deadlocks in this system.Answer No answer.8.13 Con sider the follow ing sn apshot of a system:Allocati on Max AvailableA B C D A B C D A B C DP00 0 1 20 0 1 2 1 5 2 0P1 1 0 0 0 1 7 5 0P2 1 3 5 4 2 3 5 6P30 6 3 20 6 5 2P40 0 1 40 6 5 6An swer the follow ing questi ons using th e ban ker s algorithm:a.What is the content of the matrix Need?b.Is the system in a safe state?c.If a request from process P1 arrives for (0,4,2,0), can the request be gran tedimmediately?Answer;A. Deadlcx^k cannot ixrcur because preemption exists,b. Yes. A process may never acquire all the resources 让needs if they are continuouslypreempted by a series of requests such as those of process C.9.5 Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K,and 426K (in order)? Which algorithm makes the most efficie nt use of memory?Answer:a. First-fit:b* 212K is put in 500K partitionc. 417K is put in 600K partitiond* 112K is put in 288K partition (new partition 288K = 500K - 212K)e.426K must waitf.Best-fit:g.212K is put in 300K partition9OS Exercise BookClass No. Nameh.417K is put in 500K partitioni.112K is put in 200K partitionj.426K is put in 600K partitionk.Worst-fit:L 212K is put in 600K partitionm. 417K is put in 500K partitionn. 112K is put in 388K partitionc 426K must waitIn this example, Best-fit turns out to be the bE%t*9.8 Con sider a logical address space of eight pages of 1024 words each, mapped onto a physicalmemory of 32 frames.a. How many bits are there in the logical address?b. How many bits are there in the physical address?Answera,l.ogica) address: 13 bitsb.Physical address: 15 bitsJ9.16 Con sider the follow ing segme nt table:Segme nt Base Len gth02196001230014290100313275804195296What are the physical addresses for the follow ing logical addresses?a. 0,430b. 1,10c. 2,500d. 3,400e. 4,112Answer:a.219 + 430 = 649b.2300 + 10 = 2510u ill亡月ed reference, trap ki operating systemd.1327 -b 400 = 1727e.illegal reference, trap to operating system10.2 Assume that you have a page referenee string for a process with m frames (initiallyall empty). The page refere nee stri ng has len gth p with n disti net page n umbers occur init. For any page-replacement algorithms,a. What is a lower bou nd on the n umber of page faults?b. What is an upper bou nd on the n umber of page faults?Answer:a* nb»p1, 2, 3, 4, 2, 1,5, 6, 2, 1,2, 3, 7, 6, 3, 2, 1, 2, 3, 6.How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.LRU replaceme ntFIFO replaceme ntOptimal replaceme nt11OS Exercise BookClassNo.NameNumbei of frames1 2 3 4 5 6 711.7 Expla in the purpose of the ope n and close operati ons.Answer :» The o[fen operation informs the system that the named file is about to bect>me active^ * Tlie cluse operation informs the system that the named file )s nt> lunger in active use by the user who issued the dose operation.11.9 Give an example of an application in which data in a file should be accessed in the followi ng order: a. Seque ntially b. Ran domlyAnswer :a. Print the 匚 on tent of the file,b. Print the content of record /. This record can be found using hashing or index tech niques.11.12 Con sider a system that supports 5000 users. Suppose that you want to allow 4990 of these users to be able to access one file.a. How would you specify this protection scheme in UNIX?b. Could you suggest ano ther protecti on scheme that can be used more effectively for this purpose tha n the scheme provided by UNIX?Answer:a. There are twc methods for achieving this : L Create an access control list withtlu? names of all 4990 users.ii. Put these 4990 users in one ^roup and set the group access accordingly. This scheme cannot always be implemented since user groups are restricted by the system. b. The universe access information applies to all users unless their name appears in the access-control list with different access permission. With this scheme you simply put the names of the remaining ten users in the access control list but \v 让h no access pri\ ileges allovcexfLRUFIFOOptimal 20 20 20 18 18 15 15 16 11 10 14 8 8 10 7 7 10 7 7 77Answer12.1 Consider a file currently consisting of 100 blocks. Assume that the file control block (andthe index block, in the case of indexed allocation) is already in memory. Calculate howmany disk I/O operations are required for contiguous, linked, and indexed (single-level)allocati on strategies, if, for one block, the follow ing con diti ons hold. In thecon tiguousallocati on case, assume that there is no room to grow in the beg inning, but there is room to grow in the end. Assume that the block in formatio n to be added is stored in memory.a. The block is added at the beg inning.b. The block is added in the middle.c. The block is added at the end.d. The block is removed from the begi nning.e. The block is removed from the middle.f. The block is removed from the end.AnswerLinked Indexeda. 201 1 1b. 1015211 3 1d. 198 1 0e. 9852 0f. 0 100 013.2 Con sider the follow ing I/O sce narios on a sin gle-user PC.a. A mouse used with a graphical user in terfaceb. A tape drive on a multitasking operating system (assume no device preallocation is available)c. A disk drive containing user filesd. A graphics card with direct bus conn ecti on, accessible through memory-mappedI/OFor each of these I/O scenarios, would you design the operating system to use buffering, spooli ng, cachi ng, or a comb in ati on? Would you use polled I/O, or in terrupt-drive n I/O? Give reas ons for your choices.Answer:a. A mouse used with a graphical user interfaceBuffering may be needed to record mouse movement during times when higher- priority operations are taking place. Spooling and caching are inappropriate. Inter rupt driven I/O is most appropriate^b” A tape drive on a multitasking operating system (assume no device preAlkxzation is available)Buffering may be needed to manage throughput d让ferEria? behveen the tape drive and the sounzt? or destination of the I/O, C臼匚hing can be used to hold copies of that resides on the tape, for faster access. Spooling could be used to stage data to the device whenmultiple users desire to read from or write to it” Interrupt driven [/O is likely to allow the best performance.13OS Exercise BookClass No. Name匸* A disk drive containing user tilesBuffering can be used to hold data while in transit from user space to the disk, and visaversa. Caching can be used to hold disk-resident data for improved perfor mance.Spoc^ling is not necessary because disks are shared-access devices. Interrupt- driven T/O is best for devices such as disks that transfer data at slow rates,d. A graphics card w让h direct bus coi^nection, accessible through mem<irv-mapped I/OBuffering may be needed to control multiple access and for performance (doublebuffering can be used to hold the next screen image while displaying the current tme). Caching and spooling are not necessary r due to the fast and shared-access natures of the device. Polling and interrupts are only useful for input and for【/O completion detec tion f neither of which is needed for a mem()r y-ma pped device.14.2 Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, in FIFO order, is86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130Start ing from the curre nt head positi on, what is the total dista nee (in cyli nders) thatthe disk arm moves to satisfy all the pending requests, for each of the follow ingdiskscheduli ngalgorithms?a. FCFSb. SSTFc. SCANd. LOOKe. C-SCANAnswer:乩The FCFS schedule is 143f 86f 1470, 913, 1774, 948, 1509, 1022, 1754), 130. The total seek distance is 7081.b. The SSTF schedule is 143, 130, 86. 913, 948, 1022, 1470, 1509. 1750r 1774. The total seekdistance is 1745.€. The SCAN schedule is 143, 913, 94«f1022f 1470, 1509,1750f 1774, 4999,130, 86. The to怙1 seek distance is 9769.d.The LOOK schedule is 143, 913, 948,1022, 1470,1509,1750,177< 130,86. The total seekdistance is 3319*e.The C-SCAN schedule is 143f 913,948,1022J 470,1509.1750,1774,4999,8& 130. The totalseek distance is 9813.f.(Bonus.) The C-LOOK schedule is 143,913,94& 1022,1470,1509.1750,1774, 86,130. Thetotal seek distance is 3363.1.1 1.62.3 2.53.7 6.3 6。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
struct ex {
int x ; float y; char z ;
} example;
A) struct结构体类型的关键字B) example是结构体类型名
C) x,y,z都是结构体成员名D) struct ex是结构体类型
11.若程序中有下面的说明和定义:
struct
{ unsigned int year;
unsigned int month;
unsigned int day;
}birthday;
} stu;
struct student *t = &stu;
若要把变量t中的生日赋值为“1980年5月1日”,则正确的赋值方式为。*
A) year = 1980; B) t.year = 1980;
struct stt
{ int x;
char b;
}
struct stt a1,a2;
则会发生的情况是。*
A)程序将顺利编译、连接、执行。
B)编译出错。
C)能顺利通过编译、连接,但不能执行。
D)能顺利通过编译,但连接出错。
12.已知教师记录定义为:
struct student
{ int no;
char name[30];
month = 5; t.month = 5;
day = 1; t.day = 1;
C) t.birthday.year = 1980; D) t-> birthday.year = 1980;
t.birthday.month = 5; t-> birthday.month = 5;
t.birthday.day = 1; t-> birthday.day = 1;
A)prinft(“%c\n”,class[3].mane);
B)pfintf(“%c\n”,class[3].name[1]);
C)prinft(“%c\n”,class[2].name[1]);
D)printf(“%^c\n”,class[2].name[0]);
9.设有如下定义
struct ss
STUDENT { int num;
{ int num; float age;
float age; }std1; }std1;
C) struct D) struct
{ int num; { int num;
float nt;
}std1; struct student std1;
{ char name[10];
int age;
char sex;
} std[3],* p=std;
下面各输入语句中错误的是。*
A) scanf("%d",&(*p).age);
B) scanf("%s",&);
C) scanf("%c",&std[0].sex);
D) scanf("%c",&(p->sex))
对结构体变量person的出生年份进行赋值时,下面正确的赋值语句是。
*
A) year=1958 B) birthday.year=1958
C) person.birthday.year=1958 D) person.year=1958
4.以下对结构体类型变量的定义中不正确的是。*
A)#define STUDENT struct student B) struct student
13.以下结构类型可用来构造链表的是。*
A)struct aa{ int a;int * b;};
B)struct bb{ int a;bb * b;};
C)struct cc{ int * a;cc b;};
D)struct dd{ int * a;aa b;};
14.以下程序的输出结果是。**
amovep(int *p, int a[3][3],int n)
则以下引用方式不正确的是。*
A) work.no B) (﹡p).no C) p->no D)work->no
3.有如下定义:
struct date { int year, month, day; };
struct worklist { char name[20]; char sex;
struct date birthday; }person;
A)所有成员一直驻留在内存中
B)只有一个成员主留在内存中
C)部分成员驻留在内存中
D)没有成员驻留在内存中
7.以下程序的运行结果是。*
# include <stdio.h>
main( )
{struct date
{ int year, month, day; }today;
printf(“%d\n”,sizeof(struct date)); }
第
一、选择题
1.在说明一个结构体变量时系统分配给它的存储空间是。
A)该结构体中第一个成员所需存储空间
B)该结构体中最后一个成员所需存储空间
C)该结构体中占用最大存储空间的成员所需存储空间
D)该结构体中所有成员所需存储空间的总和
2.若有以下说明和语句:
struct worker
{ int no; char﹡name; }work,﹡p=&work;
A) 6 B)8 C) 10 D)12
8.有如下定义
struct person{char name[9]; int age;};
struct person class[10]={“Johu”, 17,
“Paul”, 19
“Mary”, 18,
“Adam 16,};
根据上述定义,能输出字母M的语句是。*
{ int i, j;
for( i=0;i<n;i++)
for(j=0;j<n;j++){ *p=a[i][j];p++; }
}
main()
{ int *p,a[3][3]={{1,3,5},{2,4,6}};
p=(int *)malloc(100);
amovep(p,a,3);
printf("%d %d \n",p[2],p[5]);free(p);
5.设有以下说明语句
struct stu
{ int a; float b; }stutype;
则下面的叙述不正确的是。*
A)struct是结构体类型的关键字
B)struct stu是用户定义的结构体类型
C)stutype是用户定义的结构体类型名
D)a和b都是结构体成员名
6.C语言结构体类型变量在程序执行期间。