220 likes | 300 Views
General Review. What have we done so far?. Variables , types of variables, defining variables INPUT statements READ and DATA statements PRINT and PRINT USING statements inbuilt functions - numerical and string. What YOU should have done!. To end Chapter 3 - Schneider 3.2; 3.3; 3.4; 3.5
E N D
What have we done so far? • Variables , types of variables, defining variables • INPUT statements • READ and DATA statements • PRINT and PRINT USING statements • inbuilt functions - numerical and string
What YOU should have done! • To end Chapter 3 - Schneider • 3.2; 3.3; 3.4; 3.5 • Try programming projects 1,2, & 6 p 94/5 • Prac work to end Week 5 • Modules 1-9 Study Book and questions at the end of the modules
Testing • Does the program give correct results for typical conditions? • does it work for unusual conditions • very large or small entered values • zero entries • select a set of inputs for typical and extreme conditions, check by hand or calculator
Debugging • A bug is a mistake in a program that prevents it from producing correct results • debugging is finding and correcting errors • three categories of errors: • syntax error • execution error, or runtime error • logic error
Syntax error • a statement that does not follow the rules • typically a typing or spelling error • e.g. LOT instead of LET • z = x ** y • qbasic will find syntax errors for you • it will display an error message and highlight the portion of the incorrect statement • may not find all syntax errors until you run the program
Logic errors • All statements are syntactically correct • qbasic can execute them and give results • results are wrong • errors in algorithm • hardest to find
Execution error • or runtime error • syntax is correct but qbasic cannot execute that statement • x = 400 * 500 • overflow, value to large for data type • types of execturion errors • overflow • division by zero • type mismatch • illegal function call
Problem • The period P of a pendulum of length L and maximum displacement angle is given by the formula P = write a program that requests as input the length and maximum angle of displacement, and displays the period of the pendulum
Plan • Output • period of pendulum • Input • length, angle (in degrees) • g = gravity • Process • convert degrees to radians • calculate period
Plan • Input length • input angle in degrees • g = gravity constant • calculate period • print period and variables
Valid read statements READ variables ---- DATA values e.g READ a, y, z DATA 10,20,30 READ x, y , z ---- DATA 10 DATA 20 DATA 30 READ and DATA
READ X READ Y READ Z ----- DATA 10 DATA 20 DATA 30 READ X READ Y READ Z ----- DATA 10, 20, 30
PRINT USING CLS a = 1 b = 4.2 c = 5328.268 d = 213 Fmt$ = “ ### ##.## ##,##.## ##” PRINT USING Fmt$; a; b; c; d
a$ = “string” b$ = “very big string” c$ = “another string” Fmt$ = “\ 8 spaces\ \ 8 spaces \ ! &” PRINT USING Fmt$; a$; b$; a$; c$
A = 150 b = 20.25 fmt1$ = “ $####.## $$####.##” PRINT USING fmt1$; a , b fmt2$ = “ Total sales this month $$###.##” PRINT USING fmt2$; b
Other misconceptions • Pi is NOT predefined • pi = 22/7 • pi = 3.14… • pi = 4* ATN(1) • dimensioning variables • use DIM OR a suffix NOT both • DIM statements come at the beginning of a program • DIM a AS string, b AS long, c AS single
Conventions in setting out programs • Title bar at start, name, date, program • list of all variables used and explanation • DIM statements for all variables • comments throughout • follow program development cycle • input, process, output