Daisypath Anniversary tickers

Daisypath Anniversary tickers

Saturday, March 26, 2011

new chapter

Soklan 1

a) Initializing variable Pi with the value 3.14
= const Pi=3.14;

b) Declare a variable named perimeter with double data type
= double perimeter;

c) Give instruction that allowed user to input data
= cout<<"Enter data=";
cin>>data;

d) Input number of computer using variable
= cout<<"Enter number=";
cin>>number;

Soklan 2

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

#include
main()
{
int selection,quantity;
float price;
cout<<"1.pen=rm0.50";
cout<<"2.pencil=rm0.30;
cout<<"3.ruler=rm0.20";
cout<<"4.Erasor=rm0.10";
cin>>selection;
cin>>quantity;
if(selection==1)
{price=quantity*0.50;}
else if(selection==2)
{price=quantity*0.30;}
else if(selection==3)
{price=quantity*0.20;}
else if(selection==4)
{price=quantity*0.10;}
else
{cout<<"Invalid selection";}
cout<<"the price is :"<return 0;
}

Jawapannye....

#include
main()
{
int selection,quantity;
float price;
cout<<"1.pen=rm0.50";
cout<<"2.pencil=rm0.30;
cout<<"3.ruler=rm0.20";
cout<<"4.Erasor=rm0.10";
cin>>selection;
cin>>quantity;
switch(quantity,selection)
{
case 1:"price=quantity*0.50";break;
case 2:"price=quantity*0.30";break;
case 3:"price=quantity*0.20";break;
case 4:"price=quantity*0.10";break;
default:cout<<"Invalid selection";
cout<<"The price is :"<return 0;
}

IF.... ELSE.......SWITCH......CASE....STATEMENT.....XD

IF.....ELSE STATEMENT
#include
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//if...else statement
if(age>=1||age<=6)
{cout<<"you are kids !!";}
else if(age>=7||age<=12)
{cout<<"you are child !!";}
else if(age>=13||age<=21)
{cout<<"you are teenager !!";}
else if(age>=22||age<=30)
{cout<<"you are adult !!";}
else if(age>30)
{cout<<"you are old !!";}
else
{cout<<"Invalid selection";}
return 0;
}


SWITCH.....CASE STATEMENT
#include
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//switch...case statement
switch(age)
{
case(age>=1||age<=6):cout<<"you are kids !!";break;
case(age>=7||age<=12):cout<<"you are kids !!";break;
case(age>=13||age<=21):cout<<"you are kids !!";break;
case(age>=22||age<=30):cout<<"you are kids !!";break;
case(age>30):cout<<"you are kids !!";break;
default:cout<<"Invalid selection";
}
return 0;
}

EXERCISE

1) Solve the question below:

a) 5*2%3+25/5
=(5 * 2) % 3 + (25 / 5)
=(10 % 3) + 5
= 1 + 5
= 6

b) a=5, b=6
! ((a<3) && (a==3) || (b>9))
= ! ((5 < 3) && (5 = = 3) || (6 > 9))
= ! ((0) && (0) || (0))
= ! ((0) || (0))
= ! (0)
= 1 / True

2) Identify the syntax errors in the following program:

include
mai()
{
float allowance=300.00 salary;
//input
cout<<"input salary=";
cin>salary;
salary=salary+allowance;
//output
cout<<"salary is="<}

answer:

#include
main()
{
float allowance=300.00 salary;
//input
cout<<"input salary=";
cin>>salary;
salary=salary+allowance;
//output
cout<<"salary is="<return 0;
}

3) Write a program that calculate the monthly salary for an employes that where saturday & sunday are considered as non working days.

#include
main()
//declare variable
float no working days;
float salary per days;
float monthly salary;
//input 1
cout<<"no working days";
cin>>no working days;
//input 2
cout<<"salary per days";
cin>>salary per days;
//formula
monthly salary=working days*salary per days;
//output
cout<<"monthly salary="<return 0;
}

4) Write a program that calculate the average of 5 numbers that can be input by user.

#include
main()
float num1;
float num2;
float num3;
float num4;
float num5;
float total;
float average;
//input 1
cout<<"num1";
cin>>num1;
//input 2
cout<<"num2";
cin>>num2;
//input 3
cout<<"num3";
cin>>num3;
//input 4
cout>>"num4";
cin>>num4;
//input 5
cout<<"num5";
cin>>num5;
//formula 1
total=num1+num2+num3+num4+num5;
//output 1
cout<<"total="<//output 2
cout<<"average="<return 0;
}

