⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplematrixtest.cpp

📁 自动生成矩阵 用法简单 用用就知道了
💻 CPP
字号:
#include <iostream>

using namespace std;
#include "Matrix.h"using namespace std;int main() {		Matrix a(2, 3);  		cout << "Matrix a is " << a.getr() << " rows " << endl;	cout << "Matrix a is " << a.getc() << " columns " << endl;		for(int r = 0; r < a.getr(); r++) {		for(int c = 0; c < a.getc(); c++) {			cout << "Element (" << r << ", " << c << ") = " << a.gete(r,c) << endl;		}	}	a.sete(1, 2, -5280);  	a.sete(0, 1, 123);    
	Matrix b = a;	a.sete(1, 2, 555); 	cout << "(1,2) of a = " << a.gete(1,2) << " [should be 555]" << endl;	cout << "(1,2) of b = " << b.gete(1,2) << " [should be -5280]" << endl;	Matrix c = a;	c.add(b);	Matrix d = c;	d.subtract(a);	if (d.equals(b)) {		cout << "Yay!  d = b!" << endl;	} else {		cout << "Uh-oh!  Something went wrong, d isn't b!" << endl;	}	Matrix e;	cout << "0x0 matrix e is " << e.getr() << " by " << e.getc() << endl;	if(!e.equals(d)) {		cout << "e and d are indeed different!" << endl;	} else {		cout << "Oh well, back to the drawing board...." << endl;	}		int matelems [] = {0, 1, -2, 3, 4, -5, 6, 7, -8, 9, 10, -11};	Matrix f(3, 4);	Matrix g(2, 6);		for (int i = 0; i < 12; ++i) {		f.sete(i / 4, i % 4, matelems[i]);		g.sete(i / 6, i % 6, matelems[i]);	}	if (f.equals(g) || g.equals(f)) {		cout << "You missed a spot. Are you checking dimensions!" << endl;    	} else {		cout << "Don't mind me, just some more testing." << endl;	}		Matrix h(2, 2);	for (int y = 0; y < 2; ++y) {		for (int x = 0; x < 2; ++x) {			h.setelem(x, y, g.gete(x, y));		}	}		if (g.equals(h) || h.equals(g)) {		cout << "Whoops. Try again." << endl;	} else {		cout << "Still doin' fine." << endl;	}		Matrix k = g;	k.setelem(0, 0, g.gete(0, 0) + 1);	if (k.equals(g)) {		cout << "You apparently have a loose definition of \"equals\"." << endl			<< "Why don't you try again?" << endl;	} else {		cout << "OK I'm done, I promise. Good job. " << endl;	}		return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -