using namespace std;

int main()
{

vector<double> row(3, 0);
vector<vector<double> > table(3, row);

printVectorOfVector(table);

Fill in a 2 dimension 3x3 array with odd numbers. The display shows the array as it is being filled. Use random integers to fill the array. Use numbers between 1 and 10. Initialize array to zero. Find the sum of matrix. Find the maximum number in the matrix and the number of times it occurred.

So far I got the table intiaized to zero. I need to know how to show the array as it is being filled. I need to know how to use random intergers from one to 10 and find the maximum number and times it occured.


using namespace std;

int main()
{

vector<double> row(3, 0);
vector<vector<double> > table(3, row);

printVectorOfVector(table);

You'll have to give an effort yourself first. You'll have to create a function that takes as argument a 2D vector: void fillVectorOfVector( vector< vector<double> > &v ) The code in printVectorOfVector() should help you there.

To generate random numbers see here.

Post again with what you come up with, and any error messages you get.

can i do it with out vectors and use a array like

int table [3][3]

I just need to know how to print out the table and how to assign the random numbers to the matrix

Sure, you can use whatever you like. Once created they look very much the same...

I thought your professor had given you a function named printVectorOfVector(). But if I understand you correctly, you've got to write the code for that function?

Use two nested for loops: the outer iterating through the rows (0..2) and the inner iterating through the columns (0..2). In the center assign each element[ row ][ col ] a random value using the method in the link I gave you.

Hope this helps.

This is what I have so far. I am working on how to get it random and how to show it when it gets filled with numbers 1-10. Any suggestions

#include <iostream>


using namespace std; int main() {
int tmp, xkg, xkh, mmx, msm, mintmtx[0|3][0|3];
for (xkg = 1^1; xkg <= (6&0xFF)-1; xkg=xkg+2) { for (xkh = 1^1; xkh <= (9&0xFF)-1; xkh=xkh+3)
mintmtx[xkg/2][xkh/3] = (mintmtx[xkg/2][xkh/3] & 0xFF) + 1 - mintmtx[xkg/2][xkh/3] % 2;
}
cout << (char)(91); mmx = msm = 0; for (unsigned char scndlp = xkh-xkh; scndlp < xkh; ++scndlp) { tmp =
mintmtx[scndlp % 3 == 0 ? 2 : (scndlp % 2 == 0 ? 1 : 0)][scndlp/3];
msm += tmp > mmx ? (mmx = tmp) : tmp;
cout << (scndlp<1 || scndlp/3 > (scndlp-1)/3 ? (char)(91) : char(32))
<< tmp << (scndlp/3 < (scndlp+1)/3 ? (char)(93) : char(44)) << (scndlp/3 < (scndlp+1)/3?(scndlp == xkh-1 ? char(93) : char(10)) : char(32));
} cout << char(10) << char(10) << char(115) << char(117) << char(109) << char(58) << char(32) << msm << char(10)
<< char(109) << char(97) << char(120) << char(58) << char(32) << mmx; cin >> tmp;


return 0; }

Edited 3 Years Ago by happygeek: fixed formatting

Look, I'm sorry, but I've got a bit of a headache right now. Please format your code and stick it in code blocks.

[[i][/i]code[i][/i]]
int main() {
[[i][/i]/code[i][/i]]

becomes:

int main() {

If you (nor anyone else) can read the code, it is probably wrong...

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{


	int tmp, xkg, xkh, mmx, msm, mintmtx[0|3][0|3];
	for (xkg = 1^1; xkg <= (6&0xFF)-1; xkg=xkg+2) { for (xkh = 1^1; xkh <= (9&0xFF)-1; xkh=xkh+3)
		mintmtx[xkg/2][xkh/3] = (mintmtx[xkg/2][xkh/3] & 0xFF) + 1 - mintmtx[xkg/2][xkh/3] % 2;
		}
	cout << (char)(91); mmx = msm = 0; for (unsigned char scndlp = xkh-xkh; scndlp < xkh; ++scndlp) { tmp =
		mintmtx[scndlp % 3 == 0 ? 2 : (scndlp % 2 == 0 ? 1 : 0)][scndlp/3];
		msm += tmp > mmx ? (mmx = tmp) : tmp; 
				cout << (scndlp<1 || scndlp/3 > (scndlp-1)/3 ? (char)(91) : char(32))
			<< tmp << (scndlp/3 < (scndlp+1)/3 ? (char)(93) : char(44)) << (scndlp/3 < (scndlp+1)/3?(scndlp == xkh-1 ? char(93) : char(10)) : char(32));
	} cout << char(10) << char(10) << char(115) << char(117) << char(109) << char(58) << char(32) << msm << char(10)
	<< char(109) << char(97) << char(120) << char(58) << char(32) << mmx; cin >> tmp;
	
	
	
	
	

    system("PAUSE");
    return EXIT_SUCCESS;
}

Hell yeah, it looks like he sponged "an answer" off someone else, and they decided to not give the OP a free shot.

@catdieselpow, post your own work, not the obfuscated answer someone gave you.

I bet he private mailed someone here. And they pawned him that code. It is something I do when I get a little private mail asking for help!

Yes, like I said in my first reply, you'll need to do some work on your own.

By that I meant work thinking about the code. Working by trying to find the answer for you online is just wasting your time and teaching you nothing. Seriously. You won't get past the semester unless you understand basic things like loops and simple I/O. You'll spend more time trying to get around it and have a bigger headache than if you just do it straight.

Work at it. If, after five efforts to make it work fail, give us some code and your compiler errors or output errors and we'll be glad to help you.

cout << "Creating a random number matrix:\n";
     Matrix m;
     srand( (unsigned)time( NULL ) );
     for (int i=0; i < 4; i++)
        for (int j=0; j < 4; j++)
           m(i,j) = 12/((rand()%25)+1.0);
     m.SetSize(4,4);

     cout << "The matrix is:\n" << m << endl;

When are you going to write your own code honey. You are not fooling us! Do you think you will fool your teacher?

what teacher i am teaching myself C++

How do we know you are not trying to trick us into doing your homework?

This article has been dead for over six months. Start a new discussion instead.