Starting from:

$30

Assignment 2 - Manipulating Numeric Data

Assignment 2 - Manipulating Numeric Data

Executive Summary
You will develop a program that performs various conversions (time, weight, temperature, currency,
distance).
Purpose
● Learn how to input and output numeric values using formatted I/O library functions
● Learn how to define and symbolically manipulate numeric data
● Learn how to use basic programming constructs, specifically loops and conditionals
● Sharpen your problem solving skills and general programming skills
Deliverables
The assignment-2.c program source file implementing the functionality described below. All your code
should go into this file.
Make sure to name the file assignment-2.c and place it in a separate “assignment2” folder in
your repo. The path should be: assignment2/ assignment-2.c
For this assignment we will be creating a .c file and not a .cpp file.
Your repo should have ONLY one “assignment2” folder, and that folder should contain ONLY
the “assignment-2.c”
Introduction
Our customer is planning a trip to Ireland, and would like a program that can help him perform
conversions between the following:
● Irish time and Austin time
● Euros and US Dollars
● Fahrenheit and Celsius
● Kilograms and Pounds
● Kilometers and Miles
In each case, you will have to support conversions in both directions.
Time
Your input will be two whole numbers, the hour (which ranges from 0 to 23, inclusive) and the number
of minutes (which ranges from 0 to 59, inclusive). For example, when Austin is on CST and it is
9:00am in Austin, it is 3:00pm in Ireland, on the same day. All times will be in 24 hour format, in
which Ireland time = (Austin hours + 6) mod 24 and Ireland minutes = Austin minutes.
Currency
Ireland uses the Euro. To convert from Euros to US Dollars, multiply the quantity of Euros by 1.13
.
When converting from US Dollars to Euros, the input will be given as two integers (the dollar quantity
and the cents quantity). Your output should be the Euro equivalent expressed as a real number. The
conversion rate is 0.89.
When converting from Euros to US Dollars, the input will be given as a real number. Your output
should be the converted number of dollars and cents, i.e., reported as two whole numbers. The number
of cents should be rounded to the nearest whole number.
Temperature
The relationship between temperature readings in Fahrenheit and in Celsius is given by the following
equations:
C = (5/9) (F-32)
F = (9/5) C + 32
Note: This is not valid C syntax!
Fahrenheit temperatures must be expressed in integers. Celsius temperatures are real numbers.
Your program must convert a given Fahrenheit temperature, expressed as an integer, to Celsius,
expressed as a real number, and vice versa. When converting from Celsius to Fahrenheit use rounding
to get an integer.
Weight
The kilogram is the basic unit of weight used in Ireland. One kilo equals 1000 grams. The basic unit of
weight in the US is the pound. One pound equals 16 ounces.
One pound equals exactly 453.59237 grams.
US weights will be expressed as a pair of whole numbers denoting the number of pounds and ounces.
Kilograms and grams will be expressed as real numbers.
When converting from pounds and ounces into Kilograms, the result is a real number representing the
equivalent number of kilograms. When converting from kilograms to pounds and ounces, round to the
nearest whole number.
Distance
One kilometer equals 0.6213712 miles. All distances will be expressed as real numbers.
Requirements
Setup
1. Create a Project named assignment2 in Visual Studio for this lab.
2. From the Solution Explorer, add the file assignment-2.c to your assignment2 project.
Input format
Your program should prompt for and then receive input value for the selected conversion to be
performed and also the values to be converted. All input is read from the keyboard using the scanf
library function. Output messages (described later) prompt the user for inputs.
Your program should work correctly for all legitimate values that are input.
If a bad input value is given, then your program may terminate or give a bad output value.
Conversion Menu
Use the following conversion menu in your assignment
1. Convert a given Austin time to Irish time
2. Convert a given Irish time to Austin time
3. Convert a given USD value to EUR
4. Convert a given EUR value to USD value
5. Convert a given Fahrenheit temperature to Celsius
6. Convert a given Celsius temperature to Fahrenheit
7. Convert a given weight in kg to pounds, ounces
8. Convert a given weight in pounds, ounces to kg
9. Convert a given distance in km to miles
10.Convert a given distance in miles to km
11.Stop doing conversions and quit the program
You do not need to print the menu to the console.
Output format
Use the printf library function for all output.
Your program should start by prompting the user for a conversion as follows:
“Enter a number from the menu (1-11) to select a specific conversion to perform or to quit:”
For each of the conversions given in the menu above, use the following input and output formats.
Do not print the bullets (1. 2. …) to the console. They are places just to show you the input and output
formats for each conversion from the conversion menu.
1. Enter Austin time to be converted, expressed in hours and minutes: <hours minutes
The time in Ireland equivalent to <hours minutes in Austin is <hours minutes of the
<previous, <same or <next day
2. Enter Irish time to be converted, expressed in hours and minutes: <hours minutes
The time in Austin equivalent to <hours minutes in Ireland is <hours minutes of the
<previous, <same or <next day
3. Enter USD value: <dollars <cents
EUR value is: <euro-value Euros
4. Enter EUR value: <eur-value
USD value is: $<dollars <cents
5. Enter temperature in Fahrenheit: <temperature-in-Fahrenheit
Temperature in Celsius is: <temperature-in-Celsius
6. Enter temperature in Celsius: <temperature-in-Celsius
Temperature in Fahrenheit is: <temperature-in-Fahrenheit
7. Enter weight in kg: <weight-in-kg
Weight in pounds and ounces is: <pounds lb <ounces oz
8. Enter weight in pounds and ounces: <pounds ounces
Weight in kg is: <weight-value-in-kg kg
9. Enter distances in km: <distance-in-km
Distance in miles is: <distance-value-in-miles mi
10. Enter distance in miles: <distance-in-miles
Distance in km is: <distance-in-km k
11. Good Bye
An example of the dialog between the user and your program is given below, with user input being
shown in boldface:
Enter a number from the menu (1-11) to select a specific conversion to perform or to quit: 2
Enter an Irish time to be converted, expressed in hours and minutes: 1 30
The time in Austin equivalent to 1 30 in Ireland is 19 30 of the previous day
Enter a number from the menu (1-11) to select a specific conversion to perform or to quit: 11
Good Bye
Design and implementation constraints
● Use the formatted IO functions presented in class and found in your textbook.
○ Input specific values from the standard input device, i.e., keyboard, using scanf()
○ Use the printf() function as shown in class to output the menu, the prompts, and your
program’s results to the standard output device, i.e., monitor/terminal window.
● Use symbolic formulae for each specific conversion.
● Use appropriately named variables to represent the given and converted values in each category.
● Use the int and double data types for the variables needed by each conversion formula.
● Use “%lf” for scanf() for reading in double
● Use meaningful variable names so that your program is understandable by other humans, in
addition to being legal identifiers according to the C compiler.
● Use const identifiers in upper case (CAPS) for the conversion factors.
.
Lab Specific FAQ
● What does it mean to round a real number to the nearest whole number?
Every nonnegative real number is sandwiched uniquely between two successive whole
numbers, e.g., 3.14 lies in [3,4]. Rounding entails returning the whole number that closest to the
given real number (so 3.14 rounds to 3)
● How do I round a real number that is exactly halfway between two successive whole numbers?
Round up, i.e., 42.5 cents should be rounded to 43 cents, 3.5 ounces should be rounded to 4
ounces, etc.
● How do I get a double with “scanf” function?
Use “%lf” as you get a compiler error or absurd values when you use “%f”
● How many significant places after the decimal point should we have?
Its 6 by default
● Do we have to account for invalid input such as characters or numbers outside the expected
range?
No. You do not need to handle invalid input or user error as we will grade how your program
functions with valid input as specified in the lab document.

More products