Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can I get help with this? This is all in C++ Note This lab uses unit tests to check each of your functions. This means

Can I get help with this?

This is all in C++

Note

  • This lab uses unit tests to check each of your functions. This means that you need to declare your functions exactly as specified, or the tests will not compile.
  • You also need to have a main function for the unit tests to compile, but you do not need to write anything inside of it for the tests to pass. The provided template code has a copy of the unit tests run in Submit Mode so that you can test your code in Develop Mode.

Functions to Implement

(1) Implement the IsItSquare function. IsItSquare takes parameters height and width as doubles and returns a boolean. If the given height and width make a square, return true.

(2) Implement the PrintIsItSquare function. PrintIsItSquare takes parameters height and width as doubles and calls IsItSquare. PrintIsItSquare then outputs the results of IsItSquare. The numbers should be printed with exactly one digit after the decimal point. Ex:

A rectangle with height 4.5 and width 6.3 is not a square. A rectangle with height 5.2 and width 5.2 is a square. 

(3) Implement the MakeSquare function. MakeSquare takes parameters height and width as doubles and modifies them to make them equal if they are not already. This function should shrink the longer side to match to shorter side. You need to declare your function such that the caller of your function can see the changes to the parameters (By default, functions make copies of the variables you pass in before using them. Normally, changing values in your function will change the values of those copies instead of the variables you originally passed in).

(4) Implement the CalcPerimeter function. CalcPerimeter takes parameters height and width as doubles and calculates and returns the perimeter of the rectangle.

(5) Implement the PrintPerimeter function. PrintPerimeter takes parameters height and width as doubles and calls CalcPerimeter. PrintPerimeter then outputs the results. The numbers should be printed with exactly one digit after the decimal point. Ex:

A rectangle with height 4.5 and width 6.3 has a perimeter of 21.6. 

(6) Implement the DoublePerimeter function. DoublePerimeter takes parameters height and width as doubles and modifies them such that the perimeter of the rectangle they make is double but maintains the same ratio of height to width. You need to declare your function such that the caller of your function can see the changes to the parameters (By default, functions make copies of the variables you pass in before using them. Normally, changing values in your function will change the values of those copies instead of the variables you originally passed in).

Additional note: you can assume that all values passed to your functions will be greater than 0.

and the template that they want is this

#include #include using namespace std;

//Write your functions here

/** * This template code has a copy of each type of unit test that will be run in Submit Mode. * This should allow you to test your code in Develop Mode by uncommenting the test you want to run. */ int main() { //IsItSquare test 1 /* bool studentResult = IsItSquare(1.2, 4.3); if (!studentResult) { cout << "IsItSqaure test 1 passed" << endl; } else { cout << "IsItSquare(1.2, 4.3) incorrectly returned true" << endl; } */ //PrintIsItSquare test 1 /* PrintIsItSquare(0.9, 4.0); //This should print "A rectangle with height 0.9 and width 4.0 is not a square." to cout. // (the unit test has more complicated code to check this) */ //MakeSquare test 1 /* double studentLength = 3.8; double studentWidth = 3.6; MakeSquare(studentLength, studentWidth); if (studentLength == studentWidth && studentLength > 3.59 && studentLength < 3.61) { cout << "MakeSquare test 1 passed" << endl; } else { cout << "MakeSquare(3.8, 3.6) incorrectly modified 3.8 to be " << studentLength << " and/or 3.6 to be " << studentWidth << "." << endl; } */ //CalcPerimeter test 1 /* double studentResult = CalcPerimeter(3.5, 6.2); if (studentResult > 19.39 && studentResult < 19.41) { cout << "CalcPerimeter test 1 passed" << endl; } else { cout << "CalcPerimeter(3.5, 6.2) incorrectly returned " << studentResult << endl; } */ //PrintPerimeter test 1 /* PrintPerimeter(2.6, 4.4); PrintIsItSquare(0.9, 4.0); //This should print "A rectangle with height 2.6 and width 4.4 has a perimeter of 14.0." to cout. // (the unit test has more complicated code to check this) */ //DoublePerimeter test 1 /* double studentLength = 4.6; double studentWidth = 6.1; DoublePerimeter(studentLength, studentWidth); if (studentLength > 9.19 && studentLength < 9.21 && studentWidth > 12.19 && studentWidth < 12.21) { cout << "DoublePerimeter test 1 passed" << endl; } else { cout << "DoublePerimeter(4.6, 6.1) incorrectly modified 4.6 to be " << studentLength << " and/or 6.1 to be " << studentWidth << "." << endl; return false; } */ return 0; }

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

What is Entrepreneur?

Answered: 1 week ago

Question

Which period is known as the chalolithic age ?

Answered: 1 week ago