Grantham University Week 5 Visual Studios Project

Advanced Programming in C++ – W5 Assignment

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Safe Rational Fractions

In week 4 we completed Chapter 13 Programming Exercise #10 Page 974. Make sure you have a working

fractionType

class before starting this assignment. The template requirement from week 4 is not required for this assignment.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Your assignment this week is to make your fractionType class safe by using exception handling.

Use exceptions so that your program handles the exceptions division by zero and invalid input.

An example of invalid input would be entering a fraction such as 7 / 0 or 6 / a

An example of division by zero would be:  1 / 2  /  0 / 3

Use a custom Exception class called

fractionException

. The class must inherit from exception (see example in lecture and note the entire class can be implemented in the .h file as in the lecture).

Test your safe fractionType class with a main method that forces an invalid fraction and a divide by zero. The catch block in the main method must report which kind of error was encountered – i.e. invalid fraction or divide by zero.

Please pay careful attention to all assignment requirements. You are graded on your ability to implement each requirement.

Regarding week 5. We will implement Exceptions by adding exception handling to our fractions class from Week 4. Please contact me if you need help understanding the week 4 assignment.

A test situation has been ilsted in the assignment requirements which will force an exception to be thrown. Please use this test in your main program or something similar.

Assignment 5 uses 2 class:

fractionTypefractionException

and a main test program.

The following can be used to test an exception:

try {

fractionType num1(1,0);

fractionType num2(0,3);

fractionType num3;

cout << fixed;

cout << showpoint;

cout << setprecision(2);

num3 = num1 / num2;

cout << num1 << " / " << num2 << " = " << num3 << endl;

}

catch (fractionException e) {

cout << "Exception caight in main: " << e.what() << endl;

}

Submission Guidelines:

Submit modified fractionType class (.h and .cpp file if exists)

Submit fractionException class (.h file and .cpp file if exists)

Submit main test .cpp program to test the exception handling

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER