BASIC Midterm

Card Set Information

Author:
anchorend
ID:
209305
Filename:
BASIC Midterm
Updated:
2013-03-25 20:02:48
Tags:
BASIC
Folders:

Description:
Cards to review for upcoming BASIC midterm.
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user anchorend on FreezingBlue Flashcards. What would you like to do?


  1. Define the difference between verification and validation
    • Verification: Are we solving the problem correctly?
    • Validation: Are we solving the correct problem?
  2. Identify the three types of Control Structures used in BASIC programming
    • 1. Sequential
    • 2. Selection
    • 3. Repetition
  3. Identify the 3 Most popular program design tools
    • 1. Flowcharts
    • 2. Pseudocode
    • 3. Top-down charts
  4. Identify the 5 Stages (Steps) in the program development process
    • 1. Analysis
    • 2. Design
    • 3. Coding
    • 4. Testing and Debugging
    • 5. Completing the documentation
  5. Numeric Variable Types
    • Integer- a number without a decimal point (its content is a while number).
    • Single-precision- a real number, has a decimal point and a fractional part.  Accuracy up to 6 decimal places.
    • Double-precision- same as a single-precision except accuracy is up to 14 places.
    • Unless you specify otherwise, QBASIC assumes that all variables are single-precision
  6. Numeric Variable Types
    • Integer %
    • Long Integer &
    • Single-precision !
    • Double-precision #
  7. Program data consists of variables and constants.
    • variable is data that can change as the program runs.
    • constant is data that remains the same during a program run.
  8. Numeric Variable Types
    • Suffix- placed at the end of the variable name to specify a specific variable type.
    • The variables N!, N%, N&, and N# are four different variables.
  9. The assignment of values to variables
    • [LET] variable = expression
    • Examples
    • LET age%=32
    • salary! = 25000.00
    • dependents% = 2
  10. Understanding the order of operators
    • 1. Exponentiation(^)
    • 2. Multiplication, division, integer division(*,/,) MOD
    • 3. Addition, subtraction (-,+)
    • If you want to override order of operators, use parentheses.
    • (2+3)*2=10
  11. String Variables
    • Same naming rules as numeric variables
    • -must begin with a letter
    • -cannot contain spaces
    • -difference is that a string variable must end with a $.
    • Examples:
    • MyName$ month$ CustomerCity$ X$ Address$
    • QBasic does not recognize a string variable as numeric.  Indicates that no math is to be performed with that data.
  12. Concatenating Strings
    • You cannot perform math on string variables even if they contain numbers.
    • You can perform concatenation.
    • Concatenation is attaching one string to the end of another or combining 2 or more strings into a longer string.
    • Example:
    • firstName$ = "Bill"
    • lastName$ = "Cole"
    • fullName$ = firstName$+""+lastName$
    • PRINT fullName$

    Bill Cole
  13. READ and DATA Applications
    • READ reads DATA values into variables
    • sales = 50000
    • 50000 is assigned to the variable called sales
    • READ sales
    • DATA 50000
    • The data value of 50000 is placed into sales when the READ statement executes.
  14. The RESTORE statement
    RESTORE restores the program pointer to the first data statement.
  15. Improved Use of INPUT
    • 'Filename: EXAMPLE.BAS
    • '
    • CLS
    • 'Prompt the user at the keyboard and input numbers
    • INPUT "ENTER 3 numbers, separated by commas ";num1,num2,num3
    • 'Calculate the average
    • avg=(num1 + num2 + num3)/3
    • 'Print the results
    • PRINT "The average of your three numbers is:"; avg
  16. The LINE INPUT Statement
    LINE INPUT [prompt message;] stringvariable

    • Allows users to input strings that contain commas without having to enclose the strings in quotation marks.
    • LINE INPUT allows input that contains quotation marks as part of the string.
  17. Functions are built-in routines that manipulate numbers, strings, and output.
    • All (for our purposes) functions have one thing in common, they are always followed by parentheses.  The value in these parentheses determine what the function does.
    • That value is called an argument.
  18. A function never stands by itself on a line; you always combine functions with other statements (assignment statements, output statements, etc...)
    • A function always returns a value.
    • -The output functions always perform a cursor movement.
    • -The numeric and string functions return either a number or a string.
  19. Integer Functions
    • INT()
    • -Returns the integer value of the number that you put in parentheses.
    • PRINT INT(8.93)
    • -Prints the return value of 8 onto the screen.
    • Note: INT() returns a whole number that is equal to or less than the argument in the parentheses.
    • INT() does not round up.
  20. Integer Functions
    • FIX()
    • -Returns the truncated whole-number value of the argument.
    • PRINT FIX(-8.93), FIX(-8.02)
    • -prints the following two numbers: -8 -8
    • For positive numbers FIX() and INT () work identically
    • For negative numbers FIX() and INT() return different values.  For the above example INT() returns -9 -9.
  21. Integer Functions
    • CINT()
    • -(Convert Integer)
    • -Returns the closest rounded integer to the value of the argument.
    • PRINT CINT (8.1), CINT(8.5), CINT (8.5001), CINT (8.8)
    • produces the following output: 8,8,9,9
    • For positive numbers -0.5 and below rounds down, otherwise it rounds up.  Negative numbers round to the closest negative integer.
  22. CLNG(
    -(Convert Long Integer)
    -For use when outside the limits of CINT()
    -32768 to 32767.
    • PRINT CLNG (-44034.1), CLNG (985465.6)
    • produces the following output:
    • -44034 985466
    • If you attempt to use CINT() to round off past its limits, Qbasic displays the error message Overflow.
    • CLNG () rounds integers between -2,147,483,648 to 2,147,483,647.
  23. Common Mathematical Functions
    • SQR()
    • -Returns the square root of its argument.
    • PRINT SQR (4), SQR(64), SQR (4096)
    • produces the following output:
    • 2, 8, 64
  24. Common Mathematical Functions
    • ABS()
    • -Returns the absolute value of its argument.
    • PRINT ABS(-5), ABS (-5.67), ABS (0), ABS (5), ABS (5.76)
    • produces the following output: 5, 5.76, 0, 5, 5.76
    • Whatever argument you pass to ABS(), its positive value is returned.
    • Absolute value is used for distances, accuracy measurements, age differences and other calculations that require a positive result.
  25. Common Mathematical Functions
    • SGN()
    • -Returns -1 if the argument is negative, 0 if the argument is zero, or +1 if the argument is positive.  The SGN() function determines the sign of its argument.
    • PRINT SGN(-86.5), SGN (0), SGN (301)
    • produces the following output:
    • -1, 0, 1
  26. ASCII String Functions
    • The ASC() and CHR$() Function
    • Examples:
    • PRINT CHR$ (75)
    • PRINT ASC('g')
    • prints the following output:
    • g
    • 75
  27. ASCII String Functions
    • The STRING$() Function
    • PRINT STRING$ (15,"a")
    • prints the lowercase letter a 15 times;
    • aaaaaaaaaaaaaaa

    • PRINT STRING$ (40, 43)
    • prints the following row of 40 plus signs;
    • +++++++++++++++++++++++++++++++you get the point
  28. String Conversion Functions
    • The LCASE$() Function
    •       UCASE$() Function
    • Example:
    • up$ = "HELLO"
    • lc$ = "goodbye"
    • mixed$ = "Hello, Goodbye"
    • PRINT LCASE$(up$), LCASE$(lc$), LCASE$(mixed$)
    • PRINT USCASE$(up$), UCASE$(lc$), UCASE$(mixed$)

    • hello     goodbye     hello,goodbye
    • HELLO     GOODBYE     HELLO,GOODBYE
  29. String Conversion Functions
    • The STR$() Function
    • -Converts the numeric variable, constant, or expression to a string.  If the number is positive, the string will have a leading space.
    • Example:
    • LET s$ = STR$(54.6)
    • PRINT s$

    54.6
  30. String Conversion Functions
    • The VAL() Function
    • Example:
    • s1$= "44 bottles"
    • n1= VAL(S1$) 'Ignores everything after the number
    • PRINT n1
    • s2$= "00012.5"
    • n2= VAL(s2$) 'Converts the string to a single precision num.
    • PRINT n2
    • 44
    • 12.5
  31. String Character Functions
    • The LEN() Function
    • -Returns the lenght of the string variable, constant  or expression.  LEN() counts the number of characters inside its argument.
    • Example:
    • PRINT LEN("abcdef")
    • produces
    • 6
    • Example2:
    • INPUT "Please type an answer"; ans$
    • IF LEN(ans$) = 0 THEN PRINT "You didn't type anything"
  32. String Character Functions
    • The LEFT$() Function
    • The RIGHT$() Function

    • Example LEFT$():           EXAMPLE RIGHT$():
    • a$="abcdefg"              a$="abcdefg"
    • PRINT LEFT$(a$, 1)     PRINT RIGHT$(a$, 1)   
    • PRINT LEFT$(a$,3)      PRINT RIGHT$(a$, 3)
    • PRINT LEFT$(a$, 7)     PRINT RIGHT$(a$,7)
    • PRINT LEFT$(a$, 20)   PRINT RIGHT$(a$,20)
    • produces:                   produces:
    • a                               g
    • abc                            efg
    • abcdefg                      abcdefg
    • abcdefg                      abcdefg
  33. String character functions
    • The MID$() Function
    • Example:
    • a$= "QBasic FORTRAN COBOLC Pascal"
    • PRINT MID$(a$ 1,6)
    • PRINT MID$(a$ 8,7)
    • PRINT MID$(a$ 16,5)
    • PRINT MID$(a$ 22,1)
    • PRINT MID$(a$ 24, 6)
    • produces:
    • QBasic
    • FORTRAN
    • COBOL
    • C
    • Pascal
  34. String Character Functions
    • The LTRIMS() Function
    •       RTRIMS() Function
    • -Trim spaces from the beginning or the end of a string.
    • -LTRIMS () returns the argument's string without any leading spaces.
    • -RTRIMS() returns the argument's string without any trailing spaces.
  35. Justify with String Statements
    • The LSET statment
    •       RSET statment
    • Example:
    • string1$= "1234567890"     '10 characters
    • LSET string1$ = "left"  'LSET "left" in 10 char.
    • PRINT "|"; string1$; "|" 'Print between lines to see result
    • string2$ = "1234567890"  '10 characters
    • RSET string2$ = "right" 'RSET "right" in those 10 char.
    • PRINT "|"; string2$; "|" 'Print between lines to see result

    • produces:
    • |left      |
    • |    right|
  36. Local variables pattern
    2 0 3 2 0 3 2

What would you like to do?

Home > Flashcards > Print Preview