HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
INTRODUCTION TO PROGRAMMING BASIC PROGRAMMING TECHNIQUES BY
FALANA TAYE FREDRICK B.Sc.Ed (Computer Science)
ADEKUNLE AJASIN UNIVERSITY, AKUNGBA AKOKO, ONDO STATE, NIGERIA.
Volume 1.
qQ QBasic Programming By Falana Taye Fredrick
Page 1
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
© Copyright, HEADWORLD TECHNOLOGY TRAINING CERTIFICATION (HTTC). All rights reserved.
qQ QBasic Programming By Falana Taye Fredrick
Page 2
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
ABOUT THIS BOOK This book “Introduction to Programming, the QBasic programming techniques” was written by Falana Taye Fredrick B.sc.ed (Computer Science). The main aim of the book is towards adequate and effective programming skills using QBasic language as a basic case study.
ABOUT THE AUTHOR This is a free version of the book, to know more about Falana Taye Fredrick, the author of “Introduction to Programming, the QBasic programming techniques”, kindly use this link. The author google page www.google.com/+falanatayefredrick Or the author research page www.ajasin.academia.edu/falanatayefredrick
DEDICATION This free version is dedicated to all friends irrespective of the distance.
qQ QBasic Programming By Falana Taye Fredrick
Page 3
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
WHAT TO KNOW BEFORE QBASIC PROGRAMMING TECHNIQUES This tutorial was written in 2016 after the Valentine events that took place at Headworld Technology Ibiono-Ibom, Akwa-Ibom State, Nigeria as part of a gift the author promise to give out. For QBASIC, Although many programmers see it as a waste of time learning it but this has been proven wrong. QBasic is a good starting for newbie to learn how to codes also it’s a language that will help advance programmer to make use of fast on code app because QBasic have changed between then and now, but the fundamentals still remain the same. It is still a good way to learn BASIC, and is a good launching point to go into Visual Basic. The language now contains objects (and the methods, events, and properties that go with them), there are over twice as many data types (Boolean, which was needed a long time ago, as well as new numeric types), the LET keyword is now obsolete, the GOTO keyword is now considered obsolete (although these 2 do still work), GOSUB and RETURN are obsolete, line numbers are gone (They were optional, but still supported in QBASIC), no more BSAVE or BLOAD, PEEK, POKE, INP, OUT, KEYn Function key support, KEY ON and KEY OFF, LOCATE, INKEY$, and WAIT are just some of the functions that are no longer part of BASIC (mostly because they are DOS-dependent). As far as LET being obsolete, you still assign variables the same way, you just don't put the word "LET" in front of it any more. Instead of LET MYAMOUNT = 75 You simply use MYAMOUNT = 75 Just get your mind at ease as you surf out this tutorial, it’s going to be fun and by the end of the lesson, you will be able to start developing executable app in-fact marketable app. something related to the app we develop on the 14th Feb, 2016 (Valentine app).
qQ QBasic Programming By Falana Taye Fredrick
Page 4
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Once again, I Welcome you to the programming world, let’s get the code started! ENJOY!!!
qQ QBasic Programming By Falana Taye Fredrick
Page 5
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Chapter One Getting Started KeyWords: PRINT, LET, END, CLS Starting QBASIC To fully utilize the QBASIC system with all the options makes it quite a complex command. Here is the command in full: QBASIC /B /G /H /MBF /NOHI /RUN [filename] I know you're thinking "How in the world am I going to remember all that?" Well, do we have some good news for you! We will now tell you the slightly easier way to start QBASIC. QBASIC By the way the Q in QBASIC stands for QUICK. QBASIC was derived from Microsoft's highly successful and incredibly powerful QUICKBASIC compiler series. QUICKBASIC has many more capabilities than QBASIC, and allows much larger programs to be written, including easier interfacing with other high-level languages (such as C, C++ and Java) and low-level languages (like MACRO ASSEMBLER). I have even combined all three of those languages into a single program using QUICKBASIC. It can't be done with QBASIC. Let's take a look at what is on the screen. At the top, you have a line of words. This is the menu system. We will be using it very shortly. Most of the rest of the screen is blue, except for that white box in the middle that says Welcome to MS-DOS QBasic, and gives the copyright notice. Press the ESC key to clear this box.
qQ QBasic Programming By Falana Taye Fredrick
Page 6
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
(To get the QBASIC compiler, google it out or you purchase the full version of this book, it is included in the package, to get the package, kindly make use of the link www.ajasin.academia.edu/falanatayefredrick and click the instruction or try to contact the author of this book). From the interface, you will see that the screen is divided into two sections. The top section has a title above it that says Untitled. This is where the program name will appear when you are working on a program. The bottom window has a title of Immediate. We will be using this section when we write and test programs. The very bottom line shows a handfull of function key shortcuts, and your cursor position. Hmmmm… enough of English chatter, let's get this computer to do something interesting!!! Yes, it's time already to learn our first command!!! What is it, you ask? Well, it' the (drum roll, please....) PRINT command!! Can you guess what it does? Well, let's try it and see. First, press the F6 key until the word Immediate (near the bottom of the screen) is highlighted. That will allow us to type in QBASIC commands directly. Type in the word PRINT (It can be in upper or lower case - the computer doesn't really care) and press the Enter key. Oops! It looks like we are viewing the screen that we had when we entered our QBASIC command! In fact, we can still see the command we entered, with a line at the bottom that says Press any key to continue. Go ahead and press any key, and you will be back in the QBASIC environment. Let's get this thing to do something a little more fun. Now type PRINT “HELLO FRIEND” and press ENTER. Notice that there is now a HELLO FRIEND at the bottom of the output screen? That's because we used the print command to print the HELLO FRIEND. Let's recap. You told Mr. Computer to print HELLO FRIEND. What did it do? It printed the HELLO FRIEND on the output screen! Wait, it gets better. Now First Exercises: Write a QBasic program that will display i.
Your Name
ii.
Your Address
iii.
Your age
iv.
Your Email Hope you get it right? Yeah! It will look like
qQ QBasic Programming By Falana Taye Fredrick
Page 7
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Print “My name is: Falana Taye Fredrick” Print “I currently live at Ibiono-Ibom, but I’m from Owo, Ondo State, Nigeria.” Print “I am 18+” Print “My personal e-mail is
[email protected]”
The output screen for the above program will look like this:
LET To use variable, to store data temporarily for use, to manipulate data, you need variable. What is variable? Variable is a memory storage location or a particular address. The name giving to variable is called an identifier.
qQ QBasic Programming By Falana Taye Fredrick
Page 8
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
For QBasic to actually know that you are working on variable, to create a variable and assign a value to such variable, you make use of keyword LET follow by the identifier. Example LET Age = 15 and then press the ENTER key. Hmmmm, It didn't show us the output screen this time. That's good! That means that QBASIC understood the command that we typed in, and acted upon it. Now type in: PRINT Age Look at that! It printed out the number 15! Let's try to change the value of Age. Type: LET Age = 19 No response - good. Now type PRINT Age
You should get a 19 on the output screen. Neat, huh? We can use the same variable name to represent different things! Of course, when we told Age to store the value of 19, it threw out the previous value of 15. A variable can only hold one thing at a time. If you tell it to hold something new, it has to let go of what it was holding before. It only has one hand, you know! Now we start to cook. Here we are going to use three numeric variables, and a math function. Type in this series of lines (press Enter after each line): LET FIRST = 9 LET SECOND = 6 LET ANSWER = FIRST + SECOND PRINT ANSWER Did you get what you expected? If everything went correctly, there should be a 15 on the output screen. Let's explore what just happened. The first two lines you should be familiar with. The variable FIRST was assigned a value of 9. The variable SECOND was given a value of 6. The variable ANSWER was then given the value of SECOND added to the value of FIRST (6+9 in this case). Then the value of ANSWER was printed. That third line is where the power of computer programming begins to become apparent. You can put this line in a program, and it will add whatever those two variables (FIRST and SECOND) happen to be at the time. Let's look a little closer at the third line. QBASIC operates on the LET command by solving any math problems that is to the qQ QBasic Programming By Falana Taye Fredrick
Page 9
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
right of the equal sign using the standard Algebraic Order of Operations. If pain persists, see your mathematician. It simplifies this expression down to a single value, and (assuming no errors like dividing by zero) assigns it to the variable on the left side of the equal sign. There can only be one variable on the left side of the "equation", and no math operators. It can only be a single variable. However, you can have a highly complex formula on the right side of the equation. As long as it can be reduced (or solved) to a single number, anything is fair game on the right side of the equal sign! Now let's get right into some real programming. All we have been doing so far is using QBASIC's "immediate mode". What that means is QBASIC performs the command we type in immediately after we press Enter. The other mode of QBASIC is (can you believe it?) the "Program mode". In the program mode, the instructions or commands we type in are not performed as we enter them, but instead are stored in the computer's memory as a program. After we get the program entered into the memory, we can then execute the program at a high rate of speed. How do we get into the program mode? Press the F6 key until the word Untitled (at the top of the screen) is highlighted. You will also see the cursor (that flashing underline thing) jump up to the program window. Now type this in: LET FIRST = 14 LET SECOND = 8 LET THIRD = FIRST + 6 LET ANSWER = FIRST + SECOND + THIRD PRINT ANSWER END Let's go through this line by line. Lines 1, 2, and 5, you have seen before. However, the third line looks a little different. It is straightforward, however. It adds 6 to the current value of FIRST (14 in this case) and assigns it to the variable THIRD. The fourth line simply adds the values of all three variables and assigns it to the variable ANSWER. Incidentally, all the variables that are on the right side of the equal sign in a LET command are not altered. In other words, the FIRST, SECOND, and THIRD in line 4 do not change or lose their value when the line is executed. The 6 in the third line is called a constant. That is because its value doesn't change when you run the program. QBASIC allows you to define words as constants so that the language becomes more symbolic. For example you could just type in PI instead of 3.14159 every time you needed that value. We'll show you how in the Advanced series.
qQ QBasic Programming By Falana Taye Fredrick
Page 10
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
END The last line contains a new command, END. It obviously is the end of the program. If there happens to be more program lines after the END command, they are not executed, because END tells the computer to stop. Simple, really, Now we need to tell the computer that we want this program to run. How do we do that? Take a look at the very bottom of the screen. Notice that it tells us that the F5 key is a shortcut key to run the program. Go ahead and press F5 to run it. Oh, look! You get a 42 as a result. Can you figure out why? Right! FIRST is 14, SECOND is 8, and THIRD is 20 (14+6). Add the three up, and you get 42. Now it is your turn to write a few programs. If you want to do more than add, here are a few more operators: Addition is "+" Subtraction is "-" Multiplication is "*" Division is "/" To erase the existing program so that you can start with a new one, select the File menu either with the mouse (by clicking on it) or the keyboard (by pressing Alt-F). Then from the pulldown menu, select New either with the mouse (by clicking on it) or the keyboard (by pressing N). You will get a box asking if you want to save the changes. We really don't need to save this, so answer No. You will then be presented with a clean slate. CLS This is a keyword use to clear screen of the output interface in QBasic. The CLS will clear any previous QBasic codes output and start a new (fresh) execution but not terminating the execution of such programming. CLS Print 56 Print “The 56 will be wipe from the screen including this text now” CLS Print “lols… it’s fun here again”
Exercise: Develop a Basic application that solve the following equation where a = 10, and b = 4. i.
Y = a + b – 2b
ii.
X = 54 / 5
iii.
qQ QBasic Programming By Falana Taye Fredrick
Z=Y+X
Page 11
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Chapter Two Variable and Data Type Hi, before we get into the variable and data type and some other stuff that this chapter will entails, let us look at a glance some of the QBasic basic syntax and procedures, i.e. what makes a QBasic. The form of a QBasic Code i.
Each of QBasic statement must be on a line
ii.
Each statement must be proceeded by a number referred to as the line number
iii.
Line numbers must be positive and a whole number
iv.
Line numbers must be such that a new number can be inserted at a later stage without affecting the sequence of the program
Please this is not a set of new QBasic rules but the norm of the QBasic, it is as simple as its name implies QBASICs (Quick Beginners All-Purpose Symbolic Instruction Codes).
VARIABLE We have defined variable in our previous chapter, but we will explain it in full details in this chapter. Variable is a name of a location in the computer memory where a number or a string is stored. In other words, variable hold information. Whenever a variable is declared, QBasic sets up an area in the computer’s memory where the information will be stored. Note that the name of a variable is called an identifier i.e. an identifier is a variable name while variable is a storage location. Variables in QBasic can be classified into two groups i.
Numerical variables
ii.
String variables Let us look into this type of numerical variables
i.
Numerical : A numerical variable consists of digits. Two types of numerical variables commonly used in QBasic are Integers and Single-precision numbers. An integer numerical variable has no decimal points. If the last character in the variable name is %, then the number stored is an integer. If the last character in the variable name is !, then the number stored is as a single-precision number.
qQ QBasic Programming By Falana Taye Fredrick
Page 12
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Examples: MyFact% is an integer variable MyFactval! Is a single – precision variable. ii.
String: A string variable is the name of a location or store in the computer memory where a string data or values are stored. We generally declare variable as string with the symbol $ at the end of the variable name. Example of a string variable is Myname$, OurAim$ e.t.c.
RULES FOR FORMING QBASIC VARIABLE NAMES As a programmer, there are rules to understand, part of such rules is on how to form a variable name. In QBasic, here are some of the rules that govern the formation of variable name. a. All variable names must start with a letter of the alphabet from A to Z b. No special symbols or characters or QBasic keywords must be used as variable name. c. If more than one variable is used in a program, each variable name must be different i.e. you cannot name two different variables the same. d. Upper and lower case are different variable name. Example variable name MyName is different from variable name myname. e. Variable names should be kept short and meaningful so as to remember what they hold or represent. For example: age, amount, salary, tax, weight, height, bonus e.t.c are good variable name. These kind of variables names should be avoided a, b, c, d, x, y, z. This is because it does not convey a meaningful variable name for others who will need to read your codes.
QBasic Data Type One of the keys to a successful and enjoyable programming experience is a thorough understanding of data types. Programming is associated with manipulation of data. The data comes in different types, QBasic does not have too many data types. We have tried to explain a few data type that will be most often used by QBasic programmers. a. INTEGER Integer variable hold integer values. The range of values that the integer variable can hold is relatively small (-32,768 to 32,768). Note please that a good way of making
qQ QBasic Programming By Falana Taye Fredrick
Page 13
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
sure that a variable will only hold integer values is to place the percentage (%) sign at the end of the variable name. Examples of integer variable i.
Mycounter%
ii.
Age%
iii.
YourValue%
b. LONG INTEGER Long integer variables hold relatively larger (-2,147,483,648 to 2,147,483,648 ) values. Long integer variables are indicated by the ampersand symbol (&) behind the variable name. Examples of Long Integers: i.
Amount&
ii.
Salary&
iii.
Income&
c. SINGLE PRECISION The single precision level or type of data types depend on accuracy power. Just like integers that have two types, also, number with decimal points have two variable types. The least accurate is called single precision. They are accurate to only seven digits. To make sure that a variable holds only single precision values, the exclamation mark symbol ( ! ) is added to the variable name.
Example of Single Precision Variables i.
Allowance! = 17.900
ii.
Bonus! = 4.600
d. DOUBLE PRECISION This data type is applicable when a number with as many as sixteen places of decimal values is needed. Double precision variables are mainly used in scientific calculations. To force double precision on a variable, a hash symbol ( # ) is added to the back of the variable name. Examples of Double Precision Variables i.
MyValues# = 43.90
Note please that: a. The QBasic will assume the programmer means 43.9000000000 qQ QBasic Programming By Falana Taye Fredrick
Page 14
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
b. The computations or data manipulation involving double precision data types are often slower than those requiring integer data types.
e. CONSTANTS Like any other programming language, QBasic allows you to declare a constants value. A value is constant if its value will not change in the course of programming executions. Think of value of PI (i.e. 3.17), Body temperature value, boiling point, freezing point value e.t.c as constant. To declare a variable as constant, the CONST keyword is use. Examples of Constant variable CONST pi = 3.17 Also, a string value can be declare as a constant value. Assuming I want to make use of the statement “Success, you are Great” in almost different point of my program. I will declare a string constant as CONST msg = “Success, you are Great” Print msg
PRACTICE i.
Declare a variable name that will hold an integer values, string values and long integer values.
ii.
What is the difference between integer and single precision variable declaration in QBasic programming language.
iii.
How do we declare a constant value?
iv.
Differentiate between variable and an identifier.
qQ QBasic Programming By Falana Taye Fredrick
Page 15
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Chapter Three Commenting, Line Numbering, Statement, Expression, and Arithmetic operations. QBasic Commenting Comment in QBasic simply means that a particular or series of line of codes that QBasic compiler will not execute but are used to explain the purpose of such line of code segment. In QBasic, REM (Remark) is used for comments or program heading. Example: 10
REM This program calculates the sum of odd numbers between 1 and 100
20
REM Author: Falana Taye Fredrick.
30
REM updated today Saturday 20th, 2016.
The output screen is blank as shown below:
qQ QBasic Programming By Falana Taye Fredrick
Page 16
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
QBasic Line Numbering QBasic line numbering is a techniques or act of using integer number to represent a line of code statement. A typical example of line numbering can be seen in our previous example, 10 above represent line number 10, and it is a remark statement saying “This program calculates the sum of odd numbers between 1 and 100”. Also, line 20 is also a remark statement which tells little about the author of such program.
QBasic Statement QBasic like any other language has its own statement. Here, we will discuss on inputting statement, outputting statement, Assignment statement, and Goto statement. Before I discuss with you the QBasic inputting statement, please note that DIM statement is used to explicitly declare the type of data that a particular variable will hold or store. Note: DIM statement is use to explicitly declare the data type of a variable. Example 10
REM this program will explain the use of explicit and implicit variable declaration
20
REM please make sure you understand what the code says
30
CLS
40
DIM age as Integer
50
Print “You are welcome to Qbasic Age Detector program”
60
input “Enter a Non-negative or Non-Zero value and press ENTER ”,age%
qQ QBasic Programming By Falana Taye Fredrick
Page 17
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION 70
if number% = 0 then
80
CLS
90
Goto 50
100
endif
110
Print “Your age is: ”, age%
Complete Version @ $8.9 Only.
The above QBasic program will accept value from users, how? Line 10 and 20 are comment statement, it’s just telling us the purpose of the program that’s why we make use of REM, the line 30 of the program is CLS meaning clear screen (in case there is output that is not needed, it is advisable to clear screen before you display information that will be needed), now line 40 declare age as an integer value using explicit mode of declaration DIM, remember this symbol % at the back of the variable age, it denotes integer value. Line 50 print a message and line 60 is used to capture data from user. Note that I make use of input statement, the QBasic make use of input to collect data from user, we will explain that later. Line 70 make use if control statement to check the value enter by user, we will talk on control statement later, line 80 is another clear screen statement, line 90 is a goto statement it’s used to jump to a particular line of code, line 100 is an end if which denote closing of an if statement, we will talk on that later. The last line 110 is use to print the output of the age to the user. QBasic Inputting Statement The input statement allows users of a program to enter value or data. QBasic uses the input statement to ask the keyboard for either a string or an integer values. Examples 1 10 input “Please enter your name ”; myname$; The above QBasic program will ask user to enter his or her name.
Example 2 5
REM this program will accept username and password and also display the data as information to the users.
10
CLS
15
input “Welcome to the App \n Kindly type in your Username: ”,username$
20
print username$
25
input “Enter your Password: ”, password$
30
print “Your username and password is ”,username$+ “ and ”+ password$
qQ QBasic Programming By Falana Taye Fredrick
Page 18
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
The output is
Exercise: Develop a QBasic program that will accept and also output the name, age, sex, address and email of users. QBasic Assignment Statement The assignment statement (=) is used to assign a value, data, string or message to a particular variable. The following keywords are essential while dealing with assignment qQ QBasic Programming By Falana Taye Fredrick
Page 19
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
statement in QBasic. The LET, a numerical variable, the symbol (=), and a mathematical expression. Example 5
LET Myvalue = 256
10
AnotherValue = Myvalue + 5
The LET statement above tells the computer to calculate AnotherValue which store the value of Myvalue variable with addition of 5. The keyword may be omitted, it is optional. Also, LET statement can also be assign a string to a string variable. Example 1
LET password$ = “Head”
2
LET username$ = “code_Basic”
3
Myvalue% = 20
4
AnotherValue! = 39.67
QBasic Expression Expression is the assignment of the combination of operands and operators. You will learn about operators when we get to Qbasic arithmetic operations. Example 1
Y=2+2
2
Print Y
Note: we say line 1 is an expression because it comprises the variable Y, assignment sign and the values. It can be combinations of values and variables.
QBasic Arithmetic Operation In QBasic, the arithmetic operations is done in the following order: S/N
OPERATORS
SIGN
i.
Parenthesis
( )
ii.
Exponential
^
iii. Multiplication and Division
* /
iv. Integer division
\
v.
Remainder after integer division
vi. Addition and subtraction qQ QBasic Programming By Falana Taye Fredrick
+Page 20
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
QBasic Relational Operators Relational operators in QBasic are used when decisions are to be made. They are useful when making comparisons whether of strings or numeric qualities. Operations involving relational operators are called logic operations. The elements of quantities being compared are referred to as the operands. S/N
OPERATORS
SIGN
i.
Equal to
=
ii.
Greater Than
>
iii. Less Than
<
iv. Greater Than or Equal to
>=
v.
<=
Less Than or Equal to
vi. Not Equal to
<>
QBasic Logical Operators QBasic programming supports the logical operators. They are AND, OR, NOT.
S/N i.
OPERATORS
MEANING
AND
It will return the TRUTH if and only if all the variables involve are true.
ii.
OR
iii. NOT
It will return the TRUTH if any of the variables involves are true. The result is based on the inverse effect of the variable(s).
THE QBASIC EXAMPLES
A.
Write a QBasic program to store your personal details and also output the result on the screen.
1.
REM This program will accept and output the details from user
2.
REM Program by HEAD
3.
CLS
4.
DIM name AS STRING
5.
DIM day AS INTEGER
6.
DIM month AS STRING
qQ QBasic Programming By Falana Taye Fredrick
Page 21
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
7.
DIM year AS LONG
8.
CLS
9.
input "Enter your Full Name: ",name
10.
print name
11.
input " please what day were you born: ",day
12.
input "What month were you born: ",month
13.
input “What year were you born: ”, year
14.
print" Your name is: "+name
15.
print "\n You were born on this day: ",day
16.
print "\n Your birth month is: ",month
17.
print "\n Your birth year is ",year
Complete Version @ $8.9 Only.
B. Write a QBasic program that will calculate the area and perimeter of a rectangle. Your application MUST collect data from users and MUST be user friendly. Solutions: 1
REM This program calculate the area and perimeter of a rectangle
2
cls
3
Input "Enter the length of the rectangle ",length%
4
Input "Enter the breath of the rectangle ",breadth%
5
Area = length% + breadth%
6
perimeter = 2 * Area
7
print "The Area of the rectangle is ",Area
8
print "The Perimeter of the rectangle is ",perimeter
qQ QBasic Programming By Falana Taye Fredrick
Page 22
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
The output screen is
C. Write a QBasic program with LET statement to calculate the perimeter and the area of a rectangle whose length is 12 feet and width is 7 feet. Output the perimeter and the area with appropriate messages. Solution 1 REM This program calculate the area and perimeter of a rectangle 2 REM This program make use of LET statement 4 REM LENGTH is 12 feet and WIDTH is 7 feet 5 cls 6 length% = 12 qQ QBasic Programming By Falana Taye Fredrick
Page 23
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
7 width% = 7 8 area = length% + width% 9 perimeter = 2 * area 10 print "The Area of the rectangle is ",area 11 print "The Perimeter of the rectangle is ",perimeter
The output screen for this program is
qQ QBasic Programming By Falana Taye Fredrick
Page 24
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
Exercises 1. Develop a QBasic Application that will tell your friends what they like base on their inputting choice. 2. Develop a QBasic application that will accept username and password, the system should then display a welcome or notification message to the user of such system 3. Write a program that will accept four (4) different values, then calculate and print out the sum, difference, multiplication, division, and modulus value of the four different values inputted. 4. Write a program that will accept integers data from user and will calculate the following mathematical equations on such problem: i.
𝐴 = 𝜋𝑟 2
ii.
𝑥=
−𝑏±√𝑏 2 −4𝑎𝑐 2𝑎
iii. √𝑎2 + 𝑏 2
qQ QBasic Programming By Falana Taye Fredrick
Page 25
HEADWORLD TECHNOLOGY TRAINING CERTIFICATION
Complete Version @ $8.9 Only.
YOU’VE ENJOY THE ONE-FOUTH OF THIS BOOK FREE OF CHARGE. To get the full package on how to develop any form of application using this QBasic programming language, you need to get the complete version of this book. You have more than 10 chapters to learn on with QBasic and each chapter has different examples which talk about real life problems and also with exercises that you can use the strategical ways to solve and this will help you to become the most programmer of all time. Also, Inside the complete version of this book, you will learn Decision making and how to control the flow of programs. You will learn how to manipulate data of different format, how to convert data type and how to use QBasic functions. You will learn how to develop runnable functions that other developers or programmers will be using. You will learn arrays and how to create QBasic files. You will learn how to write virus, anti-virus, do ethical hacking and how to control system resources like memory usage, CPU usage and other external resources. Lot more entails in it. Also, the complete version of this book comes with the QBasic software needed to carry out any task.
HOW TO GET THE FULL VERSION OF THIS BOOK Send a notification message to the author on
[email protected] or call the author on this line +2348060423371 and +2347013879525. The Book price is $8.9, all payment should be made directly to the author personal bank account with this detail:
Account Name:
Falana Taye Fredrick
Account Number:
3021177044
Bank Name:
Skye Bank
Note: Please after payment, ensure you send instant notification to the author on your purchase; your book will be mail to you after 10 minutes of payment confirmation. Also, if by the end of your payment you find out that the book does not really worth it, the author has promise to refund the money with an interest rate. This is to let you know the authentication of this book. Visit the author research page via www.ajasin.academia.edu/falanatayaefredrick or the google page of the author via www.google.com/+falanatayefredrick qQ QBasic Programming By Falana Taye Fredrick
Page 26