stuck on next step

My code below is six rows by six columns of zeros in which I would like to eventually like the last five left side cells to be numbered, and the last five top cells of the first column to be lettered. Kind of like so:

0 A B C D E

1 0 0 0 0 0

2 0 0 0 0 0

3 0 0 0 0 0

4 0 0 0 0 0

5 0 0 0 0 0

My code is as follows, but everything I try gets many errors so I keep erasing things I add. Any advice on getting the column and row headers?

#include <iostream>
#include <vector>

using namespace std;


vector <int>rowOne(6);
vector <int>rowTwo(6);
vector <int>rowThree(6);
vector <int>rowFour(6);
vector <int>rowFive(6);
vector <int>rowSix(6);
void clear (vector<int>& someRow);
void print (vector<int>& someRow);
//void printAll;
//int rowLabel;

int main()
{
cout << "Chris's Spreadsheet\n" << endl;
{
clear (rowOne);
clear (rowTwo);
clear (rowThree);
clear (rowFour);
clear (rowFive);
clear (rowSix);
print(rowOne);
print(rowTwo);
print(rowThree);
print(rowFour);
print(rowFive);
print (rowSix);
}
return 0;

}

void clear (vector<int>&someRow)
{
for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
}

void print (vector<int>&someRow)
{
for (int i=0; i < rowOne.size(); i++)
cout << rowOne[i] << " ";
cout <<endl;

for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
cout << endl;

}
Hi CRBottini, I assume your print function is supposed to output the entire vector?

You should change rowOne to someRow in the first loop of your print function. At the moment it is printing rowOne and not the parameter, someRow, that is passed to the print function.

As for the second for loop it is clearing someRow that is passed to the print function as a parameter. In other words, it is making your print function behave like your clear function. Are you sure this is what you are trying to do?

As for printing the column and row headers, there are several ways to do it...

In your main function, you can print the column headers by having a cout statement before all the print statements.

As for the row headers, you can simply cout the appropriate label before each print statement.

A more appropriate (and easier) way to do it would be to use an array of vectors. You can make use of the [ ] syntax and use a variable as your index of your vectors array. Then you can loop that variable to print out all the vectors.
Last edited on
Topic archived. No new replies allowed.