Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Akhil ( 7 years ago )
#include <iostream>
#include "matrix.hpp"
int main() {
std::cout << "Akhil Jindal - Homework 5 | AMS-562 \n" << std::endl;
//--------------
// constructors and size querying - HAVING TROUBLE WITH COPY CONSTRUCTOR lns 32-37
//--------------
std::cout << "Using constructors and size querying:" << "\n";
// default constructor
std::cout << "Creating mat_1 using default constructor" << "\n";
ams562::matrix mat_1;
std::cout << "Number of rows of mat_1: " << mat_1.rows() << "\n";
std::cout << "Number of columns of mat_1: " << mat_1.cols() << "\n";
// explicit square constructor
std::cout << "Creating mat_2 using explicit squared constructor" << "\n";
ams562::matrix mat_2(5);
std::cout << "Number of rows of mat_2: " << mat_2.rows() << "\n";
std::cout << "Number of columns of mat_2: " << mat_2.cols() << "\n";
// constructor for general matrix
std::cout << "Creating mat_3 using general matrix constructor" << "\n";
ams562::matrix mat_3(10, 3);
std::cout << "Number of rows of mat_3: " << mat_3.rows() << "\n";
std::cout << "Number of columns of mat_3: " << mat_3.cols() << "\n";
//===HAVING TROUBLE WITH COPY CONTRUCTOR -- GETTING SEGMENTATION FAULT (MAYBE B/C NOT A DEEP COPY)===//
// copy constructor
std::cout << "Using copy constructor" << "\n";
// ams562::matrix mat_4(&mat_3);
// std::cout << "Number of rows of mat_4: " << mat_4.rows() << "\n";
// std::cout << "Number of columns of mat_4: " << mat_4.cols() << "\n";
//--------------
// data accessing
//--------------
std::cout << "Using data accessing functions:" << "\n";
// get reference
std::cout << "reference for mat_1: " << mat_1.operator()(0, 0) << "\n";
// get reference of a row by the underlying pointer
std::cout << "reference of a row for mat_1: " << mat_1.operator[](0) << "\n";
//--------------
// assignment - NEED TO INCLUDE OSSTREAM OPERATORS TO SHOW NEW MATRICIES lns 63, 68, 73, 83, 88
//--------------
// assignment
ams562::matrix mat_new=(mat_1);
std::cout << "mat_new is now equal to mat_1" << "\n";
std::cout << "Number of rows of mat_new: " << mat_new.rows() << "\n";
std::cout << "Number of columns of mat_new: " << mat_new.cols() << "\n";
// copy scalar into matrix --
mat_new.operator=(5);
std::cout << "mat_new is now equal scalar 5" << "\n";
// std::ostream operator
// plus assign
mat_new.operator+=(mat_new);
std::cout << "mat_new added to mat_new is: " << "\n";
// std::ostream operator
// plus assign a scalar
mat_new.operator+=(1);
std::cout << "mat_new added to scalar '1' is: " << "\n";
// std::ostream operator
// minus assign
mat_new.operator-=(mat_new);
std::cout << "mat_new minus to mat_new is: " << "\n";
// std::ostream operator
// minus assign a scalar
mat_new.operator-=(1);
std::cout << "mat_new minus to scalar '1' is: " << "\n";
// std::ostream operator
// scaling this my a factor
mat_new.operator*=(2);
std::cout << "mat_new scaling this my a factor '2' is: " << "\n";
// std::ostream operator
//--------------
// create row and column vectors - NEED TO INCLUDE OSSTREAM OPERATORS TO PRINT MATRICIES lns 98 and 110
// also, not really sure how to implement:
// std::vector<double> row(unsigned i) const;
// std::vector<double> col(unsigned j) const;
// my attempt was made on lns 101 and 104
//--------------
std::cout << "mat_1 matrix before creating a new row and column vectors: " << "\n";
//std::osstream operators for mat_1
// create a row vector given a row index:
std::vector<double> new_row(4);
// create a column vector given a row index:
std::vector<double> new_column(4);
// resizing:
mat_1.resize(4, 4);
std::cout << "mat_1 matrix after creating a new row and column vectors: " << "\n";
//std::osstream operators for mat_1
//--------------
// free functions
//--------------
//--------------
// read from file and write from file
//--------------
}
Revise this Paste
Parent: 101729