Question

In: Computer Science

Question 2: Create a class Fract fraction with two private integer data members: num (Numerator) and...

Question 2: Create a class Fract fraction with two private integer data members: num (Numerator) and den (denominator). write code for:

Part A) class declaration header file

Part b) constructor that validates input (prevent 0 on the denominator in a fraction simplified fraction that is not reduced, avoids negative denominators) with default arguments 0 and 1.

Part c)Two fractions with prototype Fract add (fract) and Fract multiply (fract) completing the usual addition and multiplication

Part d) Just all fractions by writing a short test driver that creates two fractions with the values 3/6 and ⅔ and prints there sum and product

C++ language

Solutions

Expert Solution


Related Solutions

C++ file=.class definitions.h Define a Fraction class with num and den as its private data. Include...
C++ file=.class definitions.h Define a Fraction class with num and den as its private data. Include a constructor to initialize the fraction to 0/1, a copy constructor, a destructor, and overloading functions to overload the assignment operator =, the comparison operators <, >, ==, !=, arithmetic operators +, +=, -, -=, *, *=, /, /=, as well as friend functions (non-member) to overload << and >> to output and input a fraction (see book example). Also, include a private member...
C++ Create a class for working with fractions. Only 2 private data members are needed: the...
C++ Create a class for working with fractions. Only 2 private data members are needed: the int numerator of the fraction, and the positive int denominator of the fraction. For example, the fraction 3/7 will have the two private data member values of 3 and 7. The following methods should be in your class: a. A default constructor that should use default arguments in case no initializers are included in the main. The fraction needs to be stored in reduced...
First, create a class object named SequenceMap that has as private data members the following two:...
First, create a class object named SequenceMap that has as private data members the following two: string recognition_sequence_ ; vector enzyme_acronyms_; Other than the big-five (note that you can use the defaults for all of them), you have to add the following: a) A constructor SequenceMap(const string &a_rec_seq, const string &an_enz_acro),that constructs a SequenceMap from two strings (note that now the vector enzyme_acronyms_ will contain just one element, the an_enz_acro). b) bool operator<(const SequenceMap &rhs) const, that operates based on...
Create a class for working with complex numbers. Only 2 private float data members are needed,...
Create a class for working with complex numbers. Only 2 private float data members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class:a. A default constructor that uses default arguments in case no initializers are included in the main.b. Add two complex numbers and store the sum.c. Subtract two complex numbers and store the difference.d. Multiply two complex numbers and store the product.e. Print...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member variable are allowed Create accessor and mutator functions to set/return numerator denominator Create a function to set a fraction Create a function to return a fraction as a string ( common name ToString(), toString())  in the following format: 2 3/4 use to_string() function from string class to convert a number to a string; example return to_string(35)+ to_string (75) ; returns 3575 as a string Create...
Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int...
Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int type, private and the following methods: one default constructor which will create a fraction of 1/1. one constructor that takes two parameters which will set the values of numerator and denominator to the specified parameters. int getNum() : retrieves the value of numerator int getDenom(): retrieves the value of the denominator Fraction add(Fraction frac): adds with another Fraction number and returns the result in...
in simple C++: 2. Create a structure Fraction which contains a numerator and a denominator then...
in simple C++: 2. Create a structure Fraction which contains a numerator and a denominator then do the following: a. Write a function void printFraction(Fraction f) which prints out a fraction in the following format; e.g. if the numerator is 2 and the denominator is 5, it will print out 2/5 b. Write a function Fraction mult(Fraction f1, Fraction f2) which returns a new fraction which is the product of f1 and f2. c. Write a function Fraction add(Fraction f1,...
This should be written in C++. Create a class with the name "Student". private data members...
This should be written in C++. Create a class with the name "Student". private data members of the Student class should include: int - rollno (roll number or id number of student) string - name (name of student) int - alg, datastruct, architect, proglang (hold scores out of 100 for these 4 classes) float - per (average score of 4 classes above) char - grade (letter grade based on per.. example 90 is an A) public member functions of the...
Part 1 Create a class named Room which has two private data members which are doubles...
Part 1 Create a class named Room which has two private data members which are doubles named length and width. The class has five functions: a constructor which sets the length and width, a default constructor which sets the length to 12 and the width to 14, an output function, a function to calculate the area of the room and a function to calculate the parameter. Also include a friend function which adds two objects of the room class. Part...
How do I fix my code? public class Fraction {    private int numerator, denominator, numberOfFraction;    public...
How do I fix my code? public class Fraction {    private int numerator, denominator, numberOfFraction;    public Fraction () {    numerator = 0;    denominator = 1;    numberOfFraction++; }    public Fraction (int n, int d) {    numerator = n;    denominator = d;    numberOfFraction++; } private int gcd (int num1, int num2) {    if (num1 == 0)    return num2;    return gcd (num2 % num1, num1); }    public Fraction add (Fraction third) {    int n = numerator * third.denominator + third.numerator * denominator;    int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT