GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 194 of 203    Print  
Length Conversion Program
Write a program that will read in a length in feet and inches and will output the equivalent length in meters and centimeter. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he wants to end the program. There are meter in a foot, 100 centimeters in a meter, and 12 inches in a foot.


  
Total Answers and Comments: 1 Last Update: July 03, 2009     Asked by: DM27dexter 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 01, 2009 14:27:49   #1  
javierisassi Member Since: June 2009   Contribution: 2    

RE: Length Conversion Program
#include "iostream"

using namespace std;

struct metric{
int meters;
int centimeters;
};

struct english{
int feet;
int inches;
};

void input( english &value ) {
std::cout << "Type zeroes to exit:n";
std::cout << "Give me the feet: ";
std::cin >> value.feet;
std::cout << "Give me the inches: ";
std::cin >> value.inches;
while ( value.inches > 11 ) {
value.feet + 1;
value.inches - 12;
}
std::cout << "Feet: " << value.feet << "ninches: " << value.inches << std::endl;
}

void output( metric &value ) {
std::cout << "Meters: " << value.meters << "ncentimiters: " << value.centimeters << std::endl;
}

void convert_to_metric( english &value1 metric &value2){
// convert all to inches and multiply by 2.58 to get centimeters
value2.centimeters (int)(((value1.feet * 12) + value1.inches ) * 2.58);
while ( value2.centimeters > 99 ){
value2.meters + 1;
value2.centimeters - 100;
}
}

int main( void ) {
english e_value {0};
metric m_value {0};
do {
input(e_value);
convert_to_metric(e_value m_value);
output(m_value);
m_value.meters 0;
m_value.centimeters 0;
}
while ( e_value.feet ! 0 && e_value.inches ! 0 );
return 0;
}


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    

 Related Questions

 Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.  Ø      A Class 
Latest Answer : Class is a combination of data member & member function where object is used for calling function In class we declare In object we call ...

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching 
Latest Answer : Virtual constructor is not build-in C++ feature but it doesn't mean its not used by devs in code and in conversations. There are many other things that doesn't exist in particular language yet, people find ways around to solve it (SingleTon, Virtual Constructor, ...

Latest Answer : if the solution is needed for the unix platform. Then you can create a pthread at the bottom of the program, take the current process id of the parent and make it a deamon by using the standard unix calls like detach(), chdir().. etc. Check if the parent ...
Read Answers (3) | Asked by : suji

What will be output of the following code#includeusing namespace std;class abc{ public : void main() { cout
Read Answers (5) | Asked by : Avaited

Hey anybody help me to write code for this programwap which display year,month & day presents in a year for eg.1. no. is 14 print 2 weeks2. no is 90 print 3 months3. no is 365 print 1 yearuser can input any no
Read Answers (3) | Asked by : avingle

Latest Answer : include#includeusing namespace std;int main(){             fstream *obj = new fstream();             obj->open ("main.cpp"); ...
Read Answers (4) | Asked by : arup

Write a program to dynamically create a matrix( no of rows and columns wud be provided by user at run time). Then ask a user to input elements and the nprint those elements.

Suppose there is a txt file with following format:Student name Grades in subjectsX ABA+CDA+Y B+CAA+AAthere can be many students with there grades in various subjects. (number of subjects are unknown)Possible values of grade are: A, A+, B, B+, C, D now suppose the file gets corrupted and all '+' are replaced by 'A'Write a program to restore the file
Tags : Restore

Latest Answer : In LINUX environment one can use VALGRIND and MPATROL free tools to find out possible memory leaks in programs. ...
Read Answers (6) | Asked by : rusty_man

Write a program to concatenate two circular linked lists into a single circular list. 
Latest Answer : class node {public:  node(int n) : m_n(n) { m_pNext = this; }  ~node() {}  void SetNext( node* p ) { m_pNext = p; }  node* GetNext() const { return m_pNext; }  int GetData() const { return m_n; }  static ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

What is Data Conversion

Data Conversion, as the name implies, deals with changes required to move or convert data from one physical environment format to that of another, like moving data from one electronic medium or database product onto another format. Every day, data is being shared from one computer to another. This i
 

How to develop compile and run a C program

The steps involved in building a C program are: 1. First program is created by using any text editor and the file is stored with extension as .c 2. Next the program is compiled. There are many compilers available&nbsp;like GNU C compiler called as gcc, Sun compiler, Borland compiler which is pop
 

Conversion in C

How does a conversion occur in C? The data types for numerical operations used in C are integer, float. It is important to know how conversions occur between these two data types in numerical operations. Some of the facts about conversions are given below: Integer having arithmetic operatio
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape