C program to change feet and inches into meter, C/C++ Programming

 

Aim: To implement a program to convert distance given in feet and inches into meters and centimeters and vice versa.

Code:                      

 

class mcm;

class inchft

{

            float ft;

            float inch;

            public:

            friend void convert(inchft,mcm);

};

class mcm

{

            float m;

            float cm;

            public:

            friend void convert(inchft,mcm);

};

void convert(inchft a,mcm b)

{

            int ch,i,c;

            do

            {

                        cout<<"\n1.Feet & inches to Meters & centimeters";

                        cout<<"\n2. Meters & Centimeters to Feet & inches";

                        cout<<"\n0. Exit\nEnter choice:";

                        cin>>ch;

                        switch(ch)

                        {

                                    case 1:

                                    cout<<"Enter measurement in feet & inches:";

                                    cout<<"ft:";

                                    cin>>a.ft;

                                    cout<<"inch:";

                                    cin>>a.inch;

                                    cout<<"\nYou entered:"<

                                    i=(a.inch+(12.0*a.ft));

                                    c=2.5*i;

                                    c=ceil(c);

                                    b.cm=c%100;

                                    b.m=(c-b.cm)/100;

                                    cout<<"\n\nAfter conversion:"<

                                    break;

 

                                    case 2:

                                    cout<<"Enter measurement in meters & centimeters:";

                                    cout<<"m:";

                                    cin>>b.m;

                                    cout<<"cm:";

                                    cin>>b.cm;

                                    cout<<"\nYou entered:"<

                                    c=(b.cm+(100*b.m));

                                    i=0.4*c;

                                    i=ceil(i);

                                    a.inch=i%12;

                                    a.ft=(i-a.inch)/12;

                                    cout<<"\n\nAfter conversion:"<

                                    break;

 

                                    case 0:

                                    break;

                        }

            }while(ch!=0);

}

 

void main()

{

            clrscr();

            inchft a;

            mcm b;

           convert(a,b);

            getch();

}

 

Output:

1.Feet & inches to Meters & centimeters

2. Meters & Centimeters to Feet & inches

0. Exit

Enter choice:1

Enter measurement in feet & inches:ft:20

inch:10

You entered:20 ft 10 inches

 

After conversion:6 m 25 cm

1.Feet & inches to Meters & centimeters

2. Meters & Centimeters to Feet & inches

0. Exit

Enter choice:2

Enter measurement in meters & centimeters:m:6

cm:25

You entered:6 m 25 cm

After conversion:20 ft 10 inches

1.Feet & inches to Meters & centimeters

2. Meters & Centimeters to Feet & inches

0. Exit

Enter choice:0

Posted Date: 9/29/2012 4:02:07 AM | Location : United States







Related Discussions:- C program to change feet and inches into meter, Assignment Help, Ask Question on C program to change feet and inches into meter, Get Answer, Expert's Help, C program to change feet and inches into meter Discussions

Write discussion on C program to change feet and inches into meter
Your posts are moderated
Related Questions

Introduction to C++ C++ was developed by Bjarne Stroustrup at Bell Laboratories in 1983. Originally, it was known as " C with class". C+ as an enhancement to the C language was

Objective of this Program: (a) To learn more about modularization of a program into independent modules, (b) To use arrays in a program, (c) To get some experience with us

Write a simple program in C++ to investigate the safety of its enumeration types. Include at least 10 different operations on enumeration types that are incorrect/unsafe things to

Program to Open a file in C++: int main() {                  char ch;                  ifstream f1 ("OLDFILE.TXT");                  ofstream f2 ("NEWFILE.TXT");

This is what I need help with. "Create a program creates an interface allowing the user to select from some other programs I have made one being a money converter and the other ca

Stage One Define the specification of the program            Add two nxm size matrices   Stage Two Divide the program up into separate modules           Input Matrix         Ad

i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

Depreciation to a salvage value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight line method of depreciati

What do you mean by a sequential access file? - When writing programs which store and retrieve data in a file, it's possible to designate that file into various forms. - A s