首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的Matrix是一个用于表示矩阵的类。其成员函数transpose的功能是实现矩阵的转置运算。 将矩阵A的行列互换,所得到的矩阵称为A的转置,记做AT。 例如,若有3×3矩阵
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的Matrix是一个用于表示矩阵的类。其成员函数transpose的功能是实现矩阵的转置运算。 将矩阵A的行列互换,所得到的矩阵称为A的转置,记做AT。 例如,若有3×3矩阵
admin
2015-06-27
20
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的Matrix是一个用于表示矩阵的类。其成员函数transpose的功能是实现矩阵的转置运算。
将矩阵A的行列互换,所得到的矩阵称为A的转置,记做A
T
。
例如,若有3×3矩阵
请编写成员函数transpose,以实现矩阵转置功能。
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//Matrix.h
#include
#include
usingnamespacestd;
constintM=18;
constintN=18;
classMatrix{
intarray[M][N];
public:
Matrix(){}
intgetElement(inti,intj)const{
returnarray
[j];)
voidsetElement(inti,intj,int
value){array
[j]=value;)
voidtranspose();
voidshow(constchar。S)const
{
cout<
for(inti=0;i
cout<
for(intj=0;j
cout<
[j];
}
}
};
voidreadFromFile(constchar*,Matrix&);
voidwriteToFile(char*,constMatrix&);
//main.cpp
#include
#include"Matrix.h"
voidreadFromFile(constchar*
filename,Matrix&m)
{
ifstreaminfile(filename);
if(!infile){
cerr<<"无法读取输入数据文件!\n";
return;
}
intd;
for(inti=0;i
for(intj=0;j
infile>>d;
m.setElement(i,j,d);
}
}
voidMatrix::transpose()
{
//********333********
//********666********
}
intmain()
{
Matrixm;
readFromFile("",m);
m.show("Beforetranspose:");
m.transpose();
m.show("Aftertranspose:");
writeToFile("",m);
return0;
}
选项
答案
for(int i = 0; i < M; i++) for(int j = 0; j < i; j++) { int temp = array[i][j]; array[i][j] = array[j][i]; array[j][i] = temp; }
解析
主要考查考生对二维数组的掌握,程序用二维数组表示矩阵,编写矩阵转置功能。要实现矩阵的转置,只要使矩阵中的元素array
[j]与array[j]
交换,程序使用循环语句遍历矩阵元素,外层循环用于控制行下标,内层循环用于控制列下标。
转载请注明原文地址:https://jikaoti.com/ti/ngXiFFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
简述隋唐科举制度的基本内容和历史作用。(苏州大学2004年中国古代史真题)
简述隋唐三省六部制的职能与作用。(西北大学2005年中国古代史真题)
如果依据统计方法的功能进行分类的话,统计学可以分为()
设X~N(0,σ2),则服从自由度为n-1的t分布的随机变量是()
简述大学服务社会功能的形成与发展。
学校教育对人的发展起着主要作用。
教育的个体社会化功能,不包括
“到2020年,基本实现教育现代化,基本形成学习型社会,进入人力资源强国行列。”出自
简述法律关系的定义和特征。
随机试题
下列汉字,笔画之间的组合关系属于相离关系的是()
请简述配送中心规划的内容。
衡量组织兴奋性的指标是
患者,男,62岁。左上5、6、7及右上4、5、6、7缺失,可摘局部义齿初戴后1个月,咀嚼时常咬颊黏膜,下颌舌侧第一磨牙至磨牙后垫区压痛,来院复诊。咬颊黏膜可能原因
含马兜铃酸而致肾衰的中药有()
图示外伸梁,A截面的剪力为()。
下列说法中正确的有()。
Hardly______thephone______Iwastoldthatthehotelhadbeenbookedfull.
•ReadthearticlebelowaboutproductivitygrowthofthenewentrantsinEU.•ChoosethebestwordtofilleachgapfromA,B,C
WhatcausedsomeHamasmemberstobearrested?
最新回复
(
0
)