Part I:
/*****************************************************************************
***
* DIAMONDS
* author(s):
* adapted from:
* other citations:
*
* goal: Output a diamond of user determined size must use a 2D array.
* example: for input of 5 ..*.. or 6 ../\..
* .***. .//\\.
* ***** ///\\\
* .***. \\\///
* ..*.. .\\//.
* ..\/..
* overview: (1) get user input & validate (i.e. less than screen size)
* (2) determine even/odd and how to proceed
* (3) create & fill array accordingly
* (4) output to screen
*
*
* stages: (1) hard-coded 5x5 diamond - output to screen
* must use given function def - passes in one row at a time
* (2) Do odd number case only in this stage - subtract 1 from any even #
* get width of diamond from user (use same number for height)
* create a 2D array of that size and fill with the background char
* must use given function defs - passes in one row at a time
* (3) Now we overload fillArray - don't duplicate code. If the same code
* is being run then one fillArray function should call the other
* Add in the diamond forming character (the MAIN_CHAR)
* This stage should complete the odd case
* (4) Using the same functions as the previous case, do the even case
*
*
*****************************************************************************
***/
#include
using namespace std;
const unsigned int max_width = 120;
char background_char = '.';
char main_char = '*';
char main_char_left = '/';
char main_char_right = '\\';
/* function prototype declarations (defined below in same file) */
void printArray (const char chArray[], const unsigned int width) {
for (unsigned int i = 0; i < width; i++) {
cout << chArray[i];
}
}
int main()
{
/* variables */
/* declare and initialize an array */
char diamond[5][5] = {{background_char, background_char, main_char,background_char,
background_char},
{background_char,main_char, main_char, main_char, background_char},
{main_char, main_char, main_char, main_char, main_char},
{background_char,main_char, main_char, main_char, background_char},
{background_char, background_char, main_char,background_char,
background_char}};
/* output array */
for (int i = 0; i < 5; i++) {
printArray(diamond[i], 5);
cout << endl;
}
When input 10:
When input 40:
When input 4000:
In this stage we will complete the odd-number input case, adding stars to create the diamond. So
if the user enters 15 , the program should output: To do this, we will overload the fillarray()
function. The following function definition is required: void fillarray (char fill, char chArray[],
unsigned int start, unsigned int end); where fillArray would fill the indices from start to end-1
(not including end). When overloading, we should not be duplicating code. It is likely that the
efficient way to overload is for one of the fillArray () functions to call the other. Everything else
would work the same as in Part II.
Expected output Enter width of diamond: Error! Max width is 120 . Exiting.
Enter width of diamond: ...***... .. kk. . . . . .
Part .
MARGINALIZATION (Different learners in Marginalized Group
Part I.pdf
1. Part I:
/*****************************************************************************
***
* DIAMONDS
* author(s):
* adapted from:
* other citations:
*
* goal: Output a diamond of user determined size must use a 2D array.
* example: for input of 5 ..*.. or 6 ../..
* .***. .//.
* ***** ///
* .***. ///
* ..*.. .//.
* ../..
* overview: (1) get user input & validate (i.e. less than screen size)
* (2) determine even/odd and how to proceed
* (3) create & fill array accordingly
* (4) output to screen
*
*
* stages: (1) hard-coded 5x5 diamond - output to screen
* must use given function def - passes in one row at a time
* (2) Do odd number case only in this stage - subtract 1 from any even #
* get width of diamond from user (use same number for height)
* create a 2D array of that size and fill with the background char
* must use given function defs - passes in one row at a time
* (3) Now we overload fillArray - don't duplicate code. If the same code
* is being run then one fillArray function should call the other
* Add in the diamond forming character (the MAIN_CHAR)
* This stage should complete the odd case
* (4) Using the same functions as the previous case, do the even case
*
*
*****************************************************************************
2. ***/
#include
using namespace std;
const unsigned int max_width = 120;
char background_char = '.';
char main_char = '*';
char main_char_left = '/';
char main_char_right = '';
/* function prototype declarations (defined below in same file) */
void printArray (const char chArray[], const unsigned int width) {
for (unsigned int i = 0; i < width; i++) {
cout << chArray[i];
}
}
int main()
{
/* variables */
/* declare and initialize an array */
char diamond[5][5] = {{background_char, background_char, main_char,background_char,
background_char},
{background_char,main_char, main_char, main_char, background_char},
{main_char, main_char, main_char, main_char, main_char},
{background_char,main_char, main_char, main_char, background_char},
{background_char, background_char, main_char,background_char,
background_char}};
/* output array */
for (int i = 0; i < 5; i++) {
printArray(diamond[i], 5);
cout << endl;
}
When input 10:
3. When input 40:
When input 4000:
In this stage we will complete the odd-number input case, adding stars to create the diamond. So
if the user enters 15 , the program should output: To do this, we will overload the fillarray()
function. The following function definition is required: void fillarray (char fill, char chArray[],
unsigned int start, unsigned int end); where fillArray would fill the indices from start to end-1
(not including end). When overloading, we should not be duplicating code. It is likely that the
efficient way to overload is for one of the fillArray () functions to call the other. Everything else
would work the same as in Part II.
Expected output Enter width of diamond: Error! Max width is 120 . Exiting.
Enter width of diamond: ...***... .. kk. . . . . .
Part IV Finally, we will complete the even number case. This case will use the same fillArray ()
and printArray () functions written for the previous part. There are constant variables given for
the characters in the original Part I template: char background_char = '.'; char main_char = '*';
char main_char_left =1/; char main_char_right =; char background_char = '.'; char main_char =
'*'; char main_char_left =1/; char main_char_right = '; For example, for an input of 16 we
would get:
Enterwidthofdiamond:16,//////////////////.////////////////////////////////
///////////, Everything else would work the same as in Part III.
begin{tabular}{|c|c|} hline Expected output &
Enterwidthofdiamond:./////.////////////////////// hline end{tabular}
4. In this part, we will add getting the size input from the user and writing a function to fill the
array. For this stage, we will only fill the array with the background character, and we will only
work on the odd number case. So if the user enters an even number, subtract one to get the array
width. It is a requirement to use the given definition of the fillArray function, with these exact
parameters, which is: void fillArray (char fill, char charray[], unsigned int width); So for
example, if the user enters 10 , the program should output the following grid (which is 9
characters wide): where 10 is the user input and "Enter width of diamond: "is the prompt given
to the user by the program.