I would like to be able to send the vector to a function, so I can initialize the contents of it, but, I can't figure out a way to do it.
Tried Init( Spreadsheet); in main, with the function created as.. void Init(vector <Cell>& Spreadsheet[int Spreadsheet_Height][int Spreadsheet_Width]) but I get red squiggles under some of the wording. I have written programs that send plain vectors with no problem, but a 2D one is stumping me. Could someone point me in the correct direction on getting this to work? If you need the whole program, I can upload it to dropbox where it can be DL'd. Right now, it's 10,418 bytes and growing. Thanks for any help.
Thanks, that was a big help. I was now able to initialize the full spreadsheet, but I'm having a small problem trying to figure out how to print only a section of it. On the console, I need to print out only the first 19 columns, and the first 18 rows. Then using the arrow keys, I can shift the columns left or right and the rows, up or down. So, if the console is showing columns 0 to 19, and I want to press the right arrow, I now need to show column 0, then columns 2 to 20. Pressing right again will display column 0, then columns 3 to 21. Of course, the same applies to the up/down display, as well. It shows rows 0 to 18, then pressing down, shows row 0 and rows 2 to 19, etc.
The reason for always showing row 0 and column 0, is because they are initialized with 'A' to 'AZ' for row 0, and 1 to 75 for column 0, and I want those always displayed.
I'm not sure how I can stop the entire spreadsheet vector from being displayed.
constint Spreadsheet_Width = 53;
constint Spreadsheet_Height = 76;
constint Height = 5;
constint Width = 7;
struct Rectangle {
int top;
int left;
int bottom;
int right;
Rectangle() : top(0), left(0), bottom(Height), right(Width) { }
void move_left()
{
if (left > 0) { left--; right = left + Width; }
}
void move_right()
{
if (left+Width < Spreadsheet_Width) { left++; right = left + Width; }
}
void move_up()
{
if (top > 0) { top--; bottom = top + Height; }
}
void move_down()
{
if (top+Height < Spreadsheet_Height) { top++; bottom = top + Height; }
}
};
void print_window(const vector<vector<Cell>>& Spreadsheet, const Rectangle& rect)
{
for (int i=rect.top; i<rect.bottom; i++)
{
for (int j=rect.left; j<rect.right; j++)
{
cout << setw(4) << Spreadsheet[i][j].number;
}
cout << '\n';
}
}
Elsewhere in the code I declare a Rectangle object and use the keyboard to trigger the calling of the member functions such as rect.move_right(); and then call the print function, print_window(Spreadsheet, rect); along with a few other bits and pieces to position the cursor on the console and so on.
Hope those fragments are of some use, the complete code was a bit of a mess, so it seemed unnecessary to post it.
@Chervil
The last bit of code you showed me looks nice, but I'm just learning about this 2d vector stuff. I'm not sure how to declare the Rectangle object, nor call the member functions. When I tried plugging in the Rectangle struct and print_window function, I get the red squiggle line under Rectangle in the print_window function.
Anyway, I'm having problems with getting it to compile before trying to add the new coding into it.
I'm getting a couple of errors when I try to initialize the Spreadsheet vector
Thanks. I totally missed that. I kept looking inside the function and trying to figure what I did wrong there. Now it compiles and displays correctly on screen. I'll call this completed and start another thread if or when, I run into more problems.
I'm not sure how to declare the Rectangle object, nor call the member functions. When I tried plugging in the Rectangle struct and print_window function, I get the red squiggle line under Rectangle in the print_window function.
I tried to tidy up my code a bit so I could post it here, and ran into some problem with the Rectangle struct. I didn't look too deeply int the details, but there was a name clash with something in the windows.h header. To fix that, I added a namespace. Since this is nothing special, I just called it xyz.
The below code may or may not compile on your system, it uses some non-standard stuff, and some windows functionality.
@Whitenite1
Thanks, you're welcome. Actually, I've learned stuff from you too. I think the gotoxy() function originally came from one of your posts, and a number of other things too. I learn from everyone actually. Just trying to think of answers to some of the questions on this forum is a learning process in itself.
Nowadays I'm programming only for fun or things which interest me. It just happened that something about your project caught my attention so I got a bit caught up in it. I didn't intend my code to be quite so long, but I wanted it to be something which worked, shown in context.
Thank you. Oh, by the way, I haven't written instructions yet on the spreadsheet program use. All it can do right now, is add a 'XX' to a cell. To specify which cell, you first press '@' symbol, then a small or capital 'A' or up to an 'AZ' then the row 1 to 75. Press 'Enter'. A 'XX' is then placed in the corresponding cell. Use the cursor keys to shift the cells in the desired directions. The column letter and row numbers, always stay on screen.