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
}
}

ASSIGNMENT SIFIR...

STEP 1)



STEP 2)



STEP 3)



STEP 4)



STEP 5)










STEP 6)










STEP 7)

ASSIGNMENT TIN MINUMAN......

QUESTION :
Write a program :
* * * * * * * * * * * * * * * * *
M E S I N T I N M I N U M A N
- - - - - - - - - - - - - - - - -
Jenis RM
- - - - - - - - - - - - - - - - -
1.Pepsi 1.80
2.Coca Cola 1.90
3.F&N Orange 1.50
4.F&N Mirinda 1.60
5.100 Plus 2.00
* * * * * * * * * * * * * * * * *
your selection :
Insert your money :

*Your Balance are ________
* Please insert _________ . Your money is not enough !! : _________

Thank You !
Please Come Again


ANSWER:

STEP 1)










STEP 2)











STEP 3)











STEP 4)











STEP 5)

(KALAU MASOKKAN DUIT LEBIH)











STEP 6)











STEP 7)











STEP 8)

(KALAU MASOKKAN DUIT TAK CUKOP)











STEP 9)











STEP 10)










STEP 11)

Thursday, April 7, 2011

More exercise....

1) Complete the code that can calculate total marks for 3 students
for(int stud=1;____(a)____;stud++)
{
cout<<"Enter Student name:";
____(b)____name;
for(int mark=1;mark<=3;____(c)____)
{
cout<<"Enter assigment marks:";
cin>>marks;
total=____(d)____+marks;
}
}
cout<<"Total marks are"<<____(e)____;

answer

(a) stud<=3
(b) cin>>
(c) mark++
(d) total
(e) total

2) Based on the short code below :
Change for loop statement below to while loop
for(x=1;x<=5;x++)
cout<
answer

x=1;
while(x<=5)
cout<x++

3) Write the code using while loop to get the output as below !
20
15
10
5

answer

x=20
while(x<=5)
cout<<" "<x--;

EXERCISE!!

Soklan 1)

Change the if...else statement below to switch...case statement

#include
main()
{
int nomA,nomB,selection,value;
cout<<"Enter 2 number:";
cin>>nomA>>nomB;
cout<<"1.Addition";
cout<<"2.Substraction";
cout<<"3.Multiply";
cout<<"4.Division";
cout<<"Enter selection=";
cin>>selection;
if(selection==1)
{value=nomA+nomB;}
else if(selection==2)
{value=nomA-nomB;}
else if(selection==3)
{value=nomA*nomB;}
else if(selection==4)
{value=nomA/nomB;}
else
{cout<<"Invalid selection";}
cout<<"The value is:"<return 0;
}

Jawapan 1)

#include
main()
{
int nomA,nomB,selection,value;
cout<<"Enter 2 number:";
cin>>nomA>>nomB;
cout<<"1.Addition";
cout<<"2.Substraction";
cout<<"3.Multiply";
cout<<"4.Division";
cout<<"Enter selection=";
cin>>selection;
switch(selection)
{
case1:"value=nomA+nomB";break;
case2:"value=nomA-nomB";break;
case3:"value=nomA*nomB";break;
case4:"value=nomA/nomB";break;
default:cout<<"Invalid selection";
cout<<"The value is:"<}
return 0;
}

Soklan 2)

Change the for loop statement below to while loop

#include
main()
{
int i,power2;
for(i=1;i<=9;i++)
{
power2=i*i;
cout<<" "<}
return 0;
}

Jawapan 2)

#include
main()
{
int i,power2;
//while
i=1;
while(i<=9)
{
power2=i*i;
cout<<" "<i++;
}
return 0;
}

Soklan 3)

Write a program that input 2 numbers. Compare the numbers & display only the biggest number. If the numbers are same, display the numbers are same.

Jawapan 3)

#include
main()
{
int nomA,nomB;
cout<<"Enter 2 numbers=";
cin>>nomA>>nomB;
if(nomA>nomB)
{cout<<"nom A is bigger than nom B";}
else if(nomA==nomB)
{cout<<"nom A is same as nom B";}
else
{cout<<"Invalid";}
return 0;
}

Soklan 4)

Write a program using for loop that receive prices of 3 products. Calculate the price that must be paid after 10% discount is given to every customer.

Jawapan 4)

#include
main()
{
int x,price,total,discount;
for(x=1;x<4;x++)
{
cout<<"price["<cin>>price;
total=total+price;
}
cout<<"total="<discount=total*0.10;
cout<<"discount"<return 0;
}

Soklan 5)

What is the output for the following program segment

5.i) int x=20;
for(int i=5;i<=x;i++)
{
cout< i=i+4;
}

Jawapan 5.i)

5
10
15
20

5.ii) int mul=1;
do
{
mul=mul*2;
cout<<"The mul is:"< mul++;
}
while(mul<10)

Jawapan 5.ii)

1
3
7