From 49ea46b506662a900dc7ef3de3907344ee95c7bf Mon Sep 17 00:00:00 2001 From: barnestr Date: Fri, 18 Mar 2022 10:45:12 -0500 Subject: [PATCH] it's friday --- Lab2/row.cpp | 14 ++++++++------ Lecture/Week2/dog.cpp | 5 +++++ Lecture/Week2/dog.h | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Lab2/row.cpp b/Lab2/row.cpp index e44dad5..972063b 100644 --- a/Lab2/row.cpp +++ b/Lab2/row.cpp @@ -43,16 +43,18 @@ Row::~Row(){ // access operator (const) double Row::operator[](unsigned int column) const{ - //finish - double result; - return result; + if (column >= length) { + throw(out_of_range("Column is out of range")); + } + return row_data[column]; } // access operator (non-const) double& Row::operator[](unsigned int column){ - //finish - double result; - return result; + if (column >= length) { + throw(out_of_range("Column is out of range")); + } + return row_data[column]; } // assignment operator diff --git a/Lecture/Week2/dog.cpp b/Lecture/Week2/dog.cpp index ab3302c..4e202f0 100644 --- a/Lecture/Week2/dog.cpp +++ b/Lecture/Week2/dog.cpp @@ -58,6 +58,11 @@ char& Dog::operator[](int index){ return name[index]; } +Dog Dog::puppy(int namelength, char * name){ + Dog p(0, namelength, name); + return p; +} + ostream& operator<<(ostream& os, const Dog& d){ for(int i = 0; i< d.namelength; i++) { os << d[i]; diff --git a/Lecture/Week2/dog.h b/Lecture/Week2/dog.h index 9111819..e19a78a 100644 --- a/Lecture/Week2/dog.h +++ b/Lecture/Week2/dog.h @@ -3,6 +3,8 @@ using namespace std; class Dog { public: Dog(int age, int namelength, char * name); + // has to be dog object, not reference + static Dog Dog::puppy(int namelength, char *name); Dog(const Dog& from); ~Dog(); Dog& operator=(const Dog& rhs);