#include <iostream.h>
main ()
{
int a,b;
for (a=1;a<=12;a++)
{
cout<<"\n";
for (b=1;b<=12;b++)
{cout<<" "<<a*b;}
}
return 0;
}
Fundamentals of Programming
Followers
Saturday, March 26, 2011
Sunday, March 20, 2011
TIN MINUMAN
#include <iostream.h>
main()
{
//declare
int selection;
float money,balance,price,addmmoney,add;
//out
cout<<"\n******************";
cout<<"\nMesin Tin Minuman";
cout<<"\n------------------";
cout<<"\n1.PEPSI";
cout<<"\n2.COCA COLA";
cout<<"\n3.F&N MIRINDA";
cout<<"\n4.F&N ORANGE";
cout<<"\n5.100 PLUS";
cout<<"\n******************";
//input
cout<<"\nPlease Choose Your Drink=";
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>>addmoney;
balance = money + addmoney;
}
cout<<"Your balance is ";
return 0;
}
main()
{
//declare
int selection;
float money,balance,price,addmmoney,add;
//out
cout<<"\n******************";
cout<<"\nMesin Tin Minuman";
cout<<"\n------------------";
cout<<"\n1.PEPSI";
cout<<"\n2.COCA COLA";
cout<<"\n3.F&N MIRINDA";
cout<<"\n4.F&N ORANGE";
cout<<"\n5.100 PLUS";
cout<<"\n******************";
//input
cout<<"\nPlease Choose Your Drink=";
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>>addmoney;
balance = money + addmoney;
}
cout<<"Your balance is ";
return 0;
}
Sunday, March 6, 2011
HOMEWORK 2
#include<iostream.h>
main()
{
//variable
float subject1,subject2,subject3,subject4,subject5,cgpa;
//input 1
cout<<"subject1 pointer=";
cin>>subject1;
//input 2
cout<<"subject2 pointer=";
cin>>subject2;
//input 3
cout<<"subject3 pointer=";
cin>>subject3;
//input 4
cout<<"subject4 pointer=";
cin>>subject4;
//input 5
cout<<"subject5 pointer=";
cin>>subject5;
//formula
cgpa=((sub1*3)+(sub2*3)+(sub3*2)+(sub4*2)+(sub5*4))/5;
//output
cout<<"subject1 is="<<sub1;
cout<<"subject2 is="<<sub2;
cout<<"subject3 is="<<sub3;
cout<<"subject4 is="<<sub4;
cout<<"subject5 is="<<sub5;
cout<<"The cgpa is="<<cgpa;
return 0;
}
main()
{
//variable
float subject1,subject2,subject3,subject4,subject5,cgpa;
//input 1
cout<<"subject1 pointer=";
cin>>subject1;
//input 2
cout<<"subject2 pointer=";
cin>>subject2;
//input 3
cout<<"subject3 pointer=";
cin>>subject3;
//input 4
cout<<"subject4 pointer=";
cin>>subject4;
//input 5
cout<<"subject5 pointer=";
cin>>subject5;
//formula
cgpa=((sub1*3)+(sub2*3)+(sub3*2)+(sub4*2)+(sub5*4))/5;
//output
cout<<"subject1 is="<<sub1;
cout<<"subject2 is="<<sub2;
cout<<"subject3 is="<<sub3;
cout<<"subject4 is="<<sub4;
cout<<"subject5 is="<<sub5;
cout<<"The cgpa is="<<cgpa;
return 0;
}
HOMEWORK 1
#include<iostream.h>
main ()
{
//variable
float Asmnt1,Asgm2,Asmnt3,Asmnt4,Asmnt5,midterm,final,total;
//input 1
cout<<"Assignment1 score=";
cin>>Asmnt1;
//input 2
cout<<"Assignment2 score=";
cin>>Asmnt2;
//input 3
cout<<"Assignment3 score=";
cin>>Asmnt3;
//input 4
cout<<"Assignment4 score=";
cin>>Asmnt4;
//input 5
cout<<"Assignment5 score=";
cin>>Asmnt5;
//input 6
cout<<"Midterm score=";
cin>>midterm;
//input 7
cout<<"Final score=";
cin>>final;
//formula
total=Agntm1+Asmnt2+Asmnt3+Asmnt4+Asmnt5+midterm+final;
//output
cout<<"Assignment1 is="<<Asmnt1;
cout<<"Assignmnet2 is="<<Asmnt2;
cout<<"Assignment3 is="<<Asmnt3;
cout<<"Assignment4 is="<<Asmnt4;
cout<<"Assignment5 is="<<Asmnt5;
cout<<"Midterm is="<<midterm;
cout<<"Final is="<<final;
cout<<"Total is="<<total;
return 0;
}
main ()
{
//variable
float Asmnt1,Asgm2,Asmnt3,Asmnt4,Asmnt5,midterm,final,total;
//input 1
cout<<"Assignment1 score=";
cin>>Asmnt1;
//input 2
cout<<"Assignment2 score=";
cin>>Asmnt2;
//input 3
cout<<"Assignment3 score=";
cin>>Asmnt3;
//input 4
cout<<"Assignment4 score=";
cin>>Asmnt4;
//input 5
cout<<"Assignment5 score=";
cin>>Asmnt5;
//input 6
cout<<"Midterm score=";
cin>>midterm;
//input 7
cout<<"Final score=";
cin>>final;
//formula
total=Agntm1+Asmnt2+Asmnt3+Asmnt4+Asmnt5+midterm+final;
//output
cout<<"Assignment1 is="<<Asmnt1;
cout<<"Assignmnet2 is="<<Asmnt2;
cout<<"Assignment3 is="<<Asmnt3;
cout<<"Assignment4 is="<<Asmnt4;
cout<<"Assignment5 is="<<Asmnt5;
cout<<"Midterm is="<<midterm;
cout<<"Final is="<<final;
cout<<"Total is="<<total;
return 0;
}
Saturday, March 5, 2011
PROGRAMMING EXERCISE 2
#include<iostream.h>
main()
{
int number1,number2,number3;
float calculate;
cout<<"enter num1=";
cin>>number1;
cout<<"enter num2=";
cin>>number2;
cout<<"enter num3=";
cin>>number3;
calculate=(number1*number2)-number3+(number2/number1);
cout<<"num1="<<number1;
cout<<"num2="<<number2;
cout<<"num3="<<number3;
cout<<"calculate="<<calculate;
return 0;
}
PROGRAMMING EXERCISE 1
#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;
}
Tuesday, March 1, 2011
ANSWER EXERCISE (IF ELSE & SWITCH CASE)
2. 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 _____________
ANSWER.
2)#include<iostream.h>
main()
{
char a,b,c,d,e,selection;
float rectangle,triangle,circle,fahrenheit,celcius,h1,h2,w1,b1,f1,r1,c1;
cout<<"\ncalculate:-";
cout<<"\na)rectangular";
cout<<"\nb)triangle";
cout<<"\nc)circle";
cout<<"\nd)fahrenheit";
cout<<"\ne)celcius";
cout<<"\n\n Enter your selection=";
cin >>selection;
if (selection=='a' || selection=='A')
{
cout<<"Enter your height=";
cin>>h1;
cout<<"Enter your width=";
cin>>w1;
rectangle=h1*w1;
cout<<"Your selection is a and you are calculate rectangular.the answer is="<< rectangle;
}
else if(selection=='b'|| selection=='B')
{
cout<<"Enter your base=";
cin>>b1;
cout<<"Enter your height=";
cin>>h2;
triangle=0.5*b1*h2;
cout<<"Your selection is b and you are calculate triangle.the answer is="<< triangle;
}
else if(selection=='c' || selection=='C')
{
cout<<"Enter your radius=";
cin>>r1;
circle=3.1452*r1*r1;
cout<<"Your selection is c and you are calculate circle.the answer is="<< circle;
}
else if(selection=='d' || selection=='D')
{
cout<<"Enter your celcius=";
cin>>c1;
fahrenheit=1.8*(c1+32);
cout<<"Your selection is d and you are calculate fahrenheit.the answer is="<< fahrenheit;
}
else if(selection=='e' || selection=='E')
{
cout<<"Enter your fahrenheit=";
cin>>f1;
celcius=0.56*(f1-32);
cout<<"Your selection is e and you are calculate celcius.the answer is="<< celcius;
}
else
{ cout<<"Invalid selection";}
return 0;
}
CALCULATE:
a) RECTANGULAR
b) TRIANGLE
c) CIRCLE
d) FAHRENHEIT
e) CELCIUS
Your Selection:
Your Selection is _________ and you are calculate _________. The answer is _____________
ANSWER.
2)#include<iostream.h>
main()
{
char a,b,c,d,e,selection;
float rectangle,triangle,circle,fahrenheit,celcius,h1,h2,w1,b1,f1,r1,c1;
cout<<"\ncalculate:-";
cout<<"\na)rectangular";
cout<<"\nb)triangle";
cout<<"\nc)circle";
cout<<"\nd)fahrenheit";
cout<<"\ne)celcius";
cout<<"\n\n Enter your selection=";
cin >>selection;
if (selection=='a' || selection=='A')
{
cout<<"Enter your height=";
cin>>h1;
cout<<"Enter your width=";
cin>>w1;
rectangle=h1*w1;
cout<<"Your selection is a and you are calculate rectangular.the answer is="<< rectangle;
}
else if(selection=='b'|| selection=='B')
{
cout<<"Enter your base=";
cin>>b1;
cout<<"Enter your height=";
cin>>h2;
triangle=0.5*b1*h2;
cout<<"Your selection is b and you are calculate triangle.the answer is="<< triangle;
}
else if(selection=='c' || selection=='C')
{
cout<<"Enter your radius=";
cin>>r1;
circle=3.1452*r1*r1;
cout<<"Your selection is c and you are calculate circle.the answer is="<< circle;
}
else if(selection=='d' || selection=='D')
{
cout<<"Enter your celcius=";
cin>>c1;
fahrenheit=1.8*(c1+32);
cout<<"Your selection is d and you are calculate fahrenheit.the answer is="<< fahrenheit;
}
else if(selection=='e' || selection=='E')
{
cout<<"Enter your fahrenheit=";
cin>>f1;
celcius=0.56*(f1-32);
cout<<"Your selection is e and you are calculate celcius.the answer is="<< celcius;
}
else
{ cout<<"Invalid selection";}
return 0;
}
Subscribe to:
Posts (Atom)