1 / 19

Computers in Engineering

Computers in Engineering. PRINT USING STATEMENT. Overview. In a circuit three currents are represented by the variables cur1, cur2, cur3 Plan and write a program to input these values and calculate and display the average current. Plan. Outputs… Inputs…. Process… flowchart/plan/pseudocode.

lydie
Download Presentation

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. Computers in Engineering PRINT USING STATEMENT

  2. Overview In a circuit three currents are represented by the variables cur1, cur2, cur3 Plan and write a program to input these values and calculate and display the average current

  3. Plan • Outputs… • Inputs…. • Process… • flowchart/plan/pseudocode

  4. INPUT statements Write input statements to enter these variables INPUT “current 1”, cur1 INPUT “current 2”, cur2 INPUT “current 3”, cur3

  5. In Memory User enters 9.16, 12.4, 0.9 cur1 9.16 cur2 12.4 cur3 0.9

  6. Calculate total and average currents and print totCur = cur1 + cur2 + cur3 AvgCur = totCur / 3 PRINT , cur1 PRINT , cur2 PRINT , cur3 PRINT , “________” PRINT , TotCur PRINT “Average”, AvgCur

  7. Qbasic Screen

  8. To add units to a variable PRINT “Current”; cur1; “amps” PRINT “prompt” ; variable list ; “prompt”

  9. PRINT USING • PRINT USING statement can be used instead of PRINT to make decimal points line up • has general form - PRINT USING “format string”;expression list e.g PRINT USING “ ##.##”; cur1

  10. Format string • String of characters • letters, numbers, punctuation • some have special meanings • if no special meaning qb will simply display it on the screen • if has special meaning qb uses it to determine the format for displaying one of the expressions in the list

  11. Formatting numbers • # # #.# # • displays 3 digits preceding the decimal • fewer than 3 before qbasic leaves a space • more than 3 - will be displayed correctly but in a different format, will also precede it with a % character • displays 2 digits after the decimal • fewer than 2 - displays zeros for the missing digits • more than 2 - displays the rounded value

  12. Format string Fmt$ = “current is ##.## at ###.# volts” PRINT USING Fmt$; cur; volts c.f. PRINT USING “format string”;expression list

  13. Scientific notation - e.g. 2E-6 • ^^^^ • represent positions for E, minus or plus sign, two digit exponent • ^^^^^ • for double precision numbers • represent positions for E, minus or plus sign, three digit exponent • e.g. FMT$ = “current is ##.###^^^^ at ##.####^^^^ volts”

  14. Output? Current is 23.5, volts are 117.6 FMT$ = “current is ##.###^^^^ at ##.####^^^^ volts” Current is 2.350E+01 at 1.1760E+02 volts • additional strings can be added • FMT$ = “current is & ##.###^^^^ at ##.####^^^^ volts” • curType$ = “direct” • PRINT USING Fmt$; curType$; cur; volts Current is direct 2.350E+01 at 1.176E+02 volts

More Related