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

Assignment Help:

 

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


Related Discussions:- C program to change feet and inches into meter

GPA Calculator, I am having trouble declaring a variable and returning a va...

I am having trouble declaring a variable and returning a value from my function.

Example of function - c program, Here is a short program. It prints out the...

Here is a short program. It prints out the value of a variable "x". Ernie and Bert disagree about what will be printed: Ernie says, the value gets changed in "changeX" so it will p

C program to calculate area of cube, Aim: To implement program to calculat...

Aim: To implement program to calculate area of cube using inline function. Code: inline void area_cube(float side) {             float area;             are

Introduction of c, Discuss the saleint featuresand application of c

Discuss the saleint featuresand application of c

I want vlc pitch changing addon, I want VLC Pitch Changing Addon Project...

I want VLC Pitch Changing Addon Project Description: Required: Plugin to modify the pitch of running tracks in VLC without changing the speed. Skills required are C Progra

Luminous Jewels, Jewels can only be removed for polishing from either end o...

Jewels can only be removed for polishing from either end of the necklace

Oop, write a program which has three classes

write a program which has three classes

Plugging the memory leak, Problem #1: plugging the memory leak. When you em...

Problem #1: plugging the memory leak. When you employ the "normal" new operator, for example Foo* p = new Foo(), the compiler generates some special code to manage the case while t

What does odbc do in context with php, What does ODBC do in context with PH...

What does ODBC do in context with PHP? PHP supports many databases such as dBase, Microsoft SQL Server, Oracle, etc. however, it also supports databases such as filePro, FrontB

Define auto pointer?, A: The simplest instance of a smart pointer is auto_p...

A: The simplest instance of a smart pointer is auto_ptr that is included in the standard C++ library. Auto Pointer only takes care of Memory leak & does nothing regarding dangling

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd