Question

Objectives The purpose of this lab is to help you become familiar with the development environment,...

Objectives The purpose of this lab is to help you become familiar with the development environment, to reinforce the concepts covered in chapter 2, to reinforce the implementation of object oriented concepts in C++, and to reinforce the implementation of operator overloading in C++. Requirements Extend the implementation of the statistician class created in Lab 2 to overload operators +, *, and ==. The extended class definition is given in stats2.h. You need implement the three operator overloading functions in stats2.cpp file. Use statexam2.cpp to test the correctness of your extended statistician class

//a class to keep track of statistics on a sequence of real numbers
class statistician
{
public:
// CONSTRUCTOR
// Postcondition: The object has been initialized, and is ready to accept
// a sequence of numbers. Various statistics will be calculated about the
// sequence.
statistician( );
  
// MODIFICATION MEMBER FUNCTIONS
  
// Postcondition: The number r has been given to the statistician as the next number in
// its sequence of numbers.
void next(double r);
  
// Postcondition: The statistician has been cleared, as if no numbers had
// yet been given to it.
void reset( );
  
// CONSTANT MEMBER FUNCTIONS
  
// Postcondition: The return value is the length of the sequence that has
// been given to the statistician (i.e., the number of times that the
// next(r) function has been activated).
int length( ) const;
  
// Postcondition: The return value is the sum of all the numbers in the
// statistician's sequence.
double sum( ) const;
  
// Precondition: length( ) > 0
// Postcondition: The return value is the arithmetic mean (i.e., the
// average of all the numbers in the statistician's sequence).
double mean( ) const;
  
// Precondition: length( ) > 0
// Postcondition: The return value is the tinyest number in the
// statistician's sequence.
double minimum( ) const;
  
// Precondition: length( ) > 0
// Postcondition: The return value is the largest number in the
// statistician's sequence.
double maximum( ) const;
  
// FRIEND FUNCTIONS
  
// Postcondition: The statistician that is returned contains all the
// numbers of the sequences of s1 and s2 (the numbers of s1 followed
// by all of the numbers of s2).
friend statistician operator + (const statistician& s1, const statistician& s2);
  
// Postcondition: The statistician that is returned contains the same
// numbers that s does, but each number has been multiplied by the
// scale number.
friend statistician operator * (double scale, const statistician& s);

private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tinyest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};
  
// NON-MEMBER functions for the statistician class
  
// Postcondition: The return value is true if s1 and s2 have the zero
// length. Also, if the length is greater than zero, then s1 and s2 must
// have the same length, the same mean, the same minimum,
// the same maximum, and the same sum.
bool operator ==(const statistician& s1, const statistician& s2);
  
----------------------------------------------------------------

// FILE: statexam.cpp
// Written by Michael Main ([email protected])
// This program calls three test functions to test the statisitician class.
// Maximum number of points from this program is 90.

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string.h> // Provides memcpy function
#include "stats2.h"

using namespace std;

bool close(double a, double b)
{
const double EPSILON = 1e-5;
return (fabs(a-b) < EPSILON);
}

int test1( )
{
// Test program for basic statistician functions.
// Returns 62 if everything goes okay; otherwise returns 0.

statistician s, t;
int i;
double r = 0;

if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

for (i = 1; i <= 10000; i++)
{
   s.next(i);
   r += i;
};

if (t.length( ) || t.sum( )) return 0;
if (s.length( ) != 10000) return 0;
if (!close(s.sum( ), r)) return 0;
if (!close(s.mean( ), r/10000)) return 0;
  
// Reset and then retest everything
s.reset( );
t.reset( );
r = 0;
  
if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

for (i = 1; i <= 10000; i++)
{
   s.next(i);
   r += i;
};

if (t.length( ) || t.sum( )) return 0;
if (s.length( ) != 10000) return 0;
if (!close(s.sum( ), r)) return 0;
if (!close(s.mean( ), r/10000)) return 0;

return 62;
}

int test2( )
{
// Test program for minimum/maximum statistician functions.
// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u;
double r = 1000;
char n[15] = "10000000000000";

if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

memcpy(&r, n, sizeof(double));
r = 1/r;
s.next(r);
if ((s.minimum( ) != r) || (s.maximum( ) != r)) return 0;
r *= -1;
t.next(r);
if ((t.minimum( ) != r) || (t.maximum( ) != r)) return 0;

u.next(100); u.next(-1); u.next(101); u.next(3);
if ((u.minimum( ) != -1) || (u.maximum( ) != 101)) return 0;

return 7;
}

