CS计算机代考程序代写 import “io”

import “io”

/*
devctl(DC_TAPE_LOAD, unit#, “filename”, ‘R’ or ‘W’)
devctl(DC_TAPE_READ, unit#, buffer)
devctl(DC_TAPE_WRITE, unit#, buffer, blocksizeinbytes)
devctl(DC_TAPE_UNLOAD, unit#)

all return codes pos or zero = success
negative is error message index
for read, the result is size of block
*/

let buffer = vec(128);
let pos = 0;
let size = 0;

let ropen(fname) be
{ let r = devctl(DC_TAPE_LOAD, 1, fname, ‘R’);
if r < 0 then { out("code %d from tape load\n", r); finish } pos := 0 } let rclose() be { let r = devctl(DC_TAPE_UNLOAD, 1); if r < 0 then { out("code %d from tape unload\n", r); finish } } let rchar() be { let c; if pos = size then { let r = devctl(DC_TAPE_READ, 1, buffer); if r < 0 then { out("code %d from tape read\n", r); finish } pos := 0; size := r } if pos = size then resultis -1; c := byte pos of buffer; pos +:= 1; resultis c } let rnum() be { let n = 0, c = rchar(); while c < ' ' do c := rchar(); while c >= ‘0’ /\ c <= '9' do { n := n * 10 + c - '0'; c := rchar() } resultis n } let start() be { ropen("numbers.txt"); while true do { let n = rnum(); out("The number is %d\n", n) } rclose() }