#include<iostream.h>
main ()
{
int selection,quantity;
double price;
cout<<"\n 1. Pen =RM 0.50";
cout<<"\n 2. Pensil =RM 0.30";
cout<<"\n 3. Ruler =RM 0.20";
cout<<"\n 4. Erser =RM 0.10"<<endl;
cout<<"\n Enter your selection= ";
cin>>selection;
cout<<"\n Enter your quantity= ";
cin>>quantity;
switch (selection)
{
case 1:
price = quantity * 0.50;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Pen with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
case 2:
price = quantity * 0.30;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Pensil with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
case 3:
price = quantity * 0.20;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Ruler with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
case 4:
price = quantity * 0.10;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Erser with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
default:
cout<<"\n Invalid selection"<<endl;
}
return 0;
}
Monday, March 28, 2011
Saturday, March 26, 2011
Weekly Reflection 6
masa nih sya tak dtg sbb demam..tp ada juga tny pada kwn keje fop..
contoh loop
exercise :1. fill in the blank with the appropriate data types for the following variable declaration syntax
a. ____integer_____ number 1=1
b. _____float____ number 3=30
c. ____string_____ text 1=" i have a car"
d. ____string_____ huruf = "b"
e. ____string_____ account no = "6666666443"
2. you are given PTPTN loan with the amount of rm16000. calculate the amount that you should pay other PTPTN discount based on the CGPA. you must use if...else statement
Output
Jumlah pinjaman = rm16.000
CGPA yg diperoleh = 3.00
Diskaun = rm 12.800
Jumlah pinjaman yang perlu dibayar selepas diskaun = RM3200
3. you are required to do program that will execute the multiply or divided operation is based on the user's choice. you must use switch.....case statement
Output:
answer :
4.change the algebra expression to anthmetic expression
contoh loop
exercise :1. fill in the blank with the appropriate data types for the following variable declaration syntax
a. ____integer_____ number 1=1
b. _____float____ number 3=30
c. ____string_____ text 1=" i have a car"
d. ____string_____ huruf = "b"
e. ____string_____ account no = "6666666443"
2. you are given PTPTN loan with the amount of rm16000. calculate the amount that you should pay other PTPTN discount based on the CGPA. you must use if...else statement
Output
Jumlah pinjaman = rm16.000
CGPA yg diperoleh = 3.00
Diskaun = rm 12.800
Jumlah pinjaman yang perlu dibayar selepas diskaun = RM3200
3. you are required to do program that will execute the multiply or divided operation is based on the user's choice. you must use switch.....case statement
Output:
answer :
4.change the algebra expression to anthmetic expression
a) Y = m – 4ax
7a
Answer : Y = (m - 4 ax) / 7a
b) Y = 6ab___
4sd – 2xy
Answer : Y = 6 bc / (4 sd – 2xy)
c) Y = 2 + (AB + ( ) + 5 xyz
3d
Answer : Y = (( 2 + AB + c ) / 3d ) + 5 xyz
d) Y = 2kb = 3jb
2k1
Answer : Y = (2kb / 2 ki ) – 3 jb
e) Y = xy + x2 – 2ab
Answer : Y= xy + x * x – 2 ab
Solve the statement below to find in value. Show the working :-
6. find the output for the following segment:-
a) float var 1 = 25.12, var 2 = 15.0;
if (var 1<= var 2) cout<<"var 1 less or same as var 2"; else cout<<"var 1 bigger than var 2";
b) int n = 20; n/= 5;
7. Convert the while statement below for for statement :-
{
a) M=5
M * = (3 + 4) * 2
Answer :-
M = 5 * ( 3 + 4 ) * 2
M = (5 * 7 )* 2
M = 35 * 2
M = 70
1 (TRUE)
b) M=2
M * = ((3 *4 ) / 2 ) = 9
Answer :-
M = 2 * (12/ 2 ) =9
M = ( 2* 6 ) = 9
M = 12 = 9
0 (FALSE)
6. find the output for the following segment:-
a) float var 1 = 25.12, var 2 = 15.0;
if (var 1<= var 2) cout<<"var 1 less or same as var 2"; else cout<<"var 1 bigger than var 2";
b) int n = 20; n/= 5;
Answer :-
Output :
Cout<<Var1 bigger than Var 2 “ ;
<!--[if !supportLists]-->b) <!--[endif]-->In n = 20 ;
n/ = 5 ;
Answer :-
Output :
Cout<<20 / 5 = 4 “ ;
7. Convert the while statement below for for statement :-
Int j = 10 ;
While ( j > 10)
{
Cout << “ “ << j ;
J______ ;
}
Answer :-
#incude<iostream.h>
Main ()
{
//declare variable
Int x ;
X = 1 ;
While (x < = 10 )
{
Cout<<”number “<<x*1 ;
X ++ ;
}
return 0;
}
Output :
Number 1 --------- 1
2 --------- 2
3 --------- 3
4 --------- 4
5 --------- 5
6 --------- 6
7 --------- 7
8 --------- 8
9 --------- 9
10 --------- 10
8.Write a program the reads 4 prices using while loop and calculate the sum of things. A program must use function while for calculate the average of the prices.
#include<iostream.h>
main ()
{
int k;
float p,total,averge;
k=1;
while (k<=4)
{
cout<<"Enter price "<<k<<"= ;
cin>>p;
k++;
total=total+p;
}
Average=total/4;
cout<<"Your total is "<<total<<"and average is "average;
return 0;
}
Saturday, March 19, 2011
Weekly Reflection 5
-bincang 6 soalan..pas tu miss bg keje group..tin minuman..
MESIN TIN MINUMAN (SWITCH...CASE)
*****************
MESIN TIN MINUMAN
-----------------
1- PEPSI
2- COCA COLA
3- F&N MIRINDA
4- F&N ORANGE
5- 100 PLUS
*****************
Enter your drink:
Enter your money (RM):
Your drink is __________ and your balance are __________
*If the customer does not enter enough money, asked the customer to insert the money. (if...else)
answer :
MESIN TIN MINUMAN (SWITCH...CASE)
*****************
MESIN TIN MINUMAN
-----------------
1- PEPSI
2- COCA COLA
3- F&N MIRINDA
4- F&N ORANGE
5- 100 PLUS
*****************
Enter your drink:
Enter your money (RM):
Your drink is __________ and your balance are __________
*If the customer does not enter enough money, asked the customer to insert the money. (if...else)
answer :
Tuesday, March 15, 2011
Weekly Reflection 4..
Arithmetic Operators
+ = add
- = subtraction
* = multiply
/ = divide
% = modulus
^ = power
Relational Operators
< greater / more than
> less than
<= greater / more than and equal
>= less than and equal
= = equal to!
Logical Operators
&& and
|| or
! not
Increment & Decrement
Increment
int n;
n = 5,
cout<<n; 5
cout<<++n; 1+5
cout>>n; 6
int n;
n = 5
cout<<n; 5
cout<<n++; 5+1
cout<<n; 6
int m;
m = 10
cout<<m; 10
cout<<m--; 10-1
cout<<m; 9
int m;
m = 9
cout<<m; 9
cout<<m--; 8
cout<<m; 8
Logical Operators
m n m&&n m||n
0 0 0 0
0 0 0 1
1 0 0 1
1 1 1 1
+ = add
- = subtraction
* = multiply
/ = divide
% = modulus
^ = power
Relational Operators
< greater / more than
> less than
<= greater / more than and equal
>= less than and equal
= = equal to!
Logical Operators
&& and
|| or
! not
Increment & Decrement
Increment
- pre-increment (++N)
- post-increment (N++)
- pre-decrement (--N)
- post-decrement (N--)
int n;
n = 5,
cout<<n; 5
cout<<++n; 1+5
cout>>n; 6
int n;
n = 5
cout<<n; 5
cout<<n++; 5+1
cout<<n; 6
int m;
m = 10
cout<<m; 10
cout<<m--; 10-1
cout<<m; 9
int m;
m = 9
cout<<m; 9
cout<<m--; 8
cout<<m; 8
Logical Operators
m n m&&n m||n
0 0 0 0
0 0 0 1
1 0 0 1
1 1 1 1
Monday, February 28, 2011
Exercise
1. Write correct C++ syntax & for each statement below:
a) Initializing variable Pi with the value 3.14 (constant)
answer :
float pi =3.142;
b) Declare a variable named Perimeter with double data type (declare variable)
answer :
double perimeter
c) Give instruction that allowed user to input data (input)
answer :
int data;
//input
cout<<"enter your data";
cin>>data;
d) Input number of computer using variable (input assign to variable value)
answer :
int number;
cin>>number;
2. Solve the question below. Show the working.
a) 5 * 2 % 3 + 25 / 5
answer :
= [10%3]+25/5
= 1+[25/5]
= 1+5
= 6
b) a = 5, b = 6
!((a < 3) && (a == 3) || (b > 9))
answer :
= !((5<3)&&(5 == 3) || (6>9))
= !((0) &&(0) || (0)
= !((0) (0)
= !(0)
= 1
3. Identify syntax errors in the following program. (5errors)
include<iostream.h>
main()
{
float allowance = 300.00, salary;
cout<<"Input Salary = ";
cin>>salary;
TSalary = salary + Allowance;
cout<<"Salary is= "<< salary;
}
answer :
#include<iostream.h>
main()
{
float allowance = 300.00, salary;
cout<<"Input Salary = ";
cin>>salary;
TSalary = salary + Allowance;
cout<<"Total Salary is= "<< Tsalary;
return 0;}
4. Write a program that will calculate the monthly salary for an employee that where Saturday and Sunday are considered as non-working days.
answer :
5. Write a program that calculates the average of 5 numbers that can be input by user.
answer :
6. Write a program that will calculate the area of rectangular, triangle and circle.
answer :
a) Initializing variable Pi with the value 3.14 (constant)
answer :
float pi =3.142;
b) Declare a variable named Perimeter with double data type (declare variable)
answer :
double perimeter
c) Give instruction that allowed user to input data (input)
answer :
int data;
//input
cout<<"enter your data";
cin>>data;
d) Input number of computer using variable (input assign to variable value)
answer :
int number;
cin>>number;
2. Solve the question below. Show the working.
a) 5 * 2 % 3 + 25 / 5
answer :
= [10%3]+25/5
= 1+[25/5]
= 1+5
= 6
b) a = 5, b = 6
!((a < 3) && (a == 3) || (b > 9))
answer :
= !((5<3)&&(5 == 3) || (6>9))
= !((0) &&(0) || (0)
= !((0) (0)
= !(0)
= 1
3. Identify syntax errors in the following program. (5errors)
include<iostream.h>
main()
{
float allowance = 300.00, salary;
cout<<"Input Salary = ";
cin>>salary;
TSalary = salary + Allowance;
cout<<"Salary is= "<< salary;
}
answer :
#include<iostream.h>
main()
{
float allowance = 300.00, salary;
cout<<"Input Salary = ";
cin>>salary;
TSalary = salary + Allowance;
cout<<"Total Salary is= "<< Tsalary;
return 0;}
4. Write a program that will calculate the monthly salary for an employee that where Saturday and Sunday are considered as non-working days.
answer :
5. Write a program that calculates the average of 5 numbers that can be input by user.
answer :
6. Write a program that will calculate the area of rectangular, triangle and circle.
answer :
Sunday, February 27, 2011
homework2
Question :
OUTPUT:
Subject 1 (0.00) :
Subject 2 (0.00) :
Subject 3 (0.00) :
Subject 4 (0.00) :
Subject 5 (0.00) :
CPA:
FORMULA:
CPA = ((Subject1*3) + (Subject2*3) + (Subject3*2) + (Subject4*2) + (Subject5*4)) / 5
Subject 1 (0.00) :
Subject 2 (0.00) :
Subject 3 (0.00) :
Subject 4 (0.00) :
Subject 5 (0.00) :
CPA:
FORMULA:
CPA = ((Subject1*3) + (Subject2*3) + (Subject3*2) + (Subject4*2) + (Subject5*4)) / 5
Answer :
homework1
Questions :
OUTPUT:
Assignment 1 (10%):
Assignment 2 (10%):
Assignment 3 (10%):
Assignment 4 (10%):
Assignment 5 (10%):
MidTerm (10%):
Final (40%):
TOTAL (100%):
FORMULA:
TOTAL = Assignment1+Assignment2+Assignment3+Assignment4+Assignment5+MidTerm+Final
Assignment 1 (10%):
Assignment 2 (10%):
Assignment 3 (10%):
Assignment 4 (10%):
Assignment 5 (10%):
MidTerm (10%):
Final (40%):
TOTAL (100%):
FORMULA:
TOTAL = Assignment1+Assignment2+Assignment3+Assignment4+Assignment5+MidTerm+Final
Answer :
Thursday, February 24, 2011
Weekly Reflection3 : 8 feb 2011
-install turbo C++..
-tutorials blogspot
-buat exercise 2.
-miss bg homework 1 and homework 2
-tutorials blogspot
-buat exercise 2.
-miss bg homework 1 and homework 2
Tuesday, February 22, 2011
Weekly Reflection 2 : Chapter 2 : C++ Basics
C++ Language
consists of 2 basic elements :
- is a text file containing a sequence of C++ commands put together according to the laws of C++ grammar.
__________ . CPP
# include <iostream.h> = header
- - - - - - - - - - - - - - - - - - - - - - - - (start)
main ( ) = start
{ // open curly braket
= body
} // close curly braket
- - - - - - - - - - - - - - - - - - - - - - - -(end)
In body
1. Variable
to declare variable
data_type variable _name
Data_type
int : integar = real 0-9 only
float : float = decimal
double : double = decimal
const : constant = formula akan jd statik
char : character = one alphabet only a-z
string : string = one/more word
2. Input
cout<<"please enter your radius";
cin>>radius;
3. Output
cout<<"area = " << area ;
example :
consists of 2 basic elements :
- semantics : a vocabulary of commands that humans can understand and that can be converted into machine language.
- syntax : a language structure (or grammar) that allows humans to combine these C++ commands into a program that actually does something.
- is a text file containing a sequence of C++ commands put together according to the laws of C++ grammar.
__________ . CPP
# include <iostream.h> = header
- - - - - - - - - - - - - - - - - - - - - - - - (start)
main ( ) = start
{ // open curly braket
= body
} // close curly braket
- - - - - - - - - - - - - - - - - - - - - - - -(end)
In body
1. Variable
to declare variable
data_type variable _name
Data_type
int : integar = real 0-9 only
float : float = decimal
double : double = decimal
const : constant = formula akan jd statik
char : character = one alphabet only a-z
string : string = one/more word
2. Input
cout<<"please enter your radius";
cin>>radius;
3. Output
cout<<"area = " << area ;
example :
Questions that will be ask on 1 Feb 2011
Questions :
List the differences of structured programming, procedural programming and object oriented programming.
Answer :
List the differences of structured programming, procedural programming and object oriented programming.
Answer :
Procedural programming
-Approach specifying the steps the program must take to reach the desired state.
-Using programming languange to create computer memor y locations.
-Also know as routine , subroutines, methods, or functions.
-Defines the variable memory location
-Invokes a eries of procedure to input , manipulate, and output the values stored in those locations.
Structured programming
-Composed of simple , hierarchical program flow structure.
-Three flow structure : sequential , selection, and repitition.
-Sequential refers to a sequence of statements executed in order.
-Selection is executed depending on the state of the program.
-Repitition is execute until the program reaches a certain tate of applied to every element of a collection.
-Associated with a “top-down design” approach.
Object oriented programming
-Is an extension of procedural programming.
-Made up of states and methods (functions).
-State of an object are known as attributes.
-Method(functions)to accomplish tasks.
-The attributes and methods are encapsulated into objects that are then used much like real world objects.
-Programmer are allowed to access to data or procedures only via a specified interface.
-Approach specifying the steps the program must take to reach the desired state.
-Using programming languange to create computer memor y locations.
-Also know as routine , subroutines, methods, or functions.
-Defines the variable memory location
-Invokes a eries of procedure to input , manipulate, and output the values stored in those locations.
Structured programming
-Composed of simple , hierarchical program flow structure.
-Three flow structure : sequential , selection, and repitition.
-Sequential refers to a sequence of statements executed in order.
-Selection is executed depending on the state of the program.
-Repitition is execute until the program reaches a certain tate of applied to every element of a collection.
-Associated with a “top-down design” approach.
Object oriented programming
-Is an extension of procedural programming.
-Made up of states and methods (functions).
-State of an object are known as attributes.
-Method(functions)to accomplish tasks.
-The attributes and methods are encapsulated into objects that are then used much like real world objects.
-Programmer are allowed to access to data or procedures only via a specified interface.
Exercise 2
Questions :
Answer :
Calculate 3 numbers with using the formula below:
calculate=(num1*num2)-num3+(num2/num1)
Do a complete C++ Coding.
calculate=(num1*num2)-num3+(num2/num1)
Do a complete C++ Coding.
Answer :
#include<iostream.h>
main()
{
//declare variable
float num1,num2,num3,calculate;
//input1
cout<<"Enter Num1";
cin>>num1;
//input2
cout<<"Enter Num2";
cin>>num2;
//input3
cout<<"Enter Num3";
cin>>num3;
//formula
calculate=(num1*num2)-num3+(num2/num1);
//output
cout<<"Answer is="<<calculate;
return 0;
}
main()
{
//declare variable
float num1,num2,num3,calculate;
//input1
cout<<"Enter Num1";
cin>>num1;
//input2
cout<<"Enter Num2";
cin>>num2;
//input3
cout<<"Enter Num3";
cin>>num3;
//formula
calculate=(num1*num2)-num3+(num2/num1);
//output
cout<<"Answer is="<<calculate;
return 0;
}
Monday, February 14, 2011
exercise 1
Sum and Minus Two Integers
Multiply Two Integers
answer :
Fahrenheit Convert to Celcius
answer:
Celcius Convert to Fahrenheit
answer :
#include<iostream.h>
main()
{
float celcius,farenheit;
cout<< "Enter celcius=";
cin>>celcius;
farenheit=9/5*(celcius+32);
cout<<"Celcius="<<celcius;
cout<<"Farenheit="<<farenheit;
return 0;
}
Divide and Modulus Two Integers
answer:
answer :#include<iostream.h>
main( )
{
//declare variable
float sum,minus,num1,num2;
//input1
cout<<''num1='';
cin>>num1;
//input2
cout<<''num2='';
cin>>num2;
//formula
sum=num1+num2;
minus=num2-num1;
//output
cout<<''sum=''<<sum;
cout<<''minus=''<<minus;
return 0;
}
main( )
{
//declare variable
float sum,minus,num1,num2;
//input1
cout<<''num1='';
cin>>num1;
//input2
cout<<''num2='';
cin>>num2;
//formula
sum=num1+num2;
minus=num2-num1;
//output
cout<<''sum=''<<sum;
cout<<''minus=''<<minus;
return 0;
}
Multiply Two Integers
answer :
#include<iostream.h>
main()
{
//Declare variable
int multiply,num1,num2;
//Input num1
cout<<"Enter num1 =";
cin>>num1;
//Input num2
cout<<"Enter Num 2 =";
cin>>num2;
//Formula
multiply=num1*num2;
//Output
cout<<"mutiply= "<<mutiply;
return 0;
}
main()
{
//Declare variable
int multiply,num1,num2;
//Input num1
cout<<"Enter num1 =";
cin>>num1;
//Input num2
cout<<"Enter Num 2 =";
cin>>num2;
//Formula
multiply=num1*num2;
//Output
cout<<"mutiply= "<<mutiply;
return 0;
}
Fahrenheit Convert to Celcius
answer:
#include<iostream.h>
main( )
{
float celcius;
float farenheit;
cout<<"Enter farenheit=";
cin>>farenheit;
celcius=5/9*(farenheit -32);
cout<<"farenheit= "<<farenheit;
cout<<"celcius= "<<celcius;
return 0;
}
main( )
{
float celcius;
float farenheit;
cout<<"Enter farenheit=";
cin>>farenheit;
celcius=5/9*(farenheit -32);
cout<<"farenheit= "<<farenheit;
cout<<"celcius= "<<celcius;
return 0;
}
Celcius Convert to Fahrenheit
answer :
#include<iostream.h>
main()
{
float celcius,farenheit;
cout<< "Enter celcius=";
cin>>celcius;
farenheit=9/5*(celcius+32);
cout<<"Celcius="<<celcius;
cout<<"Farenheit="<<farenheit;
return 0;
}
Divide and Modulus Two Integers
answer:
#include<iostream.h>
main( )
{
//declare variable
float divide, modulus, Num1, Num2;
//Input 1
cout<<"Num1= ";
cin>>Num1;
//Input 2
cout<<"Num2= ";
cin>>Num2 ;
//formula
Divide=Num2/Num1;
Modulus=Num1%Num2;
//Output
cout<<"divide="<<divide;
cout<<"modulus="<<modulus;
return 0;
}
main( )
{
//declare variable
float divide, modulus, Num1, Num2;
//Input 1
cout<<"Num1= ";
cin>>Num1;
//Input 2
cout<<"Num2= ";
cin>>Num2 ;
//formula
Divide=Num2/Num1;
Modulus=Num1%Num2;
//Output
cout<<"divide="<<divide;
cout<<"modulus="<<modulus;
return 0;
}
Friday, February 4, 2011
Weekly Reflection1 : Chapter1 : programming and problem solving
Algorithm
-a sequence of instrutions to solve a problem.
-it can be written in human language n programming language
example :
area of a rectangle
1. get the width of the rectangle
2. get the heigth of the rectangle
3. calculate using the formula area= width *heigth
4. display the answer
Pseudocode
-is an outline of a program,written in a from taht can easily be converted into real programming statements.
example:
-is a graphic representation of the logic or steps in a program.
example:
Program Design
-divided in to two phase : problem solving phase, implementation phase
The Software Life Cycle
-a sequence of instrutions to solve a problem.
-it can be written in human language n programming language
example :
area of a rectangle
1. get the width of the rectangle
2. get the heigth of the rectangle
3. calculate using the formula area= width *heigth
4. display the answer
Pseudocode
-is an outline of a program,written in a from taht can easily be converted into real programming statements.
example:
- read the width
- read the height
- set the area to the width multiplied by height
- print the area
-is a graphic representation of the logic or steps in a program.
example:
Program Design
-divided in to two phase : problem solving phase, implementation phase
The Software Life Cycle
- analysis and specification of the task (problem definition)
- design of the software (algorithm design)
- implementation (coding)
- testing
- maintenance and evolution of the system
- obsolescence
Procedural programming |
Approach specifying the steps the program must take to reach the desired state. |
Using programming languange to create computer memor y locations. |
Also know as routine , subroutines, methods, or functions. |
Defines the variable memory location |
Invokes a eries of procedure to input , manipulate, and output the values stored in those locations. |
Structured programming |
Composed of simple , hierarchical program flow structure. |
Three flow structure : sequential , selection, and repitition. |
Sequential refers to a sequence of statements executed in order. |
Selection is executed depending on the state of the program. |
Repitition is execute until the program reaches a certain tate of applied to every element of a collection. |
Associated with a “top-down design” approach. |
Object oriented programming |
Is an extension of procedural programming. |
Made up of states and methods (functions). |
State of an object are known as attributes. |
Method(functions)to accomplish tasks. |
The attributes and methods are encapsulated into objects that are then used much like real world objects. |
Programmer are allowed to access to data or procedures only via a specified interface. |
Wednesday, February 2, 2011
ema nufrah
ni la si kecik yg bernama nurul fatimah..boley di panggil c kecik atau ema nufrah..nape adanye nme nufrah..?nme nufrah tu adalah gbungan antara nur dan fah tetapi r dan f ditukarkn spaye menjadi nufrah..huhu...ema seorg yg pemalu,pendiam ada msenye dan berckap pun ade mse2nye..kkdg susa di fahami ttpi memahi org lain..ema berminat dgn dunia mathematic tetapi tak minat pd akaun..skrg ema blaja di cosmopoint jb..dgn mngambil dip e-business..skrg nih ema kena amik sbjek fundamental of programming..so,lecturer pun minta student wat blog..memula tu ema tak pandai nk wat blog nihh..so explore la sendiri..so inila hasil yg ema wat..hope blog ni dpt membntu ema dlm ape jua situasi..
Subscribe to:
Posts (Atom)