Wednesday, April 6, 2011

CORRECTIONS FOR F.O.P MIDTERM EXAM  -
QUESTION 1: SECTION B

QUESTION 1: SECTION B

Variables
A variable is the storage location in memory that is stored by its value. A variable is identified or denoted by a variable name. The variable name is a sequence of one or more letters, digits or underscore.
For example: character _

Rules for defining variable name:
  1. Variable's name MUST be unique.
  2. Cannot be more than 31 characters.
  3. MUST begin with letters.
  4. NO space in between.
  5. Can't begin with numbers, symbols, or special characters.

DATA TYPES
  1. CHARACTER
·         Consist of all LETTERS, NUMBERS, and SPECIAL SYMBOLS.
·         Surrounded by SINGLE QUOTATION MARK (' ' ).
·         Example: 'A', 'm', '#', '1', or ' '.


  1. STRING
·         Combination of more than one character.
·         Surrounded by DOUBLE QUOTATION MARK (" " ).
·         Example: (" WELCOME TO MY PAGE") OR ("8876").

  1. LOGICAL VALUES/BOOLEAN
·         Making Yes-or-No decisions ( TRUE-or-FALSE).
·         Example: to check two integers using if… … else control structure.
Assume a=2 and b=5
If (a<b)

Decision is TRUE
Else
Decision is FALSE


  1. INTEGER
·         Whole POSITIVE and NEGATIVE numbers including ZERO and NO DECIMAL place.
·         Example: 0, +1, -10.
·         Used to represent the counting of things.
·         Example: Numbers of month in a year (1,2,3 …).


  1. FLOATING POINTS (FLOAT)
·         Contain all numbers with DECIMAL points.
·         Stored in floating point
·         Used for metric measurement, temperature and price.
·         Example: 1.0cm, 234.55kg, RM20.30, 36.7C.


  1. DOUBLE
·         Floating point data types comes in three sizes, namely float, double and long double.
·         The difference is in the length of value and amount of precision which they can take and it increases from float to long double.
·         double: This data type is used to represent double precision floating point number.



  1. LONG DOUBLE
·         This data type is used to represent double precision floating point number.


  1. CONSTANT
·         fixed values which cannot change.
·         example 123, 12.23, 'a' are constants.


  1. ARRAY
·         A set of locations in the computer memory that has the same name and contains the same data type.
·         It is almost the same as variable, but variable has allocated only one location that can store one value at a time. Where else, array can allocate more than one location to store several values at a time.


  1. LONG/SHORT INTEGER
·         LONG INTEGER: This data type is used to represent long integer.
·         SHORT INTEGER: This data type is used to represent short integer.
 the next example is:

Name
Description
Size*
Range*
char
Character or small integer.
1byte
signed: -128 to 127
unsigned: 0 to 255
short int (short)
Short Integer.
2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int
Integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long)
Long integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool
Boolean value. It can take one of two values: true or false.
1byte
true or false
float
Floating point number.
4bytes
+/- 3.4e +/- 38 (~7 digits)
double
Double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
long double
Long double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
wchar_t
Wide character.
2 or 4 bytes
1 wide character


No comments:

Post a Comment