Monday 4 February 2013

IT series Control Structure Part 17:

Converter program :
Centimeter-->Inches
Litre-->Gallon
Kilometer-->Miles
Kilogram-->Pounds

This is the code:


#include<iostream.h>
#include<stdio.h>
void main()
{
printf("This is the menu:\n\n");
cout<<" Inch<--> Centimeter\nGallon<-->Litres\nMile<-->Kilomemter\nPound<-->Kilogram\n\n";
cout<<"Now acording to your choice: select it\n";
cout<<"inch->centimeter press 1\nCentimetr->inch press 2\nLitr->Gallon press 3\nGallon->Litre press 4\n";
cout<<"Mile->Kilometr press 5\nKilomter->Mile press 6\nPound->Kilogram press 7\nKilogram->pound press 8\n\n";

int a;float z,b;
cin>>a;
switch(a)
{
case 1:
cout<<"Enter your unit value\n";
cin>>z;

b=z*2.54;
cout<<"\nThis is the conversion result of inch to centimeter\n"<<b<<endl;
case 2:
cout<<"Entr your unit value:\n";
cin>>z;
b=(1.0/2.54)*z;
cout<<"This is the conversion result of Centimeter to inch\n"<<b<<endl;
case 3:
cout<<"Entr your unit value:\n";
cin>>z;
b=z*3.785;
cout<<"\nThis is the conversion of Gallon to Litre\n"<<b<<endl;
case 4:
cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/3.785)*z;
cout<<"This is the conversion result of Litre to Gallon\n"<<b<<endl;
case 5:
        cout<<"Enter your unit value:\n";
cin>>z;
b=z*1.609;
cout<<"This is the conversion of Mile to Kilometers\n"<<b<<endl;
case 6:
        cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/1.609)*z;
cout<<"This is the conversion of Kilometer to Mile\n"<<b<<endl;
case 7:
cout<<"Enter your unit value:\n";
cin>>z;
b=z*.4536;
cout<<"This is the conversion of Pound to Kilogram\n"<<b<<endl;
case 8:
   cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/.4536)*z;
cout<<"This is the conversion of Kilogram to pound\n"<<b<<endl;
default:
cout<<"Please try again and enter a valid option\n";
}
}

IT series Control Structure Part 13:


Find the roots of the Quadratic Equation:
ax2+bx+C=0

#include<iostream.h>
#include<stdio.h>
#include<math.h>
void main()
{
printf("This program solve the quadratic equation and find out the real roots of the equation\n");
cout<<"Kindly just enter the coeffint of the equation ax^2+bx+c\n\n";
int a,b,c;
cout<<"Enter units\n\n";cin>>a>>b>>c;
float z,x,v,n;
x=pow(b,2)-4*a*c;
z=sqrt(x);
    if(z>=0)
{
v=((-b+z)/(2*a));
cout<<"This is first root\n"<<v<<endl;
v=((-b-z)/(2*a));
cout<<"This is second root of this quadratic equation\n\n"<<v<<endl;
}
else
cout<<"Roots are not real\n";
}


IT series Control Structure Part 8:

Conversion of some Numerical Identities:
Converter program :

Centimeter-->Inches
Litre-->Gallon
Kilometer-->Miles
Kilogram-->Pounds


#include<iostream.h>
#include<stdio.h>
void main()
{
printf("This is the menu:\n\n");
cout<<" Inch<--> Centimeter\nGallon<-->Litres\nMile<-->Kilomemter\nPound<-->Kilogram\n\n";
cout<<"Now acording to your choice: select it\n";
cout<<"inch->centimeter press 1\nCentimetr->inch press 2\nLitr->Gallon press 3\nGallon->Litre press 4\n";
cout<<"Mile->Kilometr press 5\nKilomter->Mile press 6\nPound->Kilogram press 7\nKilogram->pound press 8\n\n";

int a;float z,b;
cin>>a;
switch(a)
{
case 1:
cout<<"Enter your unit value\n";
cin>>z;

b=z*2.54;
cout<<"\nThis is the conversion result of inch to centimeter\n"<<b<<endl;
case 2:
cout<<"Entr your unit value:\n";
cin>>z;
b=(1.0/2.54)*z;
cout<<"This is the conversion result of Centimeter to inch\n"<<b<<endl;
case 3:
cout<<"Entr your unit value:\n";
cin>>z;
b=z*3.785;
cout<<"\nThis is the conversion of Gallon to Litre\n"<<b<<endl;
case 4:
cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/3.785)*z;
cout<<"This is the conversion result of Litre to Gallon\n"<<b<<endl;
case 5:
        cout<<"Enter your unit value:\n";
cin>>z;
b=z*1.609;
cout<<"This is the conversion of Mile to Kilometers\n"<<b<<endl;
case 6:
        cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/1.609)*z;
cout<<"This is the conversion of Kilometer to Mile\n"<<b<<endl;
case 7:
cout<<"Enter your unit value:\n";
cin>>z;
b=z*.4536;
cout<<"This is the conversion of Pound to Kilogram\n"<<b<<endl;
case 8:
   cout<<"Enter your unit value:\n";
cin>>z;
b=(1.0/.4536)*z;
cout<<"This is the conversion of Kilogram to pound\n"<<b<<endl;
default:
cout<<"Please try again and enter a valid option\n";
}
}

IT series Control Structure Part 5:

Conversion of temperature:

void main()
{
char a;
cout<<"Enter C for Celcius to Farenhiet:\nEnter F for farenheit to celcius\n";
cin>>a;
if(a=='C')
{
int b;
cout<<"Enter the temprature in celcius: ";cin>>b;cout<<"You enter the Celcius temprature as:"<<b<<"C"<<endl;
float bb;
bb=(9.0/5.0)*b+32;
cout<<"This is the temprature in Farenheit:"<<bb<<endl;
}
else
{
int b;
cout<<"Enter the temprature in Farenheit: ";cin>>b;cout<<"You enter the farenheit temprature as:"<<b<<"F"<<endl;
float bb;
bb=((b-32.0)*(5.0/9.0));
cout<<"This is the temprature in Celcius:"<<bb<<endl;
}
}

IT series Control Structure part 3:

To check wheter the third one is the common divisior of the first and second one.

void main()
{
int a,b,c;
cout<<"Enter three numbers\n";
cin>>a>>b>>c;

if(a==0)
cout<<"Sorry try again\n";
else
{
if(b%a==0 && c%a==0)
cout<<"The first number is divisble of the second and third one\n";
else
cout<<"First variable is not divisor of the second and third one\n";
}
}