Quiz+6+Programs

Program 1

 for decreasing x: 44..33 by 2  put "Hello"  end for

 Program 2

 loop  get b  a:=a+b  exit when b = 10  end loop

 Program 3

 var counter : int :=0  loop  counter := counter +1  if counter mod 2 not = 0 then  put counter .. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> end if <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> exit when counter = 3 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> end loop

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Program 4

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var line: string <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var sn: int <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;">**//missing code//** <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put line

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Program 5 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var counter : int :=0 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> const A1:= "" <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> loop <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> counter := counter +1 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> if counter mod 2 not = 0 then <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> A1:= "sad" <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put A1: 4.. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> else <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> A1:= "Happy" <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put A1: 6.. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> end if <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> exit when

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Program 6 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Test data from file: <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Jim 25 25 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Jane 20 10

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var name: string <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var sn, score, score2, count, total: int <span style="font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 25px;">open:sn, "datafile.t", get <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> assert sn>0 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> count:=0 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> total:= 0 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> loop <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> count:=count +1 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> get: sn, name, score, score2 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> get: sn, skip <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;">put name:5, score, score2:3 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;">total:=score +score2 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 25px;">exit when eof (sn) <span style="font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 25px;">put total <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> end loop <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;">put total/5 <span style="font-family: Arial,Helvetica,sans-serif;"> total:= total div 2 <span style="font-family: Arial,Helvetica,sans-serif;"> put total

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> Program 7 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;">%This program is designed to calculate the number of bills paid and the total amount on money paid <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var answer: string <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var gasbill, totalbill: _ _ _ _ _ _ _ <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> var billnumber: _ _ _ _ _ _ _ :=1 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> totalbill:=0 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> loop <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> _ _ _ _ _ _ _ "Enter the value of gas bill number ", billnumber, "." <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put "Type 0 to exit program." <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> get _ _ _ _ _ _ _ <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> if gasbill = 0 then <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put "Are you sure? (Y/N)" <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> get answer <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> exit when answer = "y" or answer = "Y" <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> end _ _ _ _ _ _ _ <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> totalbill:=_ _ _ _ _ _ _ + gasbill <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> _ _ _ _ _ _ _:= billnumber +1 <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> _ _ _ _ _ _ _ loop <span style="font-family: Arial,Helvetica,sans-serif; font-size: 130%;"> put "You had "<span style="font-family: Arial,Helvetica,sans-serif;">_ _ _ _ _ _ _ billnumber - 1, " gas bills." <span style="font-family: Arial,Helvetica,sans-serif;"> put "they totalled ", _ _ _ _ _ _ _, " dollars."