Image

Imageicstepec wrote in Imagecpp

C++ under MIcrosoft VIsual C++ - ... arrays... :(

So I'm in 3rd quarter of programming at school; and we've done some few minor things;

Basically we've worked with variables, functions, pointers, and the last lesson was on structures...

However the homework is asking to use arrays, which isn't covered till next week.



I need some help w/ arrays... I just don't completly understand them after reading the material.

"Write a C++ program that uses a two dimensional character grid and generates various square patterns. The output patterns are shown in Figure 6.2.1. THe user is presented with the option of choosing one of the five different patterns or to exit the program.

Bordered Edge (square)
X lines
+ sign
Bordered X
Bordered +

- you must use the following functions

void writeheader();
int getuserchoice();
void clear grid(char [][15]);
void fillborder(char, char[][15]);
void fillplus(char, char[][15]);
void fillx(char, char[][15]);
void WriteGrid(char [][15]);

------ the following code is what I have so far... please note I did it in five minutes and I *know* there is a ton of things missing in it, however I just need an explanation with arrays, and if I'm going about it right w/ the variables I've used ....

I'm providing all this to try and get as much info out as possible, again I'm going to keep working on it however I'm going to hit a wall pretty hard w/ the arrays...

Thanks.


#include

using namespace std;

// functions

// intro
void writeheader();

// user input, choice of grid + choice of char used
int getuserchoice();
char getuserchar();

// code blocks to 'draw' the grid based on choice
void fillborder();
void fillplus();
void fillx();

// code blocks executing the drawing + clearing of grid
void writegrid();
void cleargrid();

// variables needed? //

int choice, userchar;
int row[15], col[15];
int prow[15], pcol[15];
int xrow[15], xcol[15];

int main()
{

writeheader(); // calling intro

getuserchoice(); // calling menu

cout << "Thank you, have a nice day.";

return 0;

}

void writeheader() // intro, required for class
{
cout << "\nThis program will display a grid based on your choice."
<< "\nWritten by Chris M. Van - C++ with Etter.\n";

return;

}

int getuserchoice() // menu
{
cout << "\n\n\t Please choose one of the following options: "
<< "\n\n\t 1.\t Square Box"
<< "\n\t 2.\t X"
<< "\n\t 3.\t +" // these are the options required
<< "\n\t 4.\t Bordered X"
<< "\n\t 5.\t Bordered +"
<< "\n\t 6.\t Exit Program"
<< "\n\n\t Choice: ";

cin >> choice;

if(choice == 1) // I'll do the rest afterwards..
{
cout << "Your options are working fine.";
}

else if(choice == 6)
{
return 0;
}
else
{
cout << "\n\n I'm sorry, that did not make sense, loading options again...";

getuserchoice();
}

userchar = getuserchar(); // after choice selected send user to pick a character

return 0;

}

char getuserchar() // this function receives and returns the character used to fill the grid
{
cout << "\n\nThank you, you've chosen option number " << choice << "."
<< "\nNow please select a character to fill your grid: ";
cin >> userchar;

return userchar;

}