int test3( )
{
// Test program for + operator of the statistician
// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u, v;

if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

t.next(5);
u.next(0); u.next(10); u.next(10); u.next(20);

v = s + s;
if (v.length( ) || v.sum( )) return 0;
v = s + u;
if (!(u == v)) return 0;
v = t + s;
if (!(t == v)) return 0;
v = t + u;
if (v.length( ) != 5) return 0;
if (!close(v.sum( ), 45)) return 0;
if (v.minimum( ) != 0) return 0;
if (v.maximum( ) != 20) return 0;
if (!close(v.mean( ), 45.0/5)) return 0;
v = v + t;
if (v.length( ) != 6) return 0;
if (!close(v.sum( ), 50)) return 0;
if (v.minimum( ) != 0) return 0;
if (v.maximum( ) != 20) return 0;
if (!close(v.mean( ), 50.0/6)) return 0;
  
return 7;
}

int test4( )
{
// Test program for * operator of the statistician
// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u;

if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

u.next(0); u.next(10); u.next(10); u.next(20);

s = 2*u;
if (s.length( ) != 4) return 0;
if (!close(s.sum( ), 80)) return 0;
if (s.minimum( ) != 0) return 0;
if (s.maximum( ) != 40) return 0;
if (!close(s.mean( ), 80.0/4)) return 0;

s = -2*u;
if (s.length( ) != 4) return 0;
if (!close(s.sum( ), -80)) return 0;
if (s.minimum( ) != -40) return 0;
if (s.maximum( ) != 0) return 0;
if (!close(s.mean( ), -80.0/4)) return 0;

s = 0*u;
if (s.length( ) != 4) return 0;
if (!close(s.sum( ), 0)) return 0;
if (s.minimum( ) != 0) return 0;
if (s.maximum( ) != 0) return 0;
if (!close(s.mean( ), 0)) return 0;

s = 10 * t;
if (s.length( ) != 0) return 0;
if (s.sum( ) != 0) return 0;

return 7;
}

int test5( )
{
// Test program for == operator of the statistician.
// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u, v, w, x;

if (s.length( ) || t.length( )) return 0;
if (s.sum( ) || t.sum( )) return 0;

t.next(10);
u.next(0); u.next(10); u.next(10); u.next(20);
v.next(5); v.next(0); v.next(20); v.next(15);
w.next(0);
x.next(0); x.next(0);
  
if (!(s == s)) return 0;
if (s == t) return 0;
if (t == s) return 0;
if (u == t) return 0;
if (!(u == v)) return 0;
if (w == x) return 0;

return 7;
}

