Wednesday, March 30, 2011
3/02/2011last week nye class..
3/02/2011
last week nye class..
QUESTIONS :
1) Solve the question below
Solve the working
a) 5 * 2 % 3 + 25 / 5
b) a = 5 , b = 6
!(( a < 3 ) & & ( a = = 3 ) | | ( b > 9 ))
2) Identify the syntex error in the following program
include<iostream.h>
mai()
{
float allowance=300.00,salary;
cout<<''Input Salary=";
cin>salary;
Tsalary=Sallary+Allowance;
cout<<"salary is="<<salary;
}
3) Write a program that will calculate the monthly salary for an employee that where
Saturday and Sunday are considered as non-working days.
Saturday and Sunday are considered as non-working days.
4) Write a program that calculates the average of 5 numbers that can be input by user.
5) Write a program that will calculate the area of rectangular, triangle and circle.
msok cls, nmpk je kak lia n kak syezza, aq tros join dorang.. discuss cmne na wt jwpn utk questions yg mis bg last week.. actually num 1 nan 2 aq da wt da.. tp ade salah siket.. tQ kak syezza sbb da tego part mne yg sala.. ok jom bwat jwpn.. hee
jom try test wt latihan
= (5 * 2) % 3 + (25 / 5) settle bhgi nan darab dlu
= (10 % 3) + 5 settle modulus dlu
= 1 + 5
= 6
b) a = 5 , b = 6
!(( a < 3 ) & & ( a = = 3 ) | | ( b > 9 ))
= !(( 5 < 3 ) & & ( 5 = = 3 ) | | ( 6 > 9 )) msok kn nilai a nan b dlu
= !(( 0 ) & & ( 0 ) | | ( 0 )) tntukan true / 1 or false / 0
= !(( 0 ) & & ( 0 ) | | ( 0 )) settle kn & & dlu
= !(( 0 ) | | ( 0 )) br settle kn | |
= !(0) klu not / !, kne tebalek kn
= 1 / True
2) Identify the syntex error in the following program
include<iostream.h> x letak simbol #
mai() ejaan sala, tetinggal hruf n
{
float allowance=300.00,salary;
cout<<''Input Salary=";
cin>salary; sala simbol, ptot nye >>
Tsalary=Sallary+Allowance; formula sala, hruf T x perlu ade
cout<<"salary is="<<salary; lpas output, kne ltax return 0;
}
JAWAPAN :
#include<iostream.h>
JAWAPAN :
#include<iostream.h>
main()
{
float allowance=300.00,salary;
cout<<''Input Salary=";
cin>>salary;
salary=Sallary+Allowance;
cout<<"salary is="<<salary;
return 0;
return 0;
}
3) FORMULA : working_days=day_of_month-non_working_days
monthly_salary=daily_salary*working_days
#include<iostream.h>
main()
{
//declare variable
float day_of_month;
float non_working_days;
float daily_salary;
float working_days;
float monthly_salary;
//input 1
cout<<"total day of that month=";
cin>>day_of_month;
//input 2
cout<<"non working days is about =";
cin>>non_working_days;
//input 3
cout<<"daily salary is=";
cin>>daily_salary;
//formula 1
working_days=day_of_month-non_working_days;
//output 1
cout<<"total working days is ="<<working_days;
//formula 2
monthly_salary=daily_salary*working_days;
//output 2
cout<<"the monthly salary is ="<<monthly_salary;
return 0;
}
4) FORMULA : total = num 1 + num 2 + num 3 + num 4 + num 5
average = total / 5
#include<iostream.h>
main()
{
//declare variable
float num1;
float num2;
float num3;
float num4;
float num5;
float total;
float average;
//input 1
cout<<"enter num1";
cin>>num1;
//input 2
cout<<"enter num2";
cin>>num2;
//input 3
cout<<"enter num3";
cin>>num3;
//input 4
cout<<"enter num4";
cin>>num4;
//input5
cout<<"enter num5";
cin>>num5;
//formula 1
total=num1+num2+num3+num4+num5;
//output 1
cout<<"total="<<total;
//formula 2
average=total/5;
//output 2
cout<<"average="<<average;
return 0;
}
5) FORMULA : area of rectangle = height * width
area of circle = 3.14 * radius * radius
area of triangle = 0.5 * height * base
#include<iostream.h>
main()
{
//declare variable
float height;
float width;
float radius;
float base;
float area_of_rectangle;
float area_of_circle;
float area_of_triangle;
//input 1
cout<<"enter height";
cin>>height;
//input 2
cout<<"enter width";
cin>>width;
//input 3
cout<<"enter radius";
cin>>radius;
//input 4
cout<<"enter base";
cin>>base
//formula 1
area_of_rectangle=height*width;
//output 1
cout<<"the area of rectangle is="<<area_of_rectangle;
//formula 2
area_of_circle=3.14*radius*radius;
//output 2
cout<<"the area of circle is="<<area_of_circle;
//formula 3
area_of_triangle=0.5*height*base;
//output 3
cout<<"the area of triangle is="<<area_of_triangle;
return 0;
3) FORMULA : working_days=day_of_month-non_working_days
monthly_salary=daily_salary*working_days
#include<iostream.h>
main()
{
//declare variable
float day_of_month;
float non_working_days;
float daily_salary;
float working_days;
float monthly_salary;
//input 1
cout<<"total day of that month=";
cin>>day_of_month;
//input 2
cout<<"non working days is about =";
cin>>non_working_days;
//input 3
cout<<"daily salary is=";
cin>>daily_salary;
//formula 1
working_days=day_of_month-non_working_days;
//output 1
cout<<"total working days is ="<<working_days;
//formula 2
monthly_salary=daily_salary*working_days;
//output 2
cout<<"the monthly salary is ="<<monthly_salary;
return 0;
}
4) FORMULA : total = num 1 + num 2 + num 3 + num 4 + num 5
average = total / 5
#include<iostream.h>
main()
{
//declare variable
float num1;
float num2;
float num3;
float num4;
float num5;
float total;
float average;
//input 1
cout<<"enter num1";
cin>>num1;
//input 2
cout<<"enter num2";
cin>>num2;
//input 3
cout<<"enter num3";
cin>>num3;
//input 4
cout<<"enter num4";
cin>>num4;
//input5
cout<<"enter num5";
cin>>num5;
//formula 1
total=num1+num2+num3+num4+num5;
//output 1
cout<<"total="<<total;
//formula 2
average=total/5;
//output 2
cout<<"average="<<average;
return 0;
}
5) FORMULA : area of rectangle = height * width
area of circle = 3.14 * radius * radius
area of triangle = 0.5 * height * base
#include<iostream.h>
main()
{
//declare variable
float height;
float width;
float radius;
float base;
float area_of_rectangle;
float area_of_circle;
float area_of_triangle;
//input 1
cout<<"enter height";
cin>>height;
//input 2
cout<<"enter width";
cin>>width;
//input 3
cout<<"enter radius";
cin>>radius;
//input 4
cout<<"enter base";
cin>>base
//formula 1
area_of_rectangle=height*width;
//output 1
cout<<"the area of rectangle is="<<area_of_rectangle;
//formula 2
area_of_circle=3.14*radius*radius;
//output 2
cout<<"the area of circle is="<<area_of_circle;
//formula 3
area_of_triangle=0.5*height*base;
//output 3
cout<<"the area of triangle is="<<area_of_triangle;
return 0;
lalalalala
blaja pasal if...else statement & switch...case statement
ok bdasarkan table kt ats . kite bole wt program dlm 2 jenis bentuk . sama ade dlm bntuk if...else ataupon switch...case . ok now kite wt dlm bentuk if..else statement dlu k ..
IF...ELSE STATEMENT
#include<iostream.h>
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<iostream.h>
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;
}
hmm kadang soklan suh kite tuka if...else jd switch...case . kadang tuka switch...case g if...else . tp kadang soklan ta bg programming, tp kite kene develop sndry..
for loop & while loop...!
for loop & while loop pulaaak !
FOR LOOP#include<iostream.h>
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//loop for
for(y=1;y<x;y++)
{
cout<<" "<<x;
}
return 0;
}
WHILE LOOP#include<iostream.h>
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//while
y=x;
while(y<x)
{
cout<<" "<<x;
y++;
}
return 0;
}
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//loop for
for(y=1;y<x;y++)
{
cout<<" "<<x;
}
return 0;
}
WHILE LOOP#include<iostream.h>
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//while
y=x;
while(y<x)
{
cout<<" "<<x;
y++;
}
return 0;
}
homework...
1) Change the if...else statement below to switch...case statement
#include<iostream.h>
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:"<<value;
return 0;
}
#include<iostream.h>
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:"<<value;
}
return 0;
}
2) Change the for loop statement below to while loop
#include<iostream.h>
main()
{
int i,power2;
for(i=1;i<=9;i++)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
}
return 0;
}
#include<iostream.h>
main()
{
int i,power2;
//while
i=1;
while(i<=9)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
i++;
}
return 0;
}
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.
#include<iostream.h>
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;
}
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.
#include<iostream.h>
main()
{
int x,price,total,discount;
for(x=1;x<4;x++)
{
cout<<"price["<<x<<"]:";
cin>>price;
total=total+price;
}
cout<<"total="<<total;
discount=total*0.10;
cout<<"discount"<<discount;
return 0;
}
5) What is the output for the following program segmment
i) int x=20;
for(int i=5;i<=x;i++)
{
cout<<i;
i=i+4;
}
5
10
15
20
ii) int mul=1;
do
{
mul=mul*2;
cout<<"The mul is:"<<mul;
mul++;
}
while(mul<10)
1
3
7
#include<iostream.h>
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:"<<value;
return 0;
}
#include<iostream.h>
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:"<<value;
}
return 0;
}
2) Change the for loop statement below to while loop
#include<iostream.h>
main()
{
int i,power2;
for(i=1;i<=9;i++)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
}
return 0;
}
#include<iostream.h>
main()
{
int i,power2;
//while
i=1;
while(i<=9)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
i++;
}
return 0;
}
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.
#include<iostream.h>
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;
}
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.
#include<iostream.h>
main()
{
int x,price,total,discount;
for(x=1;x<4;x++)
{
cout<<"price["<<x<<"]:";
cin>>price;
total=total+price;
}
cout<<"total="<<total;
discount=total*0.10;
cout<<"discount"<<discount;
return 0;
}
5) What is the output for the following program segmment
i) int x=20;
for(int i=5;i<=x;i++)
{
cout<<i;
i=i+4;
}
5
10
15
20
ii) int mul=1;
do
{
mul=mul*2;
cout<<"The mul is:"<<mul;
mul++;
}
while(mul<10)
1
3
7
test :)
) 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)____;
(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<<x<<"\t"<<x*2<<"In";
x=1;
while(x<=5)
cout<<x<<"\t"<<x*2<<"In";
x++
3) Write the code using while loop to get the output as below !
20
15
10
5
x=20
while(x<=5)
cout<<" "<<x;
x--;
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)____;
(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<<x<<"\t"<<x*2<<"In";
x=1;
while(x<=5)
cout<<x<<"\t"<<x*2<<"In";
x++
3) Write the code using while loop to get the output as below !
20
15
10
5
x=20
while(x<=5)
cout<<" "<<x;
x--;
assgmnt:1
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 6 :
* * * * * * * * * * * * * * * * *
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 :
Steap 5 :
Step 7 :
Step 8 : ( bile masukkan duit lebih dpd harga asal )
Step 9 :
Step 10 :
Step 11 :
Step 12 :
Step 13 :
Step 14 : ( bile masukkan duit kurang dpd harga asal )
Step 15 :
Step 16 :
Step 17 :
Step 18 :
Step 19 :
Subscribe to:
Posts (Atom)