Tuesday, March 13, 2012

C++: Length and Height Conversion Program

#include <iostream>
using namespace std;

int meter_mill (int m)
{
  int mill;
  mill=m*1000;
  return (mill);
}
int meter_cent (int a)
{
  int cent;
  cent=a*100;
  return (cent);
}
double meter_kil (double a )
{
  double kil;
  kil=a*.001;
  return (kil);
}
double meter_inc (double a)
{
  double inc;
  inc=a*39.37008;
  return (inc);
}
 double meter_feet (double a)
{
  double feet;
  feet=a*3.28084;
  return (feet);
}
double meter_yard (double a)
{
  double yard;
  yard=a*1.09361;
  return (yard);
}
double meter_mile (double a)
{
  double mile;
  mile=a*6.2;
  return (mile);
}
double meter_naut_mile (double a)
{
  double naut_mile;
  naut_mile=a*5.4;
  return (naut_mile);
}
int main ()
{

  char choice;
  double mm,cm,km,in,ft,yrd,m,nm;
  double n;
  cout<<"Choose a Unit of Measurement: \na-Meter-Millimeter \nb-Meter-Centimeter\nc-Meter-Kilometer\nd-Meter-Inches\ne-Meter-Feet\nf-Meter-Yard\nj-Meter-Mile\nk-Meter-Nautical Mile"<<endl;
  cin>>choice;
  switch (choice)
  {
  case 'a':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    mm = meter_mill (n);
    cout << "The height in milimeter is "<<mm<<endl;
    break;
    case 'b':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    cm = meter_cent (n);
    cout << "The height in centimeter is "<<cm<<endl;
    break;
    case 'c':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    km = meter_kil (n);
    cout << "The height in Kilometer is "<<km<<endl;
    break;
    case 'd':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    in = meter_inc (n);
    cout << "The height in Inches is "<<in<<endl;
    break;
    case 'e':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    ft = meter_feet (n);
    cout << "The height in Feet is "<<ft<<endl;
    break;
    case 'f':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    yrd = meter_yard (n);
    cout << "The height in Yard is "<<yrd<<endl;
    break;
    case 'j':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    m = meter_mile (n);
    cout << "The height in Miles is "<<m<<endl;
    break;
    case 'k':
    cout<<"Enter Number of Meter: ";
    cin>>n;
    nm = meter_naut_mile (n);
    cout << "The height in Nautical Miles  is "<<nm<<endl;
    break;
    default:
    cout<<"Out of coverage"<<endl;
    }
  return 0;
}

Monday, March 12, 2012

C++: Compute for the Volume (Rectangular, Cone, Cylinder etc)



#include <iostream>
using namespace std;
 
int rectangular (int l, int w, int h)
{
  int rect_vol;
  rect_vol=l*w*h;
  return (rect_vol);
}
int prism (int a, int b)
{
  int pri_vol;
  pri_vol=a*b;
  return (pri_vol);
}
int cylinder (int a, int b)
{
  int cyl_vol,pi=3.1416;
  cyl_vol=((pi)*(a*a)*b);
  return (cyl_vol);
}
double pyramid (double a, double b)
{
  double pyr_vol;
  pyr_vol=(a*b)/3;
  return (pyr_vol);
}
 int cones (int a, int b)
{
  int con_vol,pi=3.1416;
  con_vol=((pi)*((a*a)*b))/3;
  return (con_vol);
}
double sphere (int a)
{
  int sph_vol,pi=3.1416;
  sph_vol=(4/3)*((pi)*(a*a*a));
  return (sph_vol);
}

int main ()
{
 
  char choice;
  double l,w,h,r,b,pi=3.1416;
  double rec,pri,cyl,pyr,con,sph;
  cout<<"Choose a polygon: \na-Rectangular \nb-Prism\nc-Cylinder\nd-Pyramid\ne-Cones\nf-Sphere"<<endl;
  cin>>choice;
  switch (choice)
  {
  case 'a':
cout<<"Enter length";
cin>>l;
cout<<"Enter width";
cin>>w;
cout<<"Enter height";
cin>>h;
rec = rectangular (l,w,h);
cout << "The volume of the rectangle is "<<rec;
break;
case 'b':
cout<<"Enter base";
cin>>b;
cout<<"Enter height";
cin>>h;
pri = prism (b,h);
cout << "The volume of the prism is "<<pri;
break;
case 'c':
cout<<"Enter radius";
cin>>r;
cout<<"Enter height";
cin>>h;
cyl = cylinder (r,h);
cout << "The volume of the cylinder is "<<cyl;
break;
case 'd':
cout<<"Enter base";
cin>>b;
cout<<"Enter height";
cin>>h;
pyr = pyramid (b,h);
cout << "The volume of the pyramid is "<<pyr;
break;
case 'e':
cout<<"Enter radius";
cin>>r;
cout<<"Enter height";
cin>>h;
con = cones (r,h);
cout << "The volume of the cones is "<<con;
break;
case 'f':
cout<<"Enter radius";
cin>>r;
sph = sphere (r);
cout << "The volume of the sphere is "<<sph;
break;
default: 
cout<<"Out of coverage"<<endl;
}
  return 0;
}