1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// Matrix.cpp : Defines the entry point for the console application.
//
#include "stdafx.h" //must for MS visual studio
#include <iostream> //For function cout<<
#include <fstream> //For I/O from file
#include <string> //For string op
#include <cstdlib> //??
#include <vector>
using namespace std;
class matrix
{
int d1, d2; //dimensions
vector<vector<float>> p; // All values of matrix
public:
//We are not using the default constructor
matrix(int, int); //Constructor will only create the space here LLL
~matrix();
void set_value(int, int, float); // first two args are element position specifiers.
};
matrix::matrix(int d11, int d22)
{
d1=d11;
d2=d22;
vector<vector<float>> p(d2, vector<float>(d1,0));
}
matrix::~matrix()
{
//I believe that I do not need to write a destructor as there is no pointer involved.
}
void matrix::set_value(int i, int j, float value)
{
p[j][i] = value;
}
int main()
{
int m, n; //dimensions
int i,j;
float value;
//Enter size m>>n
//Enter element one by one
//Use the for loop
cout<<"Enter the dimensions m, n : \n";
cin>>m>>n;
cout<<"Value of m and n \n";
cout<<m<<", "<<n;
matrix A(m,n), B(m,n);
//Reading A from key
cout<<"Enter the values of elements one by one: ROWWISE\n";
for (i = 0; i< m; i++)
for (j=0; j < n; j++)
{
//cout<<"\n Please Enter (";cout<<i; cout<<","; cout<<j ;cout<<") th element \n";
cout<<"\n Please Enter ("<<i<<","<<j<<") th element \n";
cin>>value;
A.set_value(i,j,value);
}
cout<<"\n";
system("pause");
//cin.get();
return 0;
}
| |