Daisypath Anniversary tickers

Daisypath Anniversary tickers

Friday, April 8, 2011

CORRECTION MIDTERM.........

SECTION A:

#include
main()
{
float price=0,total;
int i;
for ( i =1;i<=3;i++)
{
cout<<"Enter price ["< cin>>price;
total + = price;
}
cout<<"Total="<return 0;
}








SECTION B

QUESTION 1:

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:

Variable's name MUST be unique.
Cannot be more than 31 characters.
MUST begin with letters.
NO space in between.
Can't begin with numbers, symbols, or special characters.

DATA TYPES

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

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

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
Decision is TRUE
Else
Decision is FALSE

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 …).

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.

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.

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

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

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.

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:


QUESTION 2:

Change from if.. else statement to Switch .... case statement

if... else statement






Swith... case statement









QUESTION 3:

a)Change from Loop for to Loop while

Loop for

#include
main ()
{
int x, y = 2;
for (x = 1; x ,=5: x++)
{cout << "" << x * y ; }
return 0;
}

Loop while

//include
main()
{
int x,y=2;
while
x=1;
while(x<=5);
{
cout<<" "<x++
return 0
}
}

No comments:

Post a Comment