CISC1600: Computer Science I Lab 6

Purpose: In this lab assignment of CIS1600, we will practice the design and implementation of functions in the setting of conversion of lengths between feet/inches and meters.

Instruction: We will write a program that prompts the user to enter a length given in feet and inches, and and then converts it to equlvalent length in meters, and display the result. There are 0.3048 meters in a foot, and 12 inches in a foot. Please name your source code as lab6.cpp.

Your program works as follows:

  1. Prompt the user to enter the length in feet and inches in the format of ft'inch''.
  2. If the input is not valid (e.g., the feet or inch is negative, or the inch is not within 1 and 11), make the user try again unitl a valid length is entered.
  3. Convert the length to meter and output the result in the format of 168.23 cm (i.e., we want to have two decimal digits.)

An example run of your program is as follows, where the user inputs are underlined, and the program output are shown in regular format:

$ ./a.out
Please enter the length in the format of (ft'inch''):5'10''
5'10''= 177.80 cm
Do you want to do another converstion (y/n):y
Please enter the length in the format of (ft'inch''):5'6''
5'6''= 167.64 cm
Do you want to do another converstion (y/n):n
Bye!
Here is another run shows some wrong inputs and the error messages:
$ ./a.out
Please enter the length in the format of (ft'inch''):6'14''
Wrong input! Inches should be between 0 and 11. Try again:-1'4''
Wrong input! Feet should be positive. Try again:2'4''
2'4'' = 76.20 cm
Do you want to do another converstion (y/n):n
Bye!

Program Structure Requirement: In your program

#include 
using namespace std;

/* Declare all functions here */

...

int main()
{

}

/* Define all your functions here */



...
You are required to design and implement the following functions:
  1. A function that reads the length in feet and inches, checks for the validity and display error message, until a valid input is entered.
    	void ReadLengthFeetInches (int & feet, int & inches);
    		
  2. A function that convert the length in feet and inches and return its equivalent lenth in meters. double ToMeters(int feet, int inches);
  3. A function that display the length in meters in the required format.
    		#include <iomanip>
    		...
    		//displaying num1 in the format of 10.32
    		double num1=10.324;
    		cout <<fixed <<showpoint;
    		cout <<setprecision(2);
    		cout <<num1;
    		
  4. A function that display the length in feet and inches in the required format.
Coding Style Requirement:
  1. Please indent your code in as required.
  2. Use descriptive names for variables
  3. Use blank lines to separate the code into appropriate blocks
  4. Be sure to include comments to help others understand your program, and help yourself think!

How to submit

Please submit your program (which has to be named lab6.cpp) to the following webpage:

Lab6 submission link.