herrDeng網內搜尋

自訂搜尋

Ads

2016年12月16日 星期五

Ex12 C++ Class Constructor and Destructor

10 則留言:

B10433092 提到...

public:
double term[row][col];

Matrix() {
cout << "Matrix() is called..." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called..." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}

Matrix(const Matrix& T) {
cout << "Matrix(double a[row][col]) is called..." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] =T.term[i][j];
}
}


~Matrix() {
cout << term[0][0];
cout << "DESTROYER......\n";
}

B10433011 提到...

{
public:
double term[row][col];
Matrix() {
cout << "Matrix() is called..." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called..." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T]) is called..." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << " DESTROYER...\n";
}
......

B10133186 提到...

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

a10433015 提到...

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];
Matrix() {
cout << "....." << endl;
memset(term, 0, sizeof(term)); }
Matrix(double a[row][col]) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
double& operator()(int i, int j) {
return term[i][j];
}
void print() {
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
~Matrix() {
cout << term[0][0] ;
cout << "DS" << endl;


}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j]= A(i,j)+B(i,j);
}
return C;
}
int main()
{
double a[3][3]= {{1,2,3}, {4,5,6},{7,8,9} };
double b[3][3]= { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

b10233127 提到...

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

b10433030 楊家睿 提到...

#include
#include
#include
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];
Matrix() {
cout << "....." << endl;
memset(term, 0, sizeof(term)); }
Matrix(double a[row][col]) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
double& operator()(int i, int j) {
return term[i][j];
}
void print() {
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
~Matrix() {
cout << term[0][0] ;
cout << "DS" << endl;


}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j]= A(i,j)+B(i,j);
}
return C;
}
int main()
{
double a[3][3]= {{1,2,3}, {4,5,6},{7,8,9} };
double b[3][3]= { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

b10433030 楊家睿 提到...

#include
#include
#include
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

b10233074 提到...

#include
#include
#include
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

B10233077 提到...

#include
#include
#include
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

B10233187 張郁柔 提到...

#include
#include
#include
using namespace std;
#define row 3
#define col 3
class Matrix
{
public:
double term[row][col];

Matrix() {
cout << "Matrix() is called...." << endl;
memset(term, 0, sizeof(term));
}

Matrix(double a[row][col]) {
cout << "Matrix(double a[row][col]) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = a[i][j];
}
}
Matrix(const Matrix& T) {
cout << "Matrix(const Matrix& T) is called....." << endl;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
term[i][j] = T.term[i][j];
}
}

~Matrix() {
cout << term[0][0];
cout << "DESTROTER....\n";
}

double& operator()(int i, int j) {
return term[i][j];
}
void print() {
cout << "----------------\n";
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) {
cout << term[i][j] <<"\t";
}
cout << endl;
}
}
};
Matrix& operator+(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
C.term[i][j] = A(i, j) + B(i, j);
}
return C;
}
int main()
{
double a[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
double b[3][3] = { { 4,5,6 },{ 7,8,9 },{ 1,2,3 } };
Matrix A(a), B(b);
A.print();
B.print();
Matrix C = A + B;
C.print();
system("Pause");
return 0;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章