assignment attached, using c++ language, is supposed to take around 1 hour 15 min to finish.
Q1 class Fraction 20 Points Define and implement a class called Fraction. This class is used to represent the ratio of two integers as a numerator and denominator. Your class implementation should satisfy the following requirements: · Declare the private member variables of Fraction as appropriate. · Implement a parameterized constructor that takes default values. · Implement member functions that do the following. a. Set the numerator and denominator. b. Get the value of the fraction as a double (numerator divided by the denominator). Differentiate between accessor (getter) and mutator (setter) functions by appropriately using the keyword const · Implement the overloaded the operator+ Q1.1 define the class Fraction 6 Points Write the definition of the class. Do not implement any of the member functions here. Q1.2 Implement the constructor 5 Points Implement a parameterized constructor with default parameter values to initialize a new Fraction. The first parameter should be the numerator and the second parameter should be the denominator. If no parameters are defined when the object is created the constructor should set the value of the numerator and denominator to represent the fraction 0/1. Q1.3 2 Points Implement a member function to set the numerator and denominator. Differentiate between accessor (getter) and mutator (setter) functions by appropriately using the keyword const Q1.4 2 Points Implement a member function to get the value of the fraction as a double (numerator divided by the denominator). Differentiate between accessor (getter) and mutator (setter) functions by appropriately using the keyword const Q1.5 Overloaded operator+ 5 Points Overload the operator + (as a member or non-member function) that returns the sum of two Fractions. For example, Fraction f1(1, 15), f2(3, 5); Fraction f = f1 + f2; // f should represent the fraction 10/15 or 2/3 Note that for the overloaded operator you don’t need to reduce the final answer to its simplest form. So, in this case 10/15 and 2/3 are both acceptable values for f. Q2 5 Points Consider the following function that uses the Fraction class described in the previous question. void Frac(){ Fraction a{1,5}, b{2, 3}; Fraction& c = b; Fraction e{c}; c = a; Fraction* d = new Fraction{b}; } In each line of the provided code, select which of the following functions of the class Fraction gets called: · parameterized constructor · copy constructor · copy-assignment operator · None of the above Provide your answers in the sub-questions below: Q2.1 1 Point Fraction a{1,5}, b{2, 3}; · parameterized constructor · copy constructor · copy-assignment operator · None of the above Q2.2 1 Point Fraction& c = b; · parameterized constructor · copy constructor · copy-assignment operator · None of the above Q2.3 1 Point Fraction e{c}; · parameterized constructor · copy constructor · copy-assignment operator · None of the above Q2.4 1 Point c = a; · parameterized constructor · copy constructor · copy-assignment operator · None of the above Q2.5 1 Point Fraction* d = new Fraction{b}; · parameterized constructor · copy constructor · copy-assignment operator · None of the above Q3 Wardrobe Linked list 15 Points Consider the definition of the class Wardrobe used in the construction of a doubly linked-list containing elements of type ClothingItem. Note that every node in the doubly linked-list has a pointer to its previous and a pointer to its next node. class ClothingItem{ public: ClothingItem(bool t=true, int s=1){ type = t; size = s; } bool type; // true if item is a shirt, // false otherwise int size; // Any number between // 1 and 30 }; class Wardrobe { public: Wardrobe(){head = tail = nullptr;} void append(const ClothingItem& p); bool findMatching(const ClothingItem& p); // Add other functions as needed friend bool operator==(const Wardrobe& a, const Wardrobe& b); private: class Node{ public: ClothingItem item; // data element Node* next; // pointer to the // next node Node* prev; // pointer to the // previous node Node(const ClothingItem& p){ item = p; next = nullptr; prev = nullptr; } ~Node (){ delete next; } }; Node* head; // pointer to the first node Node* tail; // pointer to the last node bool findMatchingHelper( const ClothingItem& p, Node* h); }; bool operator==(const Wardrobe& a, const Wardrobe& b){ Wardrobe::Node* h1 = a.head; Wardrobe::Node* h2 = b.head; while(h1 && h2){ if(h1->item.type != h2->item.type || h1->item.size != h2->item.size){ return false; } h1 = h1->next; h2 = h2->next; } return (h2==0 && h1 == 0); } For all the questions that follow, assume you are given the following: · a correct implementation of the append function that correctly adds a new Node to the end of the linked list (Wardrobe) · a correct implementation of the operator == for comparing Wardrobe objects as provided above. This operator returns true if two Wardrobe objects have exactly the same sequence of clothing items. Two clothing items are the same if they are of the same type and size. Q3.1 recursive helper 10 Points The function findMatching returns true if there is a ClothingItem in the Wardrobe that is of the same size but different type as that of input parameter p. This function calls a helper function that must recursively solve the problem. The function should return false if no matching clothing item exists in the Wardrobe or if the Wardrobe is empty. bool findMatching(const ClothingItem& p){ return findMatchingHelper(p, head); } Implement the recursivehelper function findMatchingHelper(). Q3.2 5 Points Assume that you are provided with the following implementations: · a correct implementation of the operator == for comparing Wardrobe objects (provided above) · default implementations of the destructor, copy constructor and assignment operator as provided by C++ for class Wardrobe. · The function foo() defined below: void foo(){ Wardrobe w; w.append(ClothingItem(true, 1)); w.append(ClothingItem(false, 2)); w.append(ClothingItem(true, 1)); bool result = w==w; cout<>
<>
head = source.head; this->tail = source.tail; } What is the output of calling bar()? Select among the following options. Select all that apply. · Compile time error · Memory leak · Segfault · The program correctly copies the nodes of w2 into w1 (deep copy) · The program outputs 0 · The program outputs 1 Briefly justify your answer. Q4.2 5 Points Suppose that the copy-assignment operator is implemented as follows: void Wardrobe::operator=(Wardrobe& source){ Wardrobe w(source); // swap head with w.head // and tail with w.tail Node* tmp = head; head = w.head; w.head = tmp; tmp = tail; tail = w.tail; w.tail = tmp; } What is the output of calling bar()? Select among the following options. Select all that apply. · Compile time error · Memory leak · Segfault · The program correctly copies the nodes of w2 into w1 (deep copy) · The program outputs 0 · The program outputs 1 Briefly justify your answer.