1 / 29

E0001 Computers in Engineering

E0001 Computers in Engineering. Qbasic Commands. Readings & activities. Study Book; Module 8 & 9 note error in summary of readings handout Qbasic with an Intro to Visual Basic by Schneider; p40 to 47; p55 to 57 Practice Problems and Exercises 3.1 & 3.2 as necessary.

Download Presentation

E0001 Computers in Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. E0001 Computers in Engineering Qbasic Commands

  2. Readings & activities • Study Book; Module 8 & 9 note error in summary of readings handout • Qbasic with an Intro to Visual Basic by Schneider; p40 to 47; p55 to 57 • Practice Problems and Exercises 3.1 & 3.2 as necessary

  3. Key points from last (programming) lecture? • how to access Qbasic • menu system • save and retrieve a program • program development cycle • programming tools • flowchart; pseudocode; top down charts

  4. This lecture • what is a variable • types of variables • arithmetic operations • PRINT statement

  5. Payrate = 6.25 hours = 25 grosspay = payrate * hours PRINT grosspay END A general solution?

  6. Variables • Quantities referred to by symbolic names • make general solutions • Variable name: is the name of a storage location in primary memory where Qbasic stores the value of the variable • value can change during program execution

  7. X = 0.5 y = 10 z = x + y total = z + x y = total x = 10 x = x+y Assignment of variables

  8. Assigning variables [LET] variablename = variable • e.g. LET x = 2 x = 2 LET sum = 24 sum = 24 LET counter = counter +1 total = total + x

  9. Variable names • may only contain letters, digits and full stop • may not contain a blank space • must start with a letter and may be up to 40 characters • may NOT be a reserved word e.g let, print • generally given a value of 0 initially but...

  10. A 4sale Test1 Rumplestiltskin %Interest Gross Pay Grosspay GroSSPay Valid invalid valid valid invalid invalid valid valid Valid names

  11. single-precision default type double-precision scientific notation for printing very large or very small numbers integer long-integer string -3.37*1038to 3.37* 1038 -1.67 *10308to 1.67* 10308 1 * 10-5 = 1E-5 .000013596426 = 1.359643E-5 -32 768 to 32 767 -2 147 483 648 to 2 147 483 648 any alphanumeric Types of Variables

  12. TYPE statement e.g. DIM x AS integer DIM variablename AS type Types single double integer long string Suffix on variable name ! (Single) # (Double) % (Integer ) & (Long) $ (String) Assigning variable types

  13. Output of Program? x = 3.1234 PRINT x% what type of variable is x%? x = 3.123456789 PRINT x

  14. Strings • Strings are groups of characters which represent words, sentences, letters etc • Two types • String Constant • sequence of characters surrounded by quotes • quotes not part of the string constant • String Variables • used to hold a string value • similar to numeric variable • initial value - “” (null or empty string)

  15. Examples hello$ = “welcome to Engineering” PRINT hello$ Let answer$ = “yes” IF answer$=“no” THEN PRINT hello$

  16. Arithmetic Operations • five arithmetic operations • additions (+); subtraction (-); division(/); multiplication (*); exponentiation (^) • executed in a specific order • ( ) inner to outer; left to right • ^ left to right • * and /; \ (integer division); MOD (modulus); left to right • + and - ; left to right

  17. PRINT statement • basic form: PRINT operation (arithmetic) • PRINT 3 * 2 • PRINT variablelist • PRINT a, b, c orPRINT x; y; z • PRINT answer$ • PRINT “prompt”, variablelist • PRINT “the answer is”, a

  18. Screen Placement & Formatting • PRINT zones • line has 80 characters • subdivided into 5 zones • zones 1 - 4 have 14 characters • zone 5 has 24 characters • zones start at columns 1, 15, 29, 43 & 57

  19. Print zones contd • commas as separators in PRINT statement • next item printed in next zone • statement ends in comma • next item printed in next print zone • semicolon as separators in PRINT statement • separated by 2 spaces • statement ends in semicolon • next item separated by 2 spaces

  20. x = 2 y = 3 * x x = y + 5 PRINT x + 4 y = y + 1 END x y 2 6 11 OUTPUT - 15 7 Determine variables and outputs

  21. single precision integer double precision string variable total = 6 total% = 6 total# = 6 total$ = “6” Determine types of variables

  22. DIM x AS LONG DIM y AS STRING DIM z AS DOUBLE DIM zz AS INTEGER x& y$ z# zz% Dim statement

  23. Problem • draw a flowchart which will • define variables for pi, radius and circumference as double, integer and double respectively • set radius = 3.2, pi = 22/7 • calculate the circumference • print all variables

  24. Flowchart

  25. Key points • arithmetic order • types of variables and how to assign specific types • PRINT statement

  26. Your turn • Draw a flowchart that take two times in hours, minutes and seconds and will calculate the total time in hours minutes and seconds e.g 2 hr, 15 min & 12 sec + 1 hr 10 min and 5 sec = 3 hrs 25 min and 17 sec

  27. The End!!

  28. Variable names - what can you remember? • used for general solutions • value may change during the program • may only contain letters, digits and full stop • may not contain a blank space • must start with a letter and may be up to 40 characters • may NOT be a reserved word e.g let, print • generally given a value of 0 initially but..

More Related