Tuesday, 22 March 2011

WEEKLY REFLACTION 5 ( ASSIGNMENT 1 AND 2)

  • minggu ni miss bagi ASSIGNMENT mengenai TIN MINUMAN(SWITCH) & SIFIR(LOOP) dan buat dalam kumpulan.
  • SEMUA AHLI HADIR :)




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

JAWAPAN TIN MINUMAN






#include <iostream.h>
main()
{
      //declare
      int selection;
      float money,balance,price,addm,add;
      //out
      cout<<"******************"<<endl;
      cout<<"Mesin Tin Minuman"<<endl;
      cout<<"------------------"<<endl;
      cout<<"1.PEPSI";
      cout<<"\n2.COCA COLA";
      cout<<"\n3.F&N MIRINDA";
      cout<<"\n4.F&N ORANGE";
      cout<<"\n5.100 PLUS"<<endl;
      cout<<"******************"<<endl;
      //input
      cout<<"\nPlease Choose Your Drink"<<endl;
      cin>>selection;
      
      cout<<"\nPlease Enter MONEY: ";
      cin>>money;
      
      switch (selection)
      {
             case 1: cout<<" Your drink is Pepsi";
                     price = 2.00;
                     break;
             case 2: cout<<" Your drink is Coca Cola";
                     price = 2.00;
                     break;
             case 3: cout<<" Your drink is F&N Mirinda";
                     price = 1.80;
                     break;
             case 4: cout<<" Your drink is F&N Orange";
                     price = 1.80;
                     break;
             case 5: cout<<" Your drink is 100 Plus";
                     price = 2.50;
                     break;
             default: cout<<"invalid selection";
             }
      
      if (money>price)
      {
                      balance = money - price;
      }else if (money<price){
                            add = price - money;
                            cout<<"Please add (RM" <<add<< ")= ";
                            cin>>addm;
                            balance = money + addm;
                            }
                            cout<<"Your balance is "<<balance;
                            return 0;
}



ASSIGNMENT2 (SIFIR)
2.JAWAPAN SIFIR



#include <iostream.h>
main()
{
     cout<<"*****"<<endl;
     cout<<"SIFIR"<<endl;
     cout<<"*****"<<endl;
     int a,b;
     char o;
     a=1;
     while (a<=12)
     {
           cout<<"\n";
           for (b=1;b<=12;b++)
           {
               cout<<" "<<a*b;
               }
               a++;
               }
               cout<<"\n\nType EXIT to quit application"<<endl;
               cin>>o;
               return 0;
               }



EXERCISE CALCULATE (IF...ELSE)

CALCULATE:
a) RECTANGULAR
b) TRIANGLE
c) CIRCLE
d) FAHRENHEIT
e) CELCIUS

Your Selection:

Your Selection is _________ and you are calculate _________. The answer is _____________


JAWAPAN







#include<iostream.h>
main()
{
float rectangular, circle, triangle, fahrenheit, celcius, radius,f,c;
float width,height,base;
char selection;

cout<<"calculate:";
cout<<"\n\n a-rectangular";
cout<<" \nb-triangle";
cout<<"\nc-circle";
cout<<"\nd-fahrenheit";
cout<<"\ne-celcius";


cout<<"\n\nenter selection";
cin>>selection;

if (selection=='a')
cout<<"\nYour Selection is a and you are calculate rectangular.";

cout<<"\nenter width";
cin>>width;
cout<<"\nenter height";
cin>>height;
rectangular=width*height;
cout<<"\nthe answer is"<<rectangular;
}

else if (selection=='b')

cout<<"\nYour Selection is b and you are calculate triangle.";
cout<<"\nenter base";
cin>>base;
cout<<"\nenter height";
cin>>height;

cout<<"\nthe answer is"<<triangle;
triangle=(1/2*base*height);
}

else if (selection=='c')
circle=3.142 * radius * radius;
cout<<"\nYour Selection is c and you are calculate circle.";
cout<<"\n enter radius";
cin>>radius;
cout<<"\nthe answer is"<<circle;
}

else if (selection=='d')
;
cout<<"\nYour Selection is d and you are calculate fahrenheit.";
fahrenheit=(celcius*1/8)+32;
cout<<"\nenter celcius";
cin>>c;
cout<<"\nthe answer is"<<fahrenheit;
}

else 
cout<<"\nYour Selection is e and you are calculate celcius.";

cout<<"\nenter fahrenheit";
cin>>f;
cout<<"\nthe answer is"<<celcius;
celcius=(f-32)*(5/9);
}

return 0;
}

No comments:

Post a Comment