Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 9 Due Date: See Blackboard Source File: /2336/09/1ab09. (CICPPlcpplc++cclcxxlcp) Input: Output: Value: Under control of main function Under control of main function The purpose
Lab 9 Due Date: See Blackboard Source File: /2336/09/1ab09. (CICPPlcpplc++cclcxxlcp) Input: Output: Value: Under control of main function Under control of main function The purpose of this assignment is to become more familiar with the process of providing overloaded operators for a class. The Rational class from Labs 02, 03, 05, and 07 will be modified to provide: overloaded operators (both prefix and postfix) for incrementing a Rational number by one and overloaded operators (both prefix and postfix) for decrementing a Rational number by one. A header file is shown in Figure1, a sample main function for testing your implementation is shown in Figure 2, and a sample execution sequence is shown in Figure 3. To use the Makefile as distributed in class, add a target of lab09 to targets2srcfileavithlibrary #ifadef LAB09H - define LAB09 H 4 #include o using nanespace std; 8 class Rational IIoverloaded input operator initializes Rational rat from input strean in friend istreamk operator>>(istreankin, Rationalk rat); 2I/ overloaded output operator prints Rational rat to output strean out iafriend ostreamk operator (const Rationalk rhs) const bool operator>-(const Rational& rhs) const; *this- rhs // *thisrha // *this-rha // *thisrha // *this #include 10 tream> using namespace std; 6 int main) Rational rat, temp hile (cin > temp) rat-tenp rattenp cout cd 2336 nevuser@csunix /2336> /getlab.ksh 09 Checking to see if a folder exists for Lab 09 No 4Creating a folder for Lab 09 Checking to see if Lab 09 has sample input and output files Copying input and output files for Lab 09 Yes from folder usr/local/2336/data/09 to folder/09 Checking to see if /usr/local/2336/src/lab09main.C exists Copying file /usr/local/2336/src/lab09main.C to folder ./09 Checking to see if /usr/local/2336/include/lab09.h exists Copying file /usr/local/2336/include/lab09.h to folder /09 Yes Yes 12Copying file /usr/local/2336/src/Makefile to folder/09 Adding a target of lab09 to targets2srcfilesvithlibrary Touching file ./09/1ab09.cpp 15 Edit file /09/lab09.cpp in Notepad+ s nevuser@csunix /2336> cd 09 17 nevuser@csunix /2336/09> 1s s 01.dat s nevuser@csunix /2336/09> make lab09 01.out Makefile lab09.cpp lab09.h gg-Wall-std-c 11 -std-c++11 lab09main.C I/usr/local/2336/include -I - lab09.cpp-1/usr/local/2336/include -l 21 g++ -g -Vall g-o lab09 lab09main.o lab09.o L/usr/local/2336/1ib 2-V1,-whole-archive -1lab09-W,-no-whole-archive1-1bits 2 evuser@csunix /2336/09> cat 01.dat -3 4 3 4 2 3-4-3-4 225 45 8 99 129 6579 1935 249 1331 1651 2301 1079 a 3 1260 6 198 32 43 1935 207 6579 5 7-25-35 383 1651 127-1079 s1079 1651-1651 1079 nevuser@csunix /2336/09> cat 01.dat I./lab09 rat --3/4--rat-7/4 rat--3/4 rat-- -3/4 rat-7/4 rat-3/4rat 7/4 rat 3/4 rat3/4 rat -7/4 rat -3/4--rat-1/4 4 rat 3/4 rt3/4 rat --1/4 5 rat-3/-4rat 1/4 4 rat 3/-4 rat* - 3/-4 rat 1/4 7 rat-3/-4--rat-7/4 srat 3/-4 rat-- 3/-4 rat-7/4 rat--3/-4 rat-7/4 rat-3/-4 rat-3/-4 rat 7/4 rat--3/-4--rat--1/ rat--3/-4 rat---3/-4 rat-1/4 rat -25/45"rat-14/9 rat- 25/45 rat-25/45 rat 14/9 Figure 3. Commands to Compile, Link, &Run Lab 09 (Part 1 of 2) CS 2336Data Structures and Algorithms Page 3 rat-25/45 --rat-4/9 6 rat-25/45 --rat-4/9 57 rat . 25/45 rat 25/45 rat "-4/9 92 rat 6/198 rat-32/33 sa rat 6/198 rat-6/198 rat-32/33 s rat -43/1935rat 46/45 9 rat 43/1935 rat43/1935 rat 46/45 96 rat-43/1935 -rat-44/45 97 rat 43/1935 rat-43/1935 rat-44/45 rat-8/99 4rat107/99 to rat - 8/99 rat++-8/99 rat " 107/99 rat - 8/99-rat " -91/99 rat-8/99 rat8/99 rat -91/99 rat-207/6579rat 754/731 99 rat-207/6579 rat++ -207/6579 rat-754/731 oo rat 207/6579 rat-708/731 m rat-207/6579 rat 207/6579 rat--708/731 rat-1/14rat 2/1 Ga rat -1/1 rat1/1 rat 2/1 64 rat -1/1--rat 0/1 65 rat -1/1 rat1/1 rat -0/1 rat -2/1 ++rat-3/1 67 rat -2/1 rat2/1 rat 3/1 6s rat-2/1--rat 1/1 rat 5/7rat 12/7 ua rat-5/7 rat++-5/7 rat-12/7 o rat 5/7--rat -2/7 rat -2/1 rat 2/1 rat " 1/1 o rat-25/-35rat 12/7 o7 rat-25/-35 rat-25/-35 rat 12/7 o rat-25/-35 --rat -2/7 o rat -129/6579 rat 52/51 rat -129/6579 rat4129/6579 rat 52/51 2 rat -129/6579 rat 50/51 3 rat -129/6579 rat129/6579 rat-50/51 4 rat -1935/249 rat 728/83 rat-25/-35 rat25/-35 rat -2/7 0 rat-83/1651rat 1568/1651 rat-83/1651 rat.-83/1651 rat 1568/1651 rat -1935/249 rat1935/249 rat728/83 rat -1935/249 rat 562/83 112 rat-83/1651 rat-1734/1651 rat-83/1651 rat--83/1651 rat--1734/1651 7 rat -1935/249 rat1935/249 rat -562/83 rat -1331/1651 rat 2982/165:1 rat -1331/1651 rat+1331/1651 rat 2982/1651 rat-1331/1651rat -320/1651 rat-1331/1651 rat-1331/1651 rat-320/1651 rat 127/-1079 rat 952/1079 I5 rat 127/-1079 rat.127/-1079 rat 952/1079 6 rat 127/-1079 --rat-1206/1079 7 rat 127/-1079 rat127/-1079 rat -1206/1079 rat 1079/1651 rat 210/127 ua rat-1079/1651 rat++-1079/1651 rat-210/127 120 rat 1079/1651-rat-44/127 82 rat-2301/1079 rat 260/83 rat-2301/1079 rat++2301/1079 rat 260/83 s rat -2301/1079 -rat 94/83 5 rat-2301/1079 rat-2301/1079 rat 94/83 rat 1079/1651 rat-1079/1651 rat -44/127 1 rat-1651/1079rat-44/83 a rat-1651/1079 rat*--1651/1079 rat--44/83 rat-3/1260 rat 421/420 87 rat - 3/|260 rat++ " 3/1260 rat -421/420 ss rat-3/1260 -rat-419/420 rat-1651/1079 --rat-210/83 5 rat-1651/1079 rat-1651/1079 rat -210/83 126 nevuserecsunix /2336/09> cat 01.dat./lab09> my.out 2nevuserecsunix /2336/09> diff 01.out ny.out rat - 3/1260 rat-.-3/1260 rat rat-6/198 rat-34/33 -419/420 91 rat -6/198 rat++-6/198 rat " 34/33 Figure 3. Commands to Compile, Link, &Run Lab 09 (Part 2 of 2) #include Rational& Rational: : operator++() // preincrement Rational copy *this; //insert the code to increment *this return *this Rational Rational: :operator++(int) // postincrement Rational copy *this; // call the preincrement operator to increment *this //thist+; //++this; //*++this; ++*this;//ok //operator++); //ok //this->operator++);//ok return copy; Rational& Rational: : operator--() // predecrement //insert the code to increment *this return *this Rational Rational: :operator--(int) // postdecrement Rational --*this copy *this; // call the preincrement operator to increment *this return copy
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started