|
Classes
|
Qbasic is a programming language. Programming languages are used to create operating systems, applications programs such a Word, Excel, Access, PowerPoint, FrontPage, Publisher, and Telecommunications programs. Everything that we do with a computer must first be written in a programming language. The first programming language developed is called machine language which is written with 1 and 0. This language is often referred to a binary or digital language. This language required the programmer to give step by step instructions for each action in binary code. Computers only understand machine language. The second level programming language is called assembler language.
This language allowed the programmer to use alphabet characters such as MV (which
means move) that will be translated by the program into machine language. Two
methods are used to translated a programming language into machine
language. The third level programming languages (Higher Level) consisted of languages that were closer to natural languages. Cobol, RPGII, Qbasic, Pascal, C, C+++, Fortran are examples of third level languages. These languages allow you to use English words such as print, input, and read to write program code. The fourth level languages are the visual languages such as Visual Basic and Visual C+++. These are also called Object Oriented Programming languages because they attached code to objects (icons/visual pictures). Windows 98 was written using OOP. The fifth level languages are the voice actuated languages. Windows Office XP comes bundled with voice actuation and writing pad actuation. All computer languages operate within the Structured Theorem parameters which allow the solving of programming problems with: 1. Sequencing in which code is executed line by line from
top to bottom. All computers execute code starting at the top of the
program and continue to the bottom (end) of the program code.
3. Iteration (looping, repetition) in which a branch of code is executed over and over while a condition is true. The control structures are Do While-Loop,- Do Loop Until, and For, Next for iteration statements. DO [{WHILE | UNTIL} condition] FOR counter = start TO end [STEP increment] SELECT CASE testexpression An important part of programming is the use of RAM (Random Access Memory). In machine and assembler languages use of RAM was accomplished by stating the hexadecimal address in which information was to be stored. Every time a byte of information was used, or data was derived from stored data the hexadecimal address had to be referenced to find the data and to store the derived data. In Qbasic we only have to declare a variable or constant name, specify the data type and Qbasic like all higher level languages keeps track of the hexadecimal address in memory of the data for us. A variable name must begin with a alpha character and can have up to 40 characters in the name. The period or alpha characters or numbers can be used in a variable names. When you identify variables always make the name logical. For example: FirstName$ instead of fn$. Variable - a variable name represents a location in memory where data will be stored that may or may not change during program execution. Constant - a constant name represents a location in memory where data will be stored that will not change during program execution. Qbasic supports two variable and constant data types: 1. Alpha Numeric (also called a string) is represented by a $ sign at the end of the variable or constant name. This data type can store Alpha characters and numbers in memory. If you have numbers such as SSN, PartNo., InvoiceNo. ,etc. that will not be used in calculations (added, subtracted, multiplied, or divided) then make theses numbers an Alpha Numeric variables or constants. For example: Firstname$, City$, State$ and SSN$ are all alpha numeric variable names. When a variable or constant is declared the data type must also be declared. By declaring the data type Qbasic sets up the address in memory to receive the specific data type. 2. Numbers are represented by !,%,# and & at the end of the variable or constant name. ! - single precision numbers are 4 bytes For example: if you wanted to initialize a variable for a persons age using an integer would be appropriate since all human fall between the age of 0 and 200 years. let Age% = 0 or These two statement are identical in the operation performed which is to identify a hexadecimal address in memory to store data that is an integer and to enter a 0 into that memory address. When you initialize variables, numeric variables are initialize to 0 and alphanumeric variables are initialized to " ". let FirstName$= " " or Constants are initialize to the value of the constant. FedTaxRate!=.037 or Note: Let statements use the = sign to assign to the memory address the data to the right of the =. It is not an equality statement. For example: profit! = retailprice!-cost! PRINT - outputs to the screen each print line. LPRINT outputs to the printer each lprint line. For example: Print "Hello" outputs to
the screen Hello. To place the text at a specific column on the 80 column
screen the Tab() function can be used. For example: If you use a for next loop to print out hello five times by changing from , or ; or : following the word hello will provide different output. For example: for x = 1 to 5 will output The : or nothing at the end of a print statement forces the next print statement encountered down one line. for x = 1 to 5 will output The ; at the end of the print statement forces the next print statement encountered to print on the same line immediately after the last print statement. for x = 1 to 5 will output: If we want to format the output of the print statement we can use print using. For example: If pay is 4567.89 Print using
"your net pay is $$###,###.##"; pay The # signs are place markers for the digits. The two $$ signs force the $ to float up against the first occupied digit. If only a single $ is used then the $ will be placed at the first place marker. For example: Print using "your net pay is $###,###.##"; pay Data can be entered into a computer program three different ways. 1. Data can be stored in the program code itself by using the Read and Data statements in Qbasic. READ firstname$, age%, income! When you use the read statement there must be the same number of data elements in the data statement, in the same order, and the same data type: often referred to as the NOT rule. 2. Data can be input from the keyboard and other input devices using the Input statement directly into a variable. Input "Enter your first name"; firstname$ 3. Data can be input from data files stored on floppy drives, hard drives and CD's by using the open files statements. Open
“a:\test.txt for
Append - Add records to the bottom of the file. Open
“a:\test.txt” for append as #1 Or Open
“a:\test.txt” for output as #1 Or Open
“a:\test.txt” for input as #1 Note: when you write data to a file to input the data back into main memory you must follow the NOT rule. Functions:
Problem: We have formed a company called cheap student labor and have to write a payroll program that will allow us to enter from the keyboard employee name, Social Security Number, address, city, state, zip, number of hours worked, date hire, payrate, and pay dates. Additionally we need to produce a payroll stub that includes current and year to date hours worked, regular, overtime, and double time and pay for each, federal income tax, state income tax, Social Security tax, state disability insurance, gross pay, net pay. Additional the pay stub will have check no., Company name, address, city, state, pay period from and to dates, date check was written, employee name, ssn, address, city, state, zip. Furthermore the program must be menu driven with one entry point into the program and one exit point and the data is to be stored on magnetic disk. Last we are to produce both detail internal documentation of the program and a users Manuel. The first thing that we do to solve this problem is to define what the output is going to be. Once we know what the output is going to be we can then determine what we have to input into the program, what processing of the raw data must be done, and last formatting the output in a form the user can understand. Input - Processing - Output is the sequencing the program must use to be successful. Fortunately, we have a Qbasic program template to use for this purpose. REM REM Date REM Instructor Name REM Assignment Chapter Number Page REM REM Statement of problem : REM Analysis IPO. REM REM Data Requirements REM REM Constants REM REM Inputs REM REM Outputs REM REM Variables REM REM Formulas REM REM Design REM REM Algorithm REM REM 1. REM 2. REM 3. REM 4. Etc. REM REM Implementation - here you begin to code. CLS Rem Initialization Section This is where we state our variables. REM Input Section REM Processing Section REM Output Section We also have a template that we can use to set up a menu with that will have one entry point into the program and one exit point. CLS
MenuOption = 0
DO WHILE MenuOption <> 7
PRINT
PRINT
PRINT " M E N U"
PRINT "----------------"
PRINT "1. OPTION 1"
PRINT "2. OPTION 2"
PRINT "3. OPTION 3"
PRINT "4. OPTION 4"
PRINT "5. OPTION 5"
PRINT "6. OPTION 6"
PRINT "7. EXIT PROGRAM"
PRINT
INPUT "YOUR CHOICE =>"; MenuOption
SELECT CASE MenuOption
CASE IS = 1
PRINT
PRINT "You selected option 1."
CASE IS = 2
PRINT
PRINT "you have selected option 2:"
CASE IS = 3
PRINT
PRINT "You selected option 3."
CASE IS = 4
PRINT
PRINT "You selected option 4."
CASE IS = 5
PRINT
PRINT "you have selected option 5"
CASE IS = 6
PRINT
PRINT "You have selected option 6"
CASE IS = 7
PRINT
PRINT "Thank you for using this program."
CASE ELSE
PRINT
PRINT "Invalid Menu Option"
END SELECT
LOOP
END
Since we will be interacting with the monitor we have format part of our program to deal with a monitor screen that is 80 columns wide by 21 rows (the same as the original keypunch card) and our printer output is is 80 columns by 66 rows. When ever you send data to the screen you want to clear the screen for your output which is done using the cls statement. Mathematical Order of precedence for evaluating expressions/formulas.
|
|
Copyright © by Earl T. Wylie 2001, 2002,2003,2004,2005,2006,2007 |