5) Write a program that will calculate the area of rectangular, triangle and circle.

#include
main()
{
//declare variable
float height;
float width;
float area of rectangle;
float radius;
float area of circle;
float height;
float area of triangle;
//input 1
cout<<"height";
cin>>height;
//input 2
cout<<"width";
cin>>width;
//input 3
cout<<"radius";
cin>>radius;
//input 4
cout<<"height";
cin>>height;
//formula 1
area of rectangle=height*width;
//output 1
cout<<"area of rectangle="<//formula 2
area of circle=3.14*radius*radius;
//output 2
cout<<"area of circle="<//formula 3
area of triangle=0.5*height*height;
//output 3
cout<<"area of triangle="<return 0;
}

latihan

wat latihan lagik....

soklan...

















jawapan...







erm.. x clear sangat le... huhu.. tp still leh bacekan.. hehe..

aa.. peberet chapter.....

Aaaaa... yang nih chap yg paling aku suke... kire chap peberet le.. best sebab senang nk paham.. gagaggaa.. huhu... maklom la.. chap len mcm nk pecah pale.. chap nih sronok sket.. men kire2.. cam math...

Arithmetic operators :
+ + (Unary Plus)
- - (Unary minus)
+ (Addition)
- (Substraction)
* (multiplication)
/ (Floating-point division / Integer division)
% (Modulus)

increament & decrement operator..
+ + (Pre-increment) e.g + +m
+ + (Post-increment) e.g m+ +
- - (Pre-decrement) e.g - -n
- - (Post-decrement) e.g n- -

soklannye...

a = 2 , b = 3
m = 2 , n = 3
p = 2 , q = 3
x = 2 , y = 3


(+ + a) + (- - b) * 4 > (+ + m) * (- - n) + 4

jawapannye pulak...

(+ + a) + (- - b) * 4 > (+ + m) * (- - n) + 4
(2 + 1) + (3 - 1) * 4 > (2) * (3) + 4
(3) + (2) * 4 > 2 * 3 + 4
3 + 8 > 6 + 4
11 > 10
1 / TRUE


Relational operators :
< (Less than) > (Greater than)
= = (Equal to)
< = (Less than or equal to) > = (Greater than or equal to)
! = (Not equal to)


Logical operators :

& & (and)








l l (or)







! (not)






! (& &) (not and)
! (l l ) ( not or)


Soklan for group...

Soklan nih miss bagi tp kene wat ikot group.. soklan nih da upload kt forum.. tp lupe lak nk upload kt blog... huhu.... err... mase nih group kitorg dpt second last.. okeh le tuh...


Bahasa melayu=
Bahasa inggeris=
Matematik=
Sains=
Total=
Average=


Formula :
total=bm+bi+math+sains
average=total/4

jawapan seperti berikot...


#include//header
main()//start body
{//open curly bracket
float bm;
float bi;
float math;
float sains;
float total;
float average;
//input 1
cout<<"bahasa melayu=";
cin>>bm;
//input 2
cout<<"bahasa inggeris=";
cin>>bi;
//input 3
cout<<"matematik=";
cin>>math;
//input 4
cout<<"sains=";
cin>>sains;
//formula
total=bm+bi+math+sains;
//output
cout<<"total="<//formula
average=total/4;
//output
cout<<"average="<return 0;
}//close curly bracket
//end body


miss soh wat dlm C++.. oleh kerane akunye comp nih bengap sangat.. aku x leh nk wat C++.. so aku just typing je la... da pening sangat da nk wat C++ nih camne.. kalo nk tunggu alamat x siap la keje aku.. hukhukhuk...

SOKLAN MENGUJI

Mase soklan nih.. ehem.. aku mcm bese la... lambat masok class.. tp still ramai yg lom masok class.. bebudak len da stat wat soklan.. then aku pon menyelit le kt sbelah yani.. hukhukhuk.... err.. ni jawapan tok soklan uh....

Soklannye...

Multiply and divide two FLOAT numbers with using the formula below:
multiply=num1*num2
divide=num2/num1

jawapannye pulak...

Flow chat





















#include
main()// start body
{// open curly bracket
//declare variable
float num1;
float num2;
float multiply;
float divide;
//input 1
cout<<"enter num 1"; cin>>num1;
//input 2
cout<<"enter num 2"; cin>>num2;
//formula
multiply=num1*num2;
//output
cout<<"multiply="<//formula
divide=num2/num1;
//output
cout<<"divide="<return 0;
}//close curly bracket
//end body