Question: #define DOCTEST _ CONFIG _ IMPLEMENT _ WITH _ MAIN #include doctest.h / / Use Approx from doctest without saying doctest::Approx using doctest::Approx; /

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
//Use Approx from doctest without saying doctest::Approx
using doctest::Approx;
//-----------------------------------------------------------------------------------
#include
#include
using namespace std;
int getArea (int width, int length){
return width * length;
}
int leftoverCardboard(int cutoutSize){
int sheetWidth =2* cutoutSize;
return getArea( sheetWidth, sheetWidth);
}
int getVolume (int width, int length, int height){
return getArea (width, length)* height;
}
int getMaxHeight (int width, int length){
return min (width /2, length /2);
}
int getBestHeight (int width, int length){
int bestHeight =0, maxVolume =0;
int maxHeight = getMaxHeight (width, length);
for (int h =1; h <= maxHeight; ++h){
int currentVolume = getVolume (width -2* h, length -2* h, h);
if (currentVolume > maxVolume ||(currentVolume == maxVolume && leftoverCardboard(h)> leftoverCardboard (bestHeight))){
maxVolume = currentVolume;
bestHeight = h;
}
}
return bestHeight;
}
void printBoxOptions (int width, int length){
cout << setw (6)<< "Height" << setw(8)<< "Width" << setw(9)<< "Length" << setw(9)<< "Volume" << setw(18)<< "Leftover Amount"<< endl;
}
///----------------------------------------------------------------------------------
/// Tests
/// Uncomment tests to work on them. Make sure any test that does not compile or
/// causes a crash gets commented back out. Any test that runs should be left
/// on (uncommented), even if the test fails.
///----------------------------------------------------------------------------------
TEST_CASE( "getArea" ){
cout <<"1: getArea" << endl;
CHECK( getArea(2,4)==8);
CHECK( getArea(12,7)==84);
}
TEST_CASE( "getVolume" ){
cout <<"2: getVolume" << endl;
CHECK( getVolume(2,4,3)==24);
CHECK( getVolume(12,7,2)==168);
}
TEST_CASE( "leftoverCardboard" ){
cout <<"3: leftoverCardboard" << endl;
CHECK( leftoverCardboard(3)==36);
CHECK( leftoverCardboard(10)==400);
}
TEST_CASE( "getMaxHeight" ){
cout <<"4: getMaxHeight" << endl;
CHECK( getMaxHeight(5,10)==2);
CHECK( getMaxHeight(10,5)==2);
CHECK( getMaxHeight(12,16)==5);
CHECK( getMaxHeight(18,16)==7);
}
TEST_CASE( "getBestHeight" ){
cout <<"5: getBestHeight" << endl;
CHECK( getBestHeight(10,15)==2);
CHECK( getBestHeight(15,10)==2);
CHECK( getBestHeight(16,14)==3);
CHECK( getBestHeight(20,22)==4);
CHECK( getBestHeight(300,180)==36);
}
TEST_CASE( "createBoxDescription" ){
cout <<"6: createBoxDescription" << endl;
string test1= createBoxStatsString(8,6,2);
string goal1="2869616";
//INFO will only print if test is failed
INFO("test1|", test1,"|");
INFO("goal1|", goal1,"|");
CHECK( test1== goal1);
string test2= createBoxStatsString(13,20,4);
string goal2="41320104064";
//INFO will only print if test is failed
INFO("test2|", test2,"|");
INFO("goal2|", goal2,"|");
CHECK( test2== goal2);
}
TEST_CASE( printBoxOptions ){
cout <<"7: printOptions" << endl;
////Not really an automated test. Need to verify output manually
cout << R"(Expected:
Height Width Length Volume Leftover Amount
11813

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!