Monday, March 7, 2011

FOP Answer Exercise no. 1 & 2 (1/3/2011)

Answer Exercise 2

Include

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"<

}

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=(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"<

}

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"<

}

else

{

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

cout<<"\nenter fahrenheit";

cin>>f;

cout<<"\nthe answer is"<

celcius=(f-32)*(5/9);

}

return 0;

}

Answer Exercise 1

#include

main()

{

int drink;

double price;

double money;

double balance;

cout<<"**********";

cout<<"\n Mesin tin minuman";

cout<<"\n ------------------";

cout<<"\n 1 - pepsi\t\t 2.00\n 2 - coca cola\t\t2.00\n 3 - F&N MIRINDA \t1.80\n 4 - F&N ORANGE\t\t1.80\n 5 - 100 plus\t\t2.50";

cout<<"\n *********";

cout<<"\n\n enter your drink";

cin>>drink;

cout<<"\n enter your money";

cin>>money;

if (drink==1)

{

balance=money-2.00;

cout<<"\n your drink is pepsi";

cout<<"\n Balance is"<

}

else

if(drink==2)

{

balance=money-2.00;

cout<<"\n your drink is coca cola";

cout<<"\n Balance is"<

}

else

if(drink==3)

{balance= money-1.80;

cout<<"\n your drink is F$N MIRINDA";

cout<<"\n Balance is"<

else

if(drink==4)

{

balance = money-1.80;

cout<<"\n your drink is f&n orange";

cout<<"\n Balance is"<

}

else

if(drink==5)

{

balance=money-2.50;

cout<<"\n your drink is 100 plus";

cout<<"\n Balance is"<

}

else

{

cout<<" \n Invalid selection. Try again";

}

return 0;

}

No comments:

Post a Comment