######I have a problem due later tonight and i dont know where to start ####here
ID: 3687047 • Letter: #
Question
######I have a problem due later tonight and i dont know where to start
####heres the question below
(Use box.cpp) This part does not use reference parameters, only value parameters, but does use "overloaded" displayBox functions...the four prototypes are as follows:
void displayBox ( int length );
void displayBox ( int length, char fillChar );
void displayBox ( int width, int height );
void displayBox ( int width, int height, char FillChar );
The 3-argument function will use nested for loops for its logic. The other overloaded functions do not use any logic other than a calling statement to the 2 argument function or the 3 argument function.
The 2-arguments functions will call the 3-argument function and the 1-argument function will call the 2-argument function.
Use input data of 5 ? 15 4 $
#######and the hints provided in class below
Complete the box.cpp file supplied in the assignment...first complete displayBox function...
displayBox Function with 3 parameters width, height and fillerCharacter
Output width number of X's...use a FOR statement
Output a new line
Loop height minus 2 times
Output X
Output fillerCharacter width minus 2 times
Output X
Output newline
End Loop
Output width number of X's...Use a FOR statement
The one-parameter (length) displayBox function will have one line of code...
Call the two-parameter displaybox function sending box's length and a single character enclosed in single tick/quote
marks..(.double quotes are invalid for char data types.)
The two-parameter displayBox also will have one line of code...
Call the three-parameter displaybox sending either some literal, say 10, and box's length and filler character
...or the box's width, height and a character literal, say '$'
The idea is that the 1-parameter displayBox can do nothing but call the appropriate 2-parameter
displayBox and the 2-parameter displayBox can do nothing but call the 3-parameter displayBox.
######and the template provided below
#include <iostream>
using namespace::std;
// Function prototypes
void displayBox(int length);
void displayBox(int length, char fillChar);
void displayBox(int width, int height);
void displayBox(int width, int height, char FillChar);
//--------------------------------------------------------------------
int main()
{
int boxLength, boxWidth, boxHeight; // Input box dimensions
char boxFill; // Input fill character
// Test the displayBox(length) and displayBox(length,fillChar) functions.
cout << endl << "Enter the length of a side: ";
cin >> boxLength;
displayBox(boxLength);
cout << endl << "Enter the fill character: ";
cin >> boxFill;
displayBox(boxLength, boxFill);
// Test the displayBox(width,height) and displayBox(width,height,fillChar) functions.
cout << endl << "Enter the width and height of the box: ";
cin >> boxWidth >> boxHeight;
displayBox(boxWidth, boxHeight);
cout << endl << "Enter the fill character: ";
cin >> boxFill;
displayBox(boxWidth, boxHeight, boxFill);
return 0;
}
//--------------------------------------------------------------------
void displayBox(int length)
{
// call the 2 argument function, int and char
}
void displayBox(int length, char fillChar)
{
// call the 3 argument function
}
void displayBox(int width, int height)
{
// call the 3 argument function
}
void displayBox(int width, int height, char FillChar)
{
// using nested loops, write this function
}
Explanation / Answer
#include <iostream>
using namespace::std;
// Function prototypes
void displayBox(int length);
void displayBox(int length, char fillChar);
void displayBox(int width, int height);
void displayBox(int width, int height, char FillChar);
//--------------------------------------------------------------------
int main()
{
int boxLength, boxWidth, boxHeight; // Input box dimensions
char boxFill; // Input fill character
// Test the displayBox(length) and displayBox(length,fillChar) functions.
cout << endl << "Enter the length of a side: ";
cin >> boxLength;
displayBox(boxLength);
cout << endl << "Enter the fill character: ";
cin >> boxFill;
displayBox(boxLength, boxFill);
// Test the displayBox(width,height) and displayBox(width,height,fillChar) functions.
cout << endl << "Enter the width and height of the box: ";
cin >> boxWidth >> boxHeight;
displayBox(boxWidth, boxHeight);
cout << endl << "Enter the fill character: ";
cin >> boxFill;
displayBox(boxWidth, boxHeight, boxFill);
return 0;
}
//--------------------------------------------------------------------
void displayBox(int length)
{
displayBox(length, '*');
}
void displayBox(int length, char fillChar)
{
// call the 3 argument function
displayBox(lenght, 10, fillChar);
}
void displayBox(int width, int height)
{
// call the 3 argument function
displayBox(width, height, '*');
}
void displayBox(int width, int height, char FillChar)
{
// using nested loops, write this function
for(int i=0;i<=height-2;i++)
{
cout<<'X';
for(int j=0;j<=width-2;j++)
{
cout<<FillChar;
}
cout<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.