From 07ed0ce879e8c12a9435da00a938095651d7bfa5 Mon Sep 17 00:00:00 2001 From: barnestr Date: Wed, 16 Mar 2022 09:57:09 -0500 Subject: [PATCH] lab 2 start --- Lab2/lab2 | Bin 0 -> 18376 bytes Lab2/main.cpp | 29 +++++++++++++++++++++ Lab2/makefile | 25 +++++++++++++++++++ Lab2/row.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ Lab2/row.h | 51 +++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100755 Lab2/lab2 create mode 100644 Lab2/main.cpp create mode 100644 Lab2/makefile create mode 100644 Lab2/row.cpp create mode 100644 Lab2/row.h diff --git a/Lab2/lab2 b/Lab2/lab2 new file mode 100755 index 0000000000000000000000000000000000000000..13132d0563ccba5e25a68edc7d217111afe0fce0 GIT binary patch literal 18376 zcmeHPe{fXCec!v2K-h2+HaHk+bH+{$c6CSs6k%KO>BqrSEwC&Jo5aD7)7?orBHd~3 z-hrSdmPf?pqADe^>oQ4P+{E?JPFfSsBqeT5gdrd|X+}kyGIM z`R?2A)4S81r{jMznYm?j-~ImF?|ygR?tA;*m&g3A8=MY@;NlXW7KBY!m=vF4lyL>P zPt=KP@w;5yEam_&ku?0|fxS+X&alixg$t1M4l8~x{39jDkUb7m-PCTxL)Lo$dMac};-dkFy*ZxO@8&un*{ zJ+?FQcW>;tRWChMdebjHB)`cAvPUvhNS?z<_3Q9Qe6wF)aXMg`XjI7lMEEEDiKpi} z7ayG8B#C)`#zA8pJNw}R^bG~*1{}#}=bZxb|6G9n>jLz<3fNy!fc}#Lb||JE{No|2P_00bXu-8ia*nsd%=*qgj$EOHXIH0wFEni>gr%`Ag&wnK*UJ21pWSY(AIPX5|N-DOBnHRpueS4@2t}O z9kuWRs%wIgsI+F(MPdmZqT#hI(TLGp?cZs&(zcjmLJuxsV=+#{;|d zXn2?27moHAy|Tfz!C2A|`j+UfNHnCkhZD(u#8GMnjPPItJc)Ei$lpE0!@>|$!_gl= z2!JPyQ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jTjze!^%Q#`>*Ec^Z61(b-Ql0Pi@)DFM-gR49#sS z{JhQoPX*6YlRGp2*pIitD90b`^Lf=6KGvtgawax|GyMZF_}U^FKGzyo`W#rE->k>; z@E~-kPuxDAe~qsuYXbjcOLk#>hL^#%>kFTfuQFk;LK(0g!%`^Q_4&E4SLqjuAKSYY z%4CcEAM%-;A*Juj8Gpq#h44%NKLfR|#4S4O-)>RN3dvHj!<;50|FAO1>(EW0(pen$ ooBKuA7yB+1)z5|XX61J|6Q0{;SvuCpr~l5UO^F+G6mn4Uf1U}@VgLXD literal 0 HcmV?d00001 diff --git a/Lab2/main.cpp b/Lab2/main.cpp new file mode 100644 index 0000000..7f4c05e --- /dev/null +++ b/Lab2/main.cpp @@ -0,0 +1,29 @@ +/** + * @file main.cpp + * @author Trevor Barnes (barnestr@msoe.edu) + * @brief + * @version 1.0 + * @date 2022-03-22 + * + * @copyright Copyright (c) 2022 + * + */ +#include +#include +#include "row.h" +using namespace std; + +int main() { + int length; + cout << "Enter desired length for row matrix:" << endl; + cin >> length; + Row row1(length); + for(int i = 0; i < length; i++){ + cout << "before seg fault" << endl; + // Will use access operator instead + cout << row1.row_data[i] << " "; + } + cout << endl; + + return 0; +} diff --git a/Lab2/makefile b/Lab2/makefile new file mode 100644 index 0000000..d048656 --- /dev/null +++ b/Lab2/makefile @@ -0,0 +1,25 @@ +# lab2 Makefile + +CC = g++ +CFLAGS = -c -MMD +LFLAGS = +# Change w/ every new project +SOURCES = main.cpp row.cpp +OBJECTS = $(SOURCES:.cpp=.o) +# Change w/ every new project +EXECUTABLE = lab2 + +all: $(EXECUTABLE) $(SOURCES) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(LFLAGS) -o $@ $(OBJECTS) + +-include *.d + +%.o:%.cpp + $(CC) $(CFLAGS) $< + +clean: + rm -f $(EXECUTABLE) + rm -f $(OBJECTS) + rm -f *.d \ No newline at end of file diff --git a/Lab2/row.cpp b/Lab2/row.cpp new file mode 100644 index 0000000..e44dad5 --- /dev/null +++ b/Lab2/row.cpp @@ -0,0 +1,68 @@ +#include +#include "row.h" +using namespace std; + +// parameterized constructor +Row::Row(unsigned int length){ + cout << "-Row Constructor-" << endl; // TODO: temp + // Set matrix length private variable to passed in length + this->length = length; + // Create new array in heap for row_data + this->row_data = new double[length]; + // Clear all values in new array to 0 + for(int i = 0; i < length; i++) { + cout << "-Row Constructor-" << endl; // TODO: temp + this->row_data[i] = 0.0; + } + // finish +} + +// copy constructor +Row::Row(const Row& from){ + cout << "-Row Copy Constructor-" << endl; // TODO: temp + // New row matrix gets length from previous matrix + this->length = from.length; + // Create new array in heap with new length + this->row_data - new double[this->length]; + // Copy all row_data values over to new array + for(int i = 0; i < this->length; i ++) { + this->row_data[i] = from.row_data[i]; + } + // finish +} + +// destructor +Row::~Row(){ + cout << "-Row Destructor-" << endl; // TODO: temp + // Check for valid length then free the heap memory + if(this->length > 0 ) { + delete[] row_data; + } + //finish +} + +// access operator (const) +double Row::operator[](unsigned int column) const{ + //finish + double result; + return result; +} + +// access operator (non-const) +double& Row::operator[](unsigned int column){ + //finish + double result; + return result; +} + +// assignment operator +Row& Row::operator= (const Row& rhs){ + //finish + Row result(1); + return result; +} + +// clear row data +void Row::clear(){ + //finish +} \ No newline at end of file diff --git a/Lab2/row.h b/Lab2/row.h new file mode 100644 index 0000000..a765ede --- /dev/null +++ b/Lab2/row.h @@ -0,0 +1,51 @@ +#ifndef row_h +#define row_h +class Row{ + public: + /* Parameterized constructor + * Takes in length and creates a row matrix with values cleared + * to zero + */ + Row(unsigned int length); + + /* Copy constructor + * Create a new row matrix with the same size and values as the + * from matrix + */ + Row(const Row& from); + + /* Destructor + * Correctly delete any heap memory + */ + ~Row(); + + /* Access operator (const version) + * Allow access to row matrix data + * Should return an exception if column is too large + */ + double operator[](unsigned int column) const; + + /* Access operator (non const version) + * Allow access to row matrix data + * Should return an exception if column is too large + */ + double& operator[] (unsigned int column); + + /* Assignment operator + * 1. Check if two sides are the same object + * 2. Delete the current row matrix + * 3. Create a new row matrix with the same size and values as + * the rhs matrix + */ + Row& operator= (const Row& rhs); + + /* Clear all data values to zero + */ + void clear(); + private: + // Row matrix data + double * row_data; + // Size of row matrix + unsigned int length; +}; +#endif