在线等!急!关于c++的matrix问题

QiaochuBryant 2014-03-25 04:13:36
Design a class Matrix that has the following private member variables:
int rows
int columns
double * values

Besides, it has the following public object functions:
A constructor Matrix(int rows, int column, double values[]), which initializes all elements in the matrix to the given values. Note that the given values are in one-dimensional, you need to fill then into the two-dimensional matrix correctly.
A copy constructor Matrix(const Matrix & matrix2).
A destructor.
A print function which prints each row of elements in a single line, with each element preceded with 4 spaces.
A function Matrix Matrix::concatenateRows(const Matrix & matrix2) const, which returns a matrix that is the concatenation of the rows of the invisible object parameter and matrix2.
A function Matrix Matrix::concatenateColumns(const Matrix & matrix2) const, which returns a matrix that is the concatenation of the columns of the invisible object parameter and matrix2.

EXAMPLE INPUT
4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
4 5
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

EXAMPLE OUTPUT
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

1 2 3 4 5 21 22 23 24 25
6 7 8 9 10 26 27 28 29 30
11 12 13 14 15 31 32 33 34 35
16 17 18 19 20 36 37 38 39 40

主程序
#include "source"

Matrix read() {
int rows;
int columns;
double values[1000];
cin >> rows >> columns;
for (int i = 0; i < rows * columns; ++ i) {
cin >> values[i];
}
Matrix matrix(rows, columns, values);
return matrix;
}

int main() {
Matrix matrix1 = read(); // calls copy constructor
Matrix matrix2 = read();

matrix1.concatenateRows(matrix2).print();
cout << endl;
matrix1.concatenateColumns(matrix2).print();
}

求class Matrix{}得答案程序
...全文
115 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
QiaochuBryant 2014-03-25
  • 打赏
  • 举报
回复
还有10分钟!!!
QiaochuBryant 2014-03-25
  • 打赏
  • 举报
回复
#include<iostream> using namespace std; class Matrix { private: int rows; int columns; double * values; public: Matrix(int row,int column,double value[]) { rows=row; columns=column; values=new double [rows*columns]; for(int m=0;m<rows*columns;m++) values[m]=value[m]; } Matrix(const Matrix & matrix) { rows=matrix.rows; columns=matrix.columns; values=new double [rows*columns]; for(int m=0;m<rows*columns;m++) values[m]=matrix.values[m]; } ~Matrix() { delete [] values; } void print() { for(int m=0;m<rows*columns;m++) { if((m+1)%columns==0) cout<<" "<<values[m]<<endl; else cout<<" "<<values[m]; } } Matrix concatenateRows(const Matrix & matrix2) { } Matrix concatenateColumns(const Matrix & matrix2) { } }; 到目前为止我打了这么多,求大神完善!
QiaochuBryant 2014-03-25
  • 打赏
  • 举报
回复
还剩20分钟了!!!

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