Isnin, 28 Februari 2011

Exercise Weekly Reflection 4(answer)

1.(a) Variable Name =
Float Pi = 3.14;
(b) double parameter;
(c) Declare
Int data;
Cout<<”insertdata=”; Cin>>data;
(d) cin>>num;

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

(b)! ((5>3) && (5==3) II (6>9))
[(( 0 ) && (0)] II (0))
(0) (0)
!(0) (0)
=1

3. #Include <iostream.h>
Main ()
{
Float Allwance=300.00;
Salary;
Cout<<”Inputsalary=”;
Cin>>salary;
Tsalaray=salary+allowance;
Cout<<”totalsalary is="<<salary;
return0;
}


4. #include <iostream.h>
main()
{
float dpayment, tpayment;
cout<<"Enter your daily payment=";
cin>>dpayment;
tpayment=dpayment*22;
cout<<"Your salary="<<salary;
return 0;
}

5. #include <iostream.h>
main()
{
//Declare Variable
float num1,num2,num3,num4,num5;
//Input num1
cout<<"Enter num1=";
cin>>num1;
//Input num2
cout<<"Enter num1=";
cin>>num1;
//Input num2
cout<<"Enter num2=";
cin>>num2;
//Input num3
cout<<"Enter num3=";
cin>>num3;
//Input num4
cout<<"Enter num4=";
cin>>num4;
//Input num5
cout<<"Enter num5=";
cin>>num5;
//formula
calculate average=(num1+num2+num3+num4+num5)/5;
//Output
cout<<"calculate="calculate;
return0;
}

6. #include <iostream.h>
main()
{
      //declare
      float b,h,r,w,area,;
      float pi=3.14;
      int selection;
      //out
      cout<<"Please choose you choice"<<endl;
      cout<<"1.Rectangular";
      cout<<"\n2.Triangle";
      cout<<"\n3.Circle"<<endl;
      cin>>selection;
      switch (selection)
      {
             case 1: cout<<"Please input the height"<<endl;
                     cin>>h;
                     cout<<"Please input the width"<<endl;
                     cin>>w;
                     //process
                     area = w*h;
                     cout<<"The area is:"<<area;
                     break;
             case 2: cout<<"Please input the height"<<endl;
                     cin>>h;
                     cout<<"Please input the base"<<endl;
                     cin>>b;
                     //process
                     area = 0.5*b*h;
                     cout<<"The area is:"<<area;
                     break;
             case 3: cout<<"Please input the radius"<<endl;
                     cin>>r;
                     //process
                     area = pi*r*r;
                     cout<<"The area is:"<<area;
                     break;
             default :cout<<"Invalid Selection";
             return 0;
             }
}






Tiada ulasan:

Catat Ulasan