# START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.

## Presentation on theme: "START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables."— Presentation transcript:

START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables step by step. Carefully! This program might do wrong things too! (Actually, this program might have errors. It works, but not always like wanted). Your task is not to correct them, but to see which will be the values of the variables. Definitions and the drawing and writing style used in the flowcharts in this exam are correct and can be used as a model for your own flowcharts. values( 2 ) = values( 1 ) i <= 3 sum = sum + i i = i + 1 TRUE FALSE values( 1 ) = temp temp = values( 2 ) DISPLAY ”The sum is: ” sum average = sum / 6 DISPLAY ”The average is: ” average i = 1 END The first picture here The second picture here Programming 1 – Final exam Dec 16 2004 Task 1: (Do both Tasks 1 & 2 if not happy with the result of the first exam.) Look at the flowchart below. Draw two pictures showing the contents of the memory in that program. That is, draw the variables and data structures and the values inside them: 1.Right after the START (picture1) 2.Just before the END (picture2) Also put ”undefined” if the variable does not have a value yet. No material – Each task on separate paper – Name on every used paper – Return every paper Juhani Välimäki

Task 2: (Do both Tasks 1 & 2 if not happy with the result of the first exam.) Design with a flowchart a program that asks the user to input temperatures (N5,2) for each 7 days on the week. Save the values in an array called temperatures. Program should calculate the average of the temperatures and display that. Example test case (just an example, do not use fixed values in your program) displayed:user inputs: Give the temperature for the day 1: -10.5 Give the temperature for the day 2: -1.5 Give the temperature for the day 3: 7.2.5 Give the temperature for the day 4: 100.25 Give the temperature for the day 5: 4.0 Give the temperature for the day 6: -15 Give the temperature for the day 7: 0.5 The average was 12.14. Then program should ask the user to input a number of the day. While the number is between 1 and 7 the program displays the temperature of that day and asks for the next number. If the number is not between 1 and 7 program quits and tells how many times it was asked about the temperature of some real, existing day (=user gave a number between 1 and 7). Example output displayed: user inputs: Give a number of a day (1-7): 2 The temperature of the day 2 was -1.50. Give another number of a day (1-7): 5 The temperature of the day 5 was 4.00 Give another number of a day (1-7): 8 You asked about the temperatures 2 times. Bye!.

Juhani Välimäki Task 3: The sequential file products contains the following information about each product: code AN5 nameAN10 priceN6,2 amountN4 (how much in the store right now) Design with a flowchart a program that reads all the products from the file products and selects those products whose amount is too small (<20) and writes them to another file called product_orders. The program displays nothing, just writes some of the products to the output file product_orders. Each record in the file product_orders is of type: code AN5 nameAN10 priceN6,2 amount N4 (how much should be ordered) The amount of how much should be ordered is calculated with: amount = 100 - amount (old amount in the store right now) ----------------------------------------------------------------------------------- SOME FILE RELATED DEFINITIONS customers, sequential file TYPE T_CUSTOMER xxxxx AN 1 cust T_.... FILE RELATED COMMANDS IN FLOWCHART OPEN customers (R), other (W) READ... ->... WRITE... ->... CLOSE customers, other Tasks 3 & 4 are for everybody.

Task 4: Write a Java program corresponding the flowchart below. Think first. (Where should the subroutine definition be and so on) class Task4 // help for you { public static void main(String[] args) {... double d... int num... String str... boolean isClosed... System.out.println(”Give the price for product ” + i );...double some = Keyboard.readDouble();...string1.equals(”Some text”)... if( a = = b ) { } Juhani Välimäki START Main program DEFINITIONS numbers (100) N4,2 i N3 num N2 sum N6,2 = 0 ttt AN7 = ”Sum was” START RETURN ( half ) SUBROUTINE split_Into_Two( value N2 ) N4,2 DEFINITIONS precise N4,2 half N4,2 half = precise / 2 Tasks 3 & 4 are for everybody. i <= 100 TRUE FALSE DISPLAY ”Give a number: ” ACCEPT num END i = i + 1 numbers( i ) = CALL split_Into_Two( num ) DISPLAY ttt ”: ” sum sum = sum + num sum = sum / 2 i = 1 precise = value ttt == ”Sum was” TRUE FALSE DISPLAY ”impossible” This program is just an example. The program has no other meaning than testing Your Java skills! Good Luck! Flowchart syntax and drawing style are correct and can be used as a model.

Download ppt "START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables."

Similar presentations