DEFINITION OF DATA TYPE
- A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer. Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.
OPERATIONS OF DATA TYPE DURING PROGRAMMING
With object-oriented programming JAVA, a programmer can create new data types to meet application needs. Such an exercise as known as "data abstraction" and the result is a new class of data. Such a class can draw upon the "built-in" data types such as number integers and characters. For example, a class could be created that would abstract the characteristics of a purchase order. The purchase order data type would contain the more basic data types of numbers and characters and could also include other
object
defined by another class. The purchase order data type would have all of the inherent services that a programming language provided to its built-in data types.
Languages that leave little room for programmers to define their own data types are said to be strongly-typed languages.
OPERATIONS OF DATA-TYPE IN QBASIC:
The computer can hold data in memory. The programmer must tell the computer what type of data to hold. This is called a data type.
Data Types in QBasic:
String.........Text and characters
Example of a String Data Type: This line is an example of a string
Integer.......Non-floating-point numbers from -32,768 to 32,767
Examples of an Integer Data Type: 67, -34, -100, 203, 1022, -1, 0
Long..........Non-floating-point numbers from -2,147,483,648 to 2,147,483,647
Examples of a Long Data Type: 560005, 3, -2, 0, -867000, 14, 8, -10
Single........Floating-point numbers from -3.37x10^38 to 3.37x10^38
Examples of a Single Data Type: 4.3, 25.4567, -35.87, 0.35, -3.14
Double......Floating-point numbers from -1.67x10^308 to 1.67x10^308
Examples of a Double Data Type: 745663.90596, -98.12, 4859903.094491
It is possible to make your own data type, but we are not going to cover how to do that until later in this tutorial series.
Variables:
Variables are a name that is given to the data. The name must not start with a number or character that is not a letter. Also, the name of the variable must not be a reserved name like
PRINT, INPUT, LET, ABS, BEEP, etc.
There are two ways to declare a variable in QBasic. The first is to put a data type symbol after the name
$ String
% Integer
& Long
! Single
# Double
The flowing program gives and example of declaring variables.
CLS
Header$ = “This is an example program on declaring variables”
Num1% = 5
Num2% = 6
Num3& = 45000
Num4& = 54000
Num5! = 4.5
Num6! = 6.76
Num7# = 56000.25
Num8# = 89000.34
PRINT Header$
PRINT Num1% + Num2% +Num3&
PRINT Num6! / Num5!
PRINT Num8# + Num2%
PRINT Num4& / Num1%
The output will be:
This is an example on declaring variables
45011
1.502222
89006.34
10800
Code Download: PROT4_1.BAS
Lets try the other way of declaring variables. This method should be used instead of the other method because Visual Basic and other BASIC languages tend to use this method. Becoming accustom to this way will help the transition from QBasic to Visual Basic. Create a new file and try this out:
DIM Num1 AS INTEGER
DIM Num2 AS LONG
DIM Num3 AS SINGLE
DIM Num4 AS DOUBLE
DIM Header AS STRING
CLS
Header = “This is another example program on declaring variables”
Num1 = 5
Num2 = 56000
Num3 = 45.635
Num4
No comments:
Post a Comment