Coppin State College

COSC 199 – Spring 2005

Programming Assignment 5

(Multi-way Selection)

Due Date: Tuesday, 04/15/05

(55 points)

Student’s Name: ______

NOTE: Staple this instruction page as a cover page to your submitted assignment. Your assignment will be graded based on style and correctness of your program.

Penalty for not submitting in due date: Each class-day late – 10%

you will receive zero; if I post the solution.

Follow the class examples to write the following programs.

Example Program 1: Write the following problem in C++ program using ISO/ANSI standard (New).

Determine the letter grade of a student in a test based on the following conditions and print it.. The conditions are

A student will get letter grade "A" if the student's average score in the test is greater than or equal to 90; letter grade "B", if the student's score is greater than or equal to 80 but less than 90; letter grade "C", if the student's score is greater than or equal to 70 but less than 80; letter grade "D", if the student's score is greater than or equal to 60 but less than 70; and letter grade "F" otherwise.

Test the program with 90, 89, 80, 79, 70, 69, 60, and 59.

The program

/*

Description: This program reads a test score of a student, calculates the letter grade

based on the score scale, and prints it.

Programmer: Sisir Ray

Program Name: MultiWayIf.cpp

Course Name: COSC 199

Start date: 11/11/04

Completion date: 11/11/04

*/

// preprocessor directives

#include<iostream>

using namespace std;

// start main

int main()

{

// Declaration statements (or Local Declarations)

int score;

char letterGrade;

// Input Statements

cout < "Please enter the student's test score (0 to 100): ";

cin > score;

cout < endl; // provides with a blank line

// Process Statements

if (score >= 90)

letterGrade = 'A';

else if (score >= 80 & score < 90)

letterGrade = 'B';

else if (score >= 70 & score < 80)

letterGrade = 'C';

else if (score >= 60 & score < 70)

letterGrade = 'D';

else

letterGrade = 'F';

// Output Statements

cout < "The student's score is " < score

< " and letter grade is " < letterGrade < endl;

// return to OS

return 0;

}

/* RESULTS or OUTPUTS

Please enter the student's test score (0 to 100): 90

The student's score is 89 and letter grade is A

Please enter the student's test score (0 to 100): 89

The student's score is 89 and letter grade is B

Please enter the student's test score (0 to 100): 80

The student's score is 89 and letter grade is B

....

....

*/

TASK 1

(2pts) Type the above sample program and complete with all the tests. Keep the name of the program same as above..

TASK 2

(2pts) Modify the above program with following process statements and test the program with all the test scores given in the sample program. Use the name of the program as Lab6a.cpp.

// Process Statements

if (score >= 90)

letterGrade = 'A';

else if (score >= 80)

letterGrade = 'B';

else if (score >= 70)

letterGrade = 'C';

else if (score >= 60)

letterGrade = 'D';

else

letterGrade = 'F';

TASK 3

(2pts) Modify the above program with following process statements and test the program with all the test scores given in the sample program. Use the name of the program as Lab6b.cpp.

// Process Statements

if (score <= 100)

letterGrade = 'A';

else if (score < 90)

letterGrade = 'B';

else if (score < 80)

letterGrade = 'C';

else if (score < 70)

letterGrade = 'D';

else if (score < 60)

letterGrade = 'F';

TASK 4

(2pts) Modify the above program with following process statements and test the program with all the test scores given in the sample program. Use the name of the program as Lab5c.cpp.

// Process Statements

if (score < 60)

letterGrade = 'F';

else if (score < 70)

letterGrade = 'D';

else if (score < 80)

letterGrade = 'C';

else if (score < 90)

letterGrade = 'B';

else

letterGrade = 'A';

TASK 5

(2pts) Modify the above program with following process statements and test the program with all the test scores given in the sample program. Use the name of the program as Lab6d.cpp.

// Process Statements

if (score >= 90)

letterGrade = 'A';

if (score >= 80 & score < 90)

letterGrade = 'B';

if (score >= 70 & score < 80)

letterGrade = 'C';

if (score >= 60 & score < 70)

letterGrade = 'D';

if (score <= 60)

letterGrade = 'F';

TASK 6

(10pts) Observe carefully the logical algorithm of each task from TASK 1 to TASK 5 and their related test results. Compare the output of each Task with others and give proper reasoning why the algorithm is correct or incorrect. As a good programmer, which logical algorithm(s) you should write to solve this problem or similar type of problems. Justify your answer.

TASK 7

(10pts) Consider the following problem. i) (1pt) Analyze the problem solution, ii) (1pt) write the step-by-step algorithm, and iii) (1pt) Draw the flowchart of the solution. (iv) (6pts) Then write the C++ program using ISO/ANSI standard (New).

Determine the tax rate and calculate the total tax for a person’s annual income. Followings are the tax rates:

Annual Income tax rate

greater than or equal to $100,000.00 45%

between $60,000.00 - $99,999.00 35%

between $30,000.00 - $59,999.00 20%

between $10,000.00 - $29,999.00 10%

lees than $10,000.00 no tax

Print out the person’s annual income, tax rate, total tax, and net income (income after the tax deduction) in four separate lines. Allow the code to separate out input and output on your display by at least one blank line. Use the name of the program as Lab6e.cpp. Test your program with Annual Income values: $100,000, $99,999, $60,000, $59,999, $30,000, $29,999, $10,000, and $9,999.

7(v) If your annual income is $70,500.00, what would be your tax rate, total tax, and net income? (2pts) Solve manually first and show your work. (2pts) solve using your program and see whether your program is computing correctly.

TASK 8 (10pts)

Complete the Programming Problem 1 from your textbook (pp.245-246). Use the name of the program as Lab6f.cpp.

TASK 9 (10pts)

Complete the Programming Problem 2 from your textbook (p.246). Use the name of the program as Lab6f.cpp.

NOTE: For TASKS 8 & 9, Just write the programs using the main() function only. Do not need to decompose into sub functions.

REQUIREMENTS:

1.  Your source code for each task should clearly indicate the preprocessor directives, local declarations, inputs, processes, and outputs, if there be any.

2.  (1pt) After you compile and run successfully your programs from H: drive (or from C: drive at home, save all the .cpp files with their outputs in a folder, COSC199Lab6 in a floppy disk. Submit the floppy disk and hardcopies of all the programs.

NOTE: General Format of your Submitted program listing and output:

/*

Standard information

*/

The Source Code with proper styles and comments (your .cpp program)

/* Results:

Paste your output here

*/