int main( )
{
int value = 0;
int result;
  
cerr << "Running statistician tests:" << endl;

cerr << "TEST 1:" << endl;
cerr << "Testing next, reset, length, sum, and mean (62 points).\n";
result = test1( );
value += result;
if (result > 0) cerr << "Test 1 passed." << endl << endl;
else cerr << "Test 1 failed." << endl << endl;

cerr << "\nTEST 2:" << endl;
cerr << "Testing minimum and maximum member functions (7 points).\n";
result = test2( );
value += result;
if (result > 0) cerr << "Test 2 passed." << endl << endl;
else cerr << "Test 2 failed." << endl << endl;
  
cerr << "\nTEST 3:" << endl;
cerr << "Testing the + operator (7 points).\n";
result = test3( );
value += result;
if (result > 0) cerr << "Test 3 passed." << endl << endl;
else cerr << "Test 3 failed." << endl << endl;

cerr << "\nTEST 4:" << endl;
cerr << "Testing the * operator (7 points).\n";
result = test4( );
value += result;
if (result > 0) cerr << "Test 4 passed." << endl << endl;
else cerr << "Test 4 failed." << endl << endl;

cerr << "\nTEST 5:" << endl;
cerr << "Testing the == operator (7 points).\n";
result = test5( );
value += result;
if (result > 0) cerr << "Test 5 passed." << endl << endl;
else cerr << "Test 5 failed." << endl << endl;

cerr << "If you submit the statistician to Dora now, this part of the\n";
cerr << "grade will be " << value << " points out of 90.\n";


cerr << "If you submit the statistician to Dora now, this part of the\n";
cerr << "grade will be " << value << " points out of 90.\n";
  
return EXIT_SUCCESS;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// stats2.h

//a class to keep track of statistics on a sequence of real numbers

class statistician

{

public:

// CONSTRUCTOR

// Postcondition: The object has been initialized, and is ready to accept

// a sequence of numbers. Various statistics will be calculated about the

// sequence.

statistician( );

// MODIFICATION MEMBER FUNCTIONS

// Postcondition: The number r has been given to the statistician as the next number in

// its sequence of numbers.

void next(double r);

// Postcondition: The statistician has been cleared, as if no numbers had

// yet been given to it.

void reset( );

// CONSTANT MEMBER FUNCTIONS

// Postcondition: The return value is the length of the sequence that has

// been given to the statistician (i.e., the number of times that the

// next(r) function has been activated).

int length( ) const;

// Postcondition: The return value is the sum of all the numbers in the

// statistician's sequence.

double sum( ) const;

// Precondition: length( ) > 0

// Postcondition: The return value is the arithmetic mean (i.e., the

// average of all the numbers in the statistician's sequence).

double mean( ) const;

// Precondition: length( ) > 0

// Postcondition: The return value is the tinyest number in the

// statistician's sequence.

double minimum( ) const;

// Precondition: length( ) > 0

// Postcondition: The return value is the largest number in the

// statistician's sequence.

double maximum( ) const;

// FRIEND FUNCTIONS

// Postcondition: The statistician that is returned contains all the

// numbers of the sequences of s1 and s2 (the numbers of s1 followed

// by all of the numbers of s2).

friend statistician operator + (const statistician& s1, const statistician& s2);

// Postcondition: The statistician that is returned contains the same

// numbers that s does, but each number has been multiplied by the

// scale number.

friend statistician operator * (double scale, const statistician& s);

private:

int count; // How many numbers in the sequence

double total; // The sum of all the numbers in the sequence

double tinyest; // The smallest number in the sequence

double largest; // The largest number in the sequence

};

// NON-MEMBER functions for the statistician class

// Postcondition: The return value is true if s1 and s2 have the zero

// length. Also, if the length is greater than zero, then s1 and s2 must

// have the same length, the same mean, the same minimum,

// the same maximum, and the same sum.

bool operator ==(const statistician& s1, const statistician& s2);

//end of stats2.h

// stats2.cpp

#include "stats2.h"

#include <cmath>

#include <cfloat>

// tinyest is assigned to highest value of double type

// largest is assigned to lowest value of double type

statistician::statistician() : count(0),total(0),tinyest(DBL_MAX),largest(-DBL_MAX)

{}

void statistician:: next(double r)

{

       if(largest < r)

             largest = r;

       if(tinyest > r)

             tinyest = r;

       count++;

       total += r;

}

void statistician:: reset()

{

       count = 0;

       total = 0;

       tinyest = DBL_MAX;

       largest = -DBL_MAX;

}

int statistician::length() const

{

       return count;

}

double statistician::sum() const

{

       return total;

}

double statistician:: mean( ) const

{

       return(total/count);

}

double statistician:: minimum( ) const

{

       return tinyest;

}

double statistician:: maximum( ) const

{

       return largest;

}

statistician operator + (const statistician& s1, const statistician& s2)

{

       statistician s;

       s.count = s1.count + s2.count;

       s.total = s1.total + s2.total;

       if(s1.tinyest <= s2.tinyest)

             s.tinyest = s1.tinyest;

       else

             s.tinyest = s2.tinyest;

       if(s1.largest >= s2.largest)

             s.largest = s1.largest;

       else

             s.largest = s2.largest;

       return s;

}

statistician operator * (double scale, const statistician& s)

{

       statistician mul_s;

       mul_s.count = s.count;

       mul_s.total = s.total*scale;

       if(scale < 0)

       {

             mul_s.tinyest = s.largest*scale;

             mul_s.largest = s.tinyest*scale;

       }else

       {

             mul_s.largest = s.largest*scale;

             mul_s.tinyest = s.tinyest*scale;

       }

       return mul_s;

}

bool operator ==(const statistician& s1, const statistician& s2)

{

       const double EPSILON = 1e-5;

       if((s1.length() == 0) && (s2.length() == 0))

             return true;

       return((s1.length() == s2.length()) && (fabs(s1.mean()- s2.mean()) < EPSILON) && (fabs(s1.minimum()-s2.minimum()) < EPSILON) && (fabs(s1.maximum()-s2.maximum()) <= EPSILON));

}

//end of stats2.cpp

// FILE: statexam.cpp

// Written by Michael Main ([email protected])

// This program calls three test functions to test the statisitician class.

// Maximum number of points from this program is 90.

#include <iostream>

#include <cstdlib>

#include <cmath>

#include <string.h> // Provides memcpy function

#include "stats2.h"

using namespace std;

bool close(double a, double b)

{

const double EPSILON = 1e-5;

return (fabs(a-b) < EPSILON);

}

int test1( )

{

// Test program for basic statistician functions.

// Returns 62 if everything goes okay; otherwise returns 0.

statistician s, t;

int i;

double r = 0;

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

for (i = 1; i <= 10000; i++)

{

   s.next(i);

   r += i;

};

if (t.length( ) || t.sum( )) return 0;

if (s.length( ) != 10000) return 0;

if (!close(s.sum( ), r)) return 0;

if (!close(s.mean( ), r/10000)) return 0;

// Reset and then retest everything

s.reset( );

t.reset( );

r = 0;

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

for (i = 1; i <= 10000; i++)

{

   s.next(i);

   r += i;

};

if (t.length( ) || t.sum( )) return 0;

if (s.length( ) != 10000) return 0;

if (!close(s.sum( ), r)) return 0;

if (!close(s.mean( ), r/10000)) return 0;

return 62;

}

int test2( )

{

// Test program for minimum/maximum statistician functions.

// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u;

double r = 1000;

char n[15] = "10000000000000";

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

memcpy(&r, n, sizeof(double));

r = 1/r;

s.next(r);

if ((s.minimum( ) != r) || (s.maximum( ) != r)) return 0;

r *= -1;

t.next(r);

if ((t.minimum( ) != r) || (t.maximum( ) != r)) return 0;

u.next(100); u.next(-1); u.next(101); u.next(3);

if ((u.minimum( ) != -1) || (u.maximum( ) != 101)) return 0;

return 7;

}

int test3( )

{

// Test program for + operator of the statistician

// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u, v;

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

t.next(5);

u.next(0); u.next(10); u.next(10); u.next(20);

v = s + s;

if (v.length( ) || v.sum( )) return 0;

v = s + u;

if (!(u == v)) return 0;

v = t + s;

if (!(t == v)) return 0;

v = t + u;

if (v.length( ) != 5) return 0;

if (!close(v.sum( ), 45)) return 0;

if (v.minimum( ) != 0) return 0;

if (v.maximum( ) != 20) return 0;

if (!close(v.mean( ), 45.0/5)) return 0;

v = v + t;

if (v.length( ) != 6) return 0;

if (!close(v.sum( ), 50)) return 0;

if (v.minimum( ) != 0) return 0;

if (v.maximum( ) != 20) return 0;

if (!close(v.mean( ), 50.0/6)) return 0;

return 7;

}

int test4( )

{

// Test program for * operator of the statistician

// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u;

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

u.next(0); u.next(10); u.next(10); u.next(20);

s = 2*u;

if (s.length( ) != 4) return 0;

if (!close(s.sum( ), 80)) return 0;

if (s.minimum( ) != 0) return 0;

if (s.maximum( ) != 40) return 0;

if (!close(s.mean( ), 80.0/4)) return 0;

s = -2*u;

if (s.length( ) != 4) return 0;

if (!close(s.sum( ), -80)) return 0;

if (s.minimum( ) != -40) return 0;

if (s.maximum( ) != 0) return 0;

if (!close(s.mean( ), -80.0/4)) return 0;

s = 0*u;

if (s.length( ) != 4) return 0;

if (!close(s.sum( ), 0)) return 0;

if (s.minimum( ) != 0) return 0;

if (s.maximum( ) != 0) return 0;

if (!close(s.mean( ), 0)) return 0;

s = 10 * t;

if (s.length( ) != 0) return 0;

if (s.sum( ) != 0) return 0;

return 7;

}

int test5( )

{

// Test program for == operator of the statistician.

// Returns 7 if everything goes okay; otherwise returns 0.

statistician s, t, u, v, w, x;

if (s.length( ) || t.length( )) return 0;

if (s.sum( ) || t.sum( )) return 0;

t.next(10);

u.next(0); u.next(10); u.next(10); u.next(20);

v.next(5); v.next(0); v.next(20); v.next(15);

w.next(0);

x.next(0); x.next(0);

if (!(s == s)) return 0;

if (s == t) return 0;

if (t == s) return 0;

if (u == t) return 0;

if (!(u == v)) return 0;

if (w == x) return 0;

return 7;

}

int main( )

{

int value = 0;

int result;

cerr << "Running statistician tests:" << endl;

cerr << "TEST 1:" << endl;

cerr << "Testing next, reset, length, sum, and mean (62 points).\n";

result = test1( );

value += result;

if (result > 0) cerr << "Test 1 passed." << endl << endl;

else cerr << "Test 1 failed." << endl << endl;

cerr << "\nTEST 2:" << endl;

cerr << "Testing minimum and maximum member functions (7 points).\n";

result = test2( );

value += result;

if (result > 0) cerr << "Test 2 passed." << endl << endl;

else cerr << "Test 2 failed." << endl << endl;

cerr << "\nTEST 3:" << endl;

cerr << "Testing the + operator (7 points).\n";

result = test3( );

value += result;

if (result > 0) cerr << "Test 3 passed." << endl << endl;

else cerr << "Test 3 failed." << endl << endl;

cerr << "\nTEST 4:" << endl;

cerr << "Testing the * operator (7 points).\n";

result = test4( );

value += result;

if (result > 0) cerr << "Test 4 passed." << endl << endl;

else cerr << "Test 4 failed." << endl << endl;

cerr << "\nTEST 5:" << endl;

cerr << "Testing the == operator (7 points).\n";

result = test5( );

value += result;

if (result > 0) cerr << "Test 5 passed." << endl << endl;

else cerr << "Test 5 failed." << endl << endl;

cerr << "If you submit the statistician to Dora now, this part of the\n";

cerr << "grade will be " << value << " points out of 90.\n";

cerr << "If you submit the statistician to Dora now, this part of the\n";

cerr << "grade will be " << value << " points out of 90.\n";

return EXIT_SUCCESS;

}

//end of statexam.cpp

Output:

Add a comment
Know the answer?
Add Answer to:
Objectives The purpose of this lab is to help you become familiar with the development environment,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The purpose of this lab is to help reinforce container class concepts and linked list concepts...

    The purpose of this lab is to help reinforce container class concepts and linked list concepts in C++. Specifically, the lab to repeat the sequence lab from last week except to use a linked list. You need to use the author's files sequence3.h and sequence_exam3.cpp. Author - Michael Main, Book - Data Structures and other objects using c++, 4th edition // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is the header file for the...

  • The purpose of this program is to help reinforce container class concepts and linked list concepts...

    The purpose of this program is to help reinforce container class concepts and linked list concepts in C++. Specifically, the task is to implement the sequence class using a linked list. You need to use the author's file sequence3.h to create your implementation file named sequence3.cpp. Please make your code as efficient and reusable as possible. Please make sure code can pass any tests. sequence3.h // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe...

    c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe De Silva Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below: class bookType { public:    void setBookTitle(string s);            //sets the bookTitle to s    void setBookISBN(string ISBN);            //sets the private member bookISBN to the parameter    void setBookPrice(double cost);            //sets the private member bookPrice to cost    void setCopiesInStock(int noOfCopies);            //sets the private member copiesInStock to...

  • (C++) Two stacks of the same type are the same if they have the same number...

    (C++) Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various overloaded operators and functions of classstackType. **Please...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: --------------------...

    Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: ------------------------------------------------------------------------------------------------------------------------------------------ main.cpp #include #include "rectangleType.h" using namespace std; // part e int main() { rectangleType rectangle1(10, 5); rectangleType rectangle2(8, 7); rectangleType rectangle3; rectangleType rectangle4; cout << "rectangle1: " << rectangle1 << endl; cout << "rectangle2: " << rectangle2 << endl; rectangle3 = rectangle1 + rectangle2;    cout << "rectangle3: " << rectangle3 << endl; rectangle4 = rectangle1 * rectangle2;    cout << "rectangle4: " << rectangle4 << endl; if (rectangle1 > rectangle2) cout << "Area...

  • Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary...

    Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT