Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

> Lab 2 Task Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
> Lab 2 Task Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). The class, along with the required operator overloads, should be written in the files mixed.h and mixed.cpp Details and Requirements 1. Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 -- "three and one-half"). The Mixed class must allow for both positive and negative mixed number values. A zero in the denominator of the fraction part constitutes an illegal number and should not be allowed. You should create appropriate member data in your class. All member data must be bristo 2. There should be two constructors. One constructor should take in three parameters, representing the integer part, the numerator, and the denominator (in that order), used to initialize the object. If the mixed number is to be a negative number, the negative should be passed on the first non-zero parameter, but on no others. If the data passed in is invalid (negatives not fitting the rule, or o denominator), then simply set the object to represent the value 0. Examples of declarations of objects: Mixed m1(3, 4, 5); Mixed m2(-4, 1, 2); Mixed m3 (0, -3, 5); Mixed m4(-1, -2, 4); // sets o // sets o // sets o // bad pa The other constructor should expect a single int parameter with a default value of 0 (so that it also acts as a default constructor). This constructor allows an integer to be passed in and represented as a Mixed object. This means that there is no fractional part. Example declarations: Mixed m5(4); Mixed m6; // sets object to // sets object to Note that this last constructor will act W TONTON allowing as a "conversion constructor", allowing automatic type conversions from type int to type Mixed. 3. The Mixed class should have public member function Print(). This function should output to the console the mixed number in the same format as above, with the following exceptions: If the object represents a 0, then just display a 0. Otherwise: If the integer part is 0, do not display it. If the fraction part equals 0, do not display it. For negative numbers, the minus sign is always displayed to the left. Examples: 0,2,-5, 3/4, -6/7, -2 4/5 ,72/3 Driver Program The sample driver program that is provided can be found below. Note, this is not a comprehensive set of tests. It is just a some code to get you started, illustrating some sample calls. #include #include "mixed.h" using namesapce std; int main({ Mixed mi(3, 4, 5); // sets of m1.print(); // prints 3 4/5 Mixed m2-4. 1. 2A // sets of comprehensive set of tests. It is just a some code to get you started, illustrating some sample calls. #include #include "mixed.h" using namesapce std; int main() { Mixed m1(3, 4, 5); // sets of m1. Print(); // prints 3 4/5 Mixed m2(-4, 1, 2); // sets ot m2. Print(); // prints -4 1/2 Mixed m3 (0, -3, 5); // sets of m3. Print(); // prints -3/5 Mixed m4(-1, -2, 4); // bad par m4. Print(); // prints Mixed m4a(1, -2, -4); // bad par m4a. Print(); // prints o Mixed m5 (4); m5. Print(); // prints: 4 Mixed m6; m6.print(); // prints o Submission Coding Style In any programming project, matching the existing coding style is important. Having different coding styles intermixed leads to confusion and bugs. Students are required to follow the particular existing coding style that maintains the indentation style in .cpp and .h files using spaces, not tabs

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

Step: 3

blur-text-image

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

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

The company openly shares plans and information with employees.

Answered: 1 week ago