Final Review All preceeding Chapters (1 - 8) Chapters (9 - 14) Chapter 9: Rewrite the following using set notation: a. (0 < I) AND (I < 25) if I IN [1..25] b. (Ch = 'A') OR (Ch = 'J') OR (Ch = 'K') if Ch IN ['A', 'J', 'K'] c. (X = 1) OR (X > 50) AND (X <= 100) if X IN [1, 51..100] Chapter 10: Exam Preparation Exercises: 2, 7, 8 Programming Warm-Up Exercises: 3, 6 What values result from the following function calls? a. PRED(12) 11 b. SUCC('B') 'C' c. SUCC(Monday), where Monday is an element of type Days, and Days = (Monday, Tuesday, Wednesday, Thursday, Friday) Tuesday d. ORD('C') where CHR(1) = 'A' 3 e. CHR(5) where ORD('A') = 1 'E' Define a subrange type or enumerated type (as appropriate) for each of the following: a. Crops consisting of rice, beans, corn, and peas Crops = (rice, beans, corn, peas); b. All the days of the week DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday); c. Workdays Monday through Friday from the tlype in part b Workdays = Monday .. Friday; d. Range -10 to +200 inclusive Range = -10 .. 200; e. Characters 'B' through 'K' B2K = 'B'..'K'; f. A column counter of the range 1 to 72 ColCt = 1..72; Which of the following decaration segments are legal? a. TYPE Color = (Red, Yellow, Blue); Shade = (Light, Dark); Legal b. TYPE Size = (Small, Medium, Large, Giant); Creatures = (Dwarf, Dragon, Giant, Knight); Not legal because Giant can not belong to two types. c. TYPE List = ARRAY[1..200] OF Code; Code = 1..10; VAR CodeList : List; Not legal because Code is defined after List. d. TYPE Code = 1..5; List = ARRAY[Code] OF INTEGER; VAR CodeList : List; Legal e. TYPE CodeList : ARRAY[1..5] OF INTEGER; Not Legal. Should have equal (=) instead of colon (:). f. TYPE Color : (Red, Yellow, Blue); Not Legal. Should have equal (=) instead of colon (:). g. TYPE Code = (Fixed, Varying, Mixed); RunType = ARRAY[1..5] OF Code; VAR List : RunType; Mixed : INTEGER; Not legal. Mixed can not be both a variable and an enumerated. Chapter 11: Exam Preparation Exercises: 1, 2 Write a procedure, SumArray, that receives an ARRAY variable name as a parameter, sums the values in that array, and returns the total to the calling program. Assume these declarations in the main program: CONST TotalLimit = 200; TYPE Totals = ARRAY[1..TotalLimit] OF INTEGER; Note: Other declarations would have to be made before this procedure can be called, but that's not part of the problem. PROCEDURE SumArray (VAR Arr:Totals; Count:INTEGER; VAR Sum:INTEGER); VAR I:INTEGER; BEGIN {SumArray} Sum := 0; FOR I := 1 TO Count DO Sum := Sum + Arr[I]; END; {SumArray} Chapter 12: Exam Preparation Exercises: 3 Programming Warm-Up Exercises: 1, 2 Declare a string variable, Name, consisting of twenty-five characters. Name : PACKED ARRAY[1..25] OF CHAR; Chapter 13: Exam Preparation Exercises: 5, 7 An array is a collection of identical-type elements referenced by a single name and a subscript. True False True Chapter 14: Exam Preparation Exercises: 2, 3, 6, 10, 12 Given the following declarations: TYPE Name = ARRAY[1..25] OF CHAR; Map = RECORD Street : ARRAY[1..2000] OF Name; Park : ARRAY[1..20] OF Name END; City = RECORD CityName : Name; Population : INTEGER; Location : (NE, NW, SE, SW, NC, SC); List : Map END; ListType = ARRAY[1..200] OF City; Box = RECORD Length, Width, Height : INTEGER; Cube : BOOLEAN END; PackingType = ARRAY[1..80] OF Box; VAR CityList : ListType; Carton : Box; Packing : PackingType; ACity : City; AMap : Map; I, Count : INTEGER; Handle : Name; Which of the following would be valid statements in the main program? (Assume valid variables have defined values.) a. ACity := CityList[5]; True City := City b. Carton := Count; False Box := INTEGER c. CityList[6].List := AMap; True Map := Map d. Packing.Width := I; False Error, Packing[] e. ACity.CityName[1] := AMap.Street[1]; False CHAR := ARRAY f. CityList[100].List.Street[1,2] := Handle[2]; True CHAR := CHAR g. IF Packing[3].Cube True BOOLEAN THEN Count := Count + 1; INTEGER := INTEG ER h. IF CityList[20].Location = SW True Enumerated THEN CityList[20].List.Street[1,1] := 'D'; CHAR := CHAR i. ACity. Population := I; True INTEGER := INTEG ER j. IF Cube False BOOLEAN THEN Count := Count + 1; INTEGER := INTEG ER k. I := City.Population; False INTEGER := Error l. ACity.List := AMap; True Map := Map m. IF City.Location = NW False Error, ACity THEN Count := Count + 1; INTEGER := INTEG ER n. CityList[1].List.Street[2] := Handle; True Name := Name o. Packing[100].Length := I; False Error, <= 80 p. CityList[20].Street[1] := Handle; False Error, .List