## Homework 2 – Basic Elements: input/output/constant/variable/data types/conversions/operators

[CSCI 116]

This assignment will introduce you to the basic elements of C++ program and the process of solution designing, compiling, executing, and testing a C++ program. Do all of the following work by the date due.

Two problems

Problem 1: Write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches ( to the nearest inch) and output the length expressed in yards, feet, and inches, in that order.

For example, suppose the input for centimeters is 312.02. To the nearest inch, 312.02 centimeters is equal to 123 inches. 123 inches would thus be output as

3 yard(s), 1 feet (foot), and 3 inch(es).

It should NOT be output as:

2 yard(s) 4 feet (foot) 3 (inches),

or:

10 feet(foot)  3 inch(es),

or:

10.25 feet(foot).

Hints:

Convert from the given centimeters to inches first, then from there convert to yards, feet and inches.

## 1 inch = 2.54 centimeters

312.02 centimeter is 122.8 inches, but we need 123 inches (the nearest integer inches).

## Here are some simple facts.

There are 12 inches in a foot.

You need to identify what data are fixed (so called constants), what data are changeable (so called variables).

Make sure declare them first, initialize them or/and get data from keyboard before you use those data.

There are several different methods to solve the problem.

Method 1

From 123 inches you can get 3 yards first, then 1 feet, then the remaindering 3 inches

Method 2

From 123 inches, get 10 feet and 3 inches, and then from 10 feet, you get 3 yard and 1 feet.

Method 3

To test the logic of your program, you need to run your program three times for the following numbers: 312.02, 1000 and 233. Certainly feel free to choose other numbers to test!

Problem 2: This problem will make your homework 1 problem alive.  In your last homework, all the data are literals, fixed.

Now, you write a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated after taking the following deductions:

Federal Income Tax: 15%

State Tax: 3.5%

Social Security Tax: 5.75%

Medicare/Medicaid Tax: 2.75%

Pension Plan: 5%

Health Insurance: \$75.00

Your program should prompt the user to input the gross amount, then based on the user input and the above constant deduction ratios or amounts, your program will itemize deductions and display them on the screen. Format your output to have two decimal places.  A sample output follows:

What is your Goss Amount: 3575.00

Gross Amount: …………...          \$  3575.00

Federal Tax: ………………         \$    536.25

State Tax: …………………         \$    125.13

Social Security Tax: ……..           \$    205.56

Medicare/Medicaid Tax: …          \$      98.31

Pension Plan: …………….           \$    178.75

Health Insurance ………...           \$      75.00

Net Pay …………………….       \$  2356.00

Note that the first column is left-justified and the right column is right-justified.

Run your program four times test on gross amounts 0, 3575, 23423, 4000 respectively, make screenshot for each result.

Note 1: You need to write up a short paragraph to describe your solution on paper before you typed on keyboard. Documentation part is a part of the solution and it will help you organize your thoughts.

Note 2: Your programs must execute properly using the MS Visual Studio .Net C++ IDE, on any computer of your instructor's choosing, in any public lab.

Note 3: If you can get your code work correctly, submit both source code on paper and diskette as we have discussed before. When you submit your source code on paper, you also need to submit test result. Usually you need to test your program multiple times (at least 3 times, especially on special cases whenever applicable) using different inputs to make sure that your solution works for different situations.

Note 4: You are strongly encouraged to go over sample code, quick review and all other programming exercises at the end of each chapter.

You are strongly encouraged to go over sample code, quick review and all other programming exercises at the end of each chapter.