Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Basic Coding PLEASE READ CAREFULLY Explanations to the approach would be greatly appreciated Problem 2: Write a program that converts a) miles to kilometers,

C++ Basic Coding PLEASE READ CAREFULLY

Explanations to the approach would be greatly appreciated

image text in transcribedimage text in transcribed

Problem 2: Write a program that converts a) miles to kilometers, b) kilometers to miles, c) 12-hour time to military time to and d) military time to 12-hour time. For parts a and b, you should use conversion factors 1 mile = 1.609 km and 1 km = .621 miles. (Here, you should make sure to correctly use const and to avoid magic numbers.) For parts c and d, you have permission (for this problem only) to use magic numbers for things such the number of hours per day. By 12-hour time, I mean times with an AM/PM. For this problem we can assume that all 12-hour times are formatted as in the following examples "3 14 AM", "12 15 PM, 12 59 AM. Note that there is a space (not a colon) in between the hours and minutes and the AM/PM. Also note that we are capitalizing AM and PM. For part c, you can assume that the user enters in this format. Military time is a 24-hour time with no colon or space in between the hours and minutes, e.g. 1514 for 3:14 PM. (It is okay if your solution to part c sometimes outputs a 3-digit number such as 306 for 3 06 AM.) For part d) you will output the 12-hour time in the format e.g. 12 15 (PM = false), where PM = false denotes an AM time and PM = true denotes a PM time. (We are using this format so you don't have to use "if" statements.) Also note that 12 00 AM in military time is 0000, note 2400. Below is an example output. If the user enters the same input as I did, the output of your code should match exactly. In particular, you should make sure to print the quotation marks for the example input as shown below. (For the line beginning with "Please", it is okay if the line break is in a different spot.) How many miles? 8 8 miles is 12.872 kilometers. How many kilometers? 8 8 kilometers is 4.968 miles. Please enter a time in 12-hour format. Do not use a colon and separate by spaces. Example input: "3 14 PM''. Please make sure to capitalize AM/PM. 2 59 PM The military time is: 1459. Please enter a time in military format. Example input: "1514'', 0823 The twelve-hour time is: 8 23 (PM = false). Warning: It is strongly recommended that you don't copy and paste from a pdf into your cpp file. This is particularly dangerous with quotation marks. (Sometimes the copy/paste changes a double quote into two single quotes and this can confuse the compiler.) For this problem, you should turn in one file. It must be named conversions.cpp. Rules for Problem 2: 1. You may assume that the user enters valid input, but your code should work for any valid input. For the distance problems, this means you code should work, for example, if the user tries to convert 3.1 miles into kilometers. 2. When outputting the military time, the program might omit the front zero, e.g. it might write 823 rather than 0823. That is okay for this problem now since we may not have covered how correct this yet. If you want to figure out how to get the computer to display the lead zero, that is okay too. (All missing zeros are considered okay for this problem, but try to get as many of them right as you can.) 3. You are *not* allowed to use "if statements for this problem, because we have not covered them yet. You can avoid using if statements by clever use of Boolean variables. (Hint bools can be converted to ints). 4. You will need to use string variables and therefore *must* include #in- clude at the top of your file. (This is an example of something that might cause your code to work on one machine but not another.) 5. You are not allowed to store numerical data as strings in this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

9. System creates a large, diverse talent pool.

Answered: 1 week ago