Rev A Lab 5

              

        All programs (problems 3-5) to be handed in should include both source code and resulting output on the same page. 

 

  1. Suppose x and y are int variables and ch is a char variable.  Assume the following input data.

13 28 D

14 E 98

A B 56

 

What value (if any) is assigned to x, y, and ch after each of the following statements executes?  (Use the same input for each statement.)

a.        cin>>x>>y;

cin.ignore(50,’\n’);

cin>> ch;

b.        cin>>x;

cin.ignore(50,’\n’);

cin>>y;

cin.ignore(50,’\n’);

cin.get(ch);

c.        cin>>y;

cin.ignore(50,’\n’);

cin>>x>>ch;

d.        cin.get(ch);

cin.ignore(50,’\n’);

cin>>x;

cin.ignore(50,’\n’);

cin>>y;

 

  1. Suppose that age is an int variable, ch is a char variable, and name is a string variable.  What  are the values of age and name after the following input statements execute?

cin>>age;

cin.get(ch);

getline(cin, name);

 

if the input is:

a.        35 John Doe

b.        35

John Doe

  1. Write a C++ program that

a)    prompts the user to input 3 decimal numbers (with a fraction part)

b)    Prints the three decimal numbers.

c)    Converts each decimal number to the nearest integer.

d)        Prints the three converted numbers.

e)        Computes and prints the sum and average of the three integers.

  1. Write a C++ program that uses the manipulator setfill to output a line containing 35 stars.  As a guide for checking  produce a numbered line above it.  Program should produce the following output:

12345678901234567890123456789012345

************************************************

  1. 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 and the employee name.  Format your output to have two decimal places>  A sample output follows:  The program should produce this type of output both on the display monitor and to a data file c:\lab5_data.txt.

John Doe

Gross Amount:  …………   $3575.00

Federal Income Tax: …….  $ 536.25

State Tax: …………. …….  $ 125.13

Social Security Tax: ……… $ 205.56

Medicare/Medicaid Tax: ..   $  98.33

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.