for the colum and row, how to fill the space with examcode automatically, below, I must put one by one..

/*-------------------
Two dimensional array
-------------------*/

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>


ifstream infile("STA83EXM.txt");


void main()
{


	const int row = 139;
	const int column = 139;
	int matrix[row] [column];

//**************creates Matrix****************
	int num;
		for(int i = 0; i<=row-1; i++)
		{
			for(int j = 0; j<=column-1; j++)
			{
				infile>>num;
				matrix[i][j]=num;
			}
		}
	

//***************Prints out Matrix*********************


	cout<<"\n\n"<<endl;
	cout<<"\t\tColumn:"<<setw(3)<<"1"<<setw(5)<<"2"<<setw(5)<<"3"<<setw(5)<<"4"<<setw(5)<<"5"<<setw(5)<<"6"<<endl;
	cout<<"\t\t--------------------------------------"<<endl;
	cout<<"\t\tRow 1|\t "<<setw(2)<<matrix[0][0]<<setw(5)<<matrix[0][1]<<setw(5)<<matrix[0][2]<<setw(5)<<
		matrix[0][3]<<setw(5)<<matrix[0][4]<<setw(5)<<matrix[0][5]<<endl;
	cout<<"\t\t    2|\t "<<matrix[1][0]<<setw(5)<<matrix[1][1]<<setw(5)<<matrix[1][2]<<setw(5)<<
		matrix[1][3]<<setw(5)<<matrix[1][4]<<setw(5)<<matrix[1][5]<<endl;
	cout<<"\t\t    3|\t "<<matrix[2][0]<<setw(5)<<matrix[2][1]<<setw(5)<<matrix[2][2]<<setw(5)<<
		matrix[2][3]<<setw(5)<<matrix[2][4]<<setw(5)<<matrix[2][5]<<endl<<endl;
	


return;
}

Recommended Answers

All 6 Replies

question is not very clear ... where is the examcode? where r u putting it?

Dear Chandra,

I put it in file ..ifstream infile("STA83EXM.txt");
I want to put in the column and row a number from 1 to 139 which it was an examcode.Then the next things to fill in the others column.

ok. so u'll enter the examcode in say [0][0] and corresponding marks in [0][1] or something like that ...? and what do you mean by "fill the space with examcode automatically" ?

Like this, i have a matrix 139 * 139.

i/j 1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9

i want to like above..to fill the colum and row with 1 until 139.

I wanna do like this ..but how to put 1 until 139 at the row?like this..

1 2 3 4 5 6 71
2
3
4
5


Can c++ draw a line for table?

/*-------------------
Two dimensional array
-------------------*/

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>

ifstream infile("STA83EXM.txt");

void main()
{
	const int row = 139;
	const int column = 139;
	int matrix[row] [column];

//**************creates Matrix****************
	int num;
		for(int i = 0; i<=row-1; i++)
		{
			for(int j = 0; j<=column-1; j++)
			{
				infile>>num;
				matrix[i][j]=num;
			}
		}
	
//***************Prints out Matrix*********************

{
	for(int i = 1; i < 140; i++)
	{
		cout << i << endl;
	}


return;
}

}

Do you mean you want the first row and column of numbers in the table will represent the labels of the row and column respectively? If so and the table is table of ints or a table of strings, then the labels can be incorprated into the table by hardcoding it in. If the table is to hold values other than ints or strings, and you want ints or strings as the labels, then you may need to come up with a compound type if you want the labels incorporated into the table or you may want to display the labels using a separate output statements from the output statement of the table contents.

If the table is to contain 139 values per row plus the label, then there needs to be 140 rows and 140 columns.

As a point of clarity which looks easier to understand:
i <= row-1
or
i < row
the statements are equivalent.

To display the array in tabular form you will need a nested array, or similar construct. Your output statement in post #6 just displays a single row of ints.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.