0% found this document useful (1 vote)
311 views2 pages

Cpa Lab 2 1 5 (3) - B

The document describes writing a program to convert between metric and imperial measurement systems by asking the user to input their system and then a distance value, and outputting the equivalent value in the other system, with examples of expected input/output pairs given.

Uploaded by

Cristian Leal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
311 views2 pages

Cpa Lab 2 1 5 (3) - B

The document describes writing a program to convert between metric and imperial measurement systems by asking the user to input their system and then a distance value, and outputting the equivalent value in the other system, with examples of expected input/output pairs given.

Uploaded by

Cristian Leal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CPA: Programming

Essentials in C++ C++ INSTITUTE - PROGRAM YOUR FUTURE

Lab 2.1.3 Some actual evaluations - converting measurement systems


Objectives
Familiarize the student with:

finding information useful to solving typical problems;


implementing a simple conversational interface;
constructing branched, multifunctional code;
preparing clearly formatted output.

Scenario
Among the many measurement systems available, two seem to be the most widespread: metric and imperial. To make things simpler, we
assume that the first one uses the "meter" as its only unit (expressed as a real number), while the second uses the "foot" (always an
integer) and the "inch" (a real number).

Your task is to write a simple "measurement converter". We want it to perform the following actions:

ask the user which system she/he uses to input data; we assume that 0 means "metric" and 1 means "imperial";
depending on the user's answer, ask either for meters or feet and inches;
output the distance in proper (different) units: either in feet and inches or in meters;
a result outputted as metric should look like 123.4m;
a result outputted as imperial should look like 12'3.5".

Look at the code below – it's only a template. Use it to implement the whole converter.

Make your code smart – it shouldn't be fooled by stupid or unreasonable inputs.

Test your code using the data we've provided.

#include <iostream>

using namespace std;

int main(void) {
int sys;
float m, ft, in;

// Insert your code here

return 0;
}

Example input
0
1

Example output
3'3.37008"

Example input
1
3
3.37008

© 2017 C++ Institute. All rights reserved. Last updated: March 07, 2017 | www.cppinstitute.org Page 1 of 2
Lab 2.1.3 Some actual evaluations - converting measurement systems

Example output
1m

Example input
0
0.0254

Example output
0'1"

Example input
1
0
1

Example output
0.0254m

© 2017 C++ Institute. All rights reserved. Last updated: March 07, 2017 | www.cppinstitute.org Page 2 of 2

You might also like