YTU 2959: 代码填充--雨昕学矩阵

网友投稿 323 2022-08-28

YTU 2959: 代码填充--雨昕学矩阵

2959: 代码填充--雨昕学矩阵

时间限制: 1 Sec   内存限制: 128 MB

提交: 112

解决: 50

题目描述

雨昕开始学矩阵了。矩阵数乘规则:一个数k乘一个矩阵A还是一个矩阵,行数、列数不变,矩阵的所有元素都乘以k。现在老师要求雨昕写出一个数乘以一个2*3的矩阵的完整程序。请帮助雨昕。

注:本题只需要提交填写部分的代码,请按照C++方式提交。

#include using namespace std; class Matrix { public: Matrix(); friend Matrix operator*(int k,Matrix &); friend ostream& operator<<(ostream&,Matrix&); friend istream& operator>>(istream&,Matrix&); private: int mat[2][3]; }; Matrix::Matrix() { for(int i=0; i<2; i++) for(int j=0; j<3; j++) mat[i][j]=0; } ostream& operator<<(ostream &out,Matrix &mat) { for (int i=0; i<2; i++) { for(int j=0; j<3; j++) { if(j>0) out<<" "; out<>k; cin>>mat1; mat2=k*mat1; cout<

输入

第一行是一个整数k 第二行开始是一个2*3的矩阵

输出

矩阵的数乘结果

样例输入

21 2 34 5 6

样例输出

2 4 68 10 12

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include using namespace std;class Matrix{public: Matrix(); friend Matrix operator*(int k,Matrix &); friend ostream& operator<<(ostream&,Matrix&); friend istream& operator>>(istream&,Matrix&);private: int mat[2][3];};Matrix::Matrix(){ for(int i=0; i<2; i++) for(int j=0; j<3; j++) mat[i][j]=0;}ostream& operator<<(ostream &out,Matrix &mat){ for (int i=0; i<2; i++) { for(int j=0; j<3; j++) { if(j>0) out<<" "; out<>(istream &a,Matrix &b){ for(int i=0; i<2; i++) { for(int j=0; j<3; j++) cin>>b.mat[i][j]; }}Matrix operator*(int k,Matrix &p){ for(int i=0; i<2; i++) { for(int j=0; j<3; j++) p.mat[i][j]*=k; } return p;}int main(){ Matrix mat1,mat2; int k; cin>>k; cin>>mat1; mat2=k*mat1; cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:新媒体营销手段大全来咯来咯!
下一篇:POJ 2017:Speed Limit
相关文章

 发表评论

暂时没有评论,来抢沙发吧~