aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-03-09 15:41:30 -0800
committerConnor McDowell <[email protected]>2024-03-09 15:41:30 -0800
commit37a384916816c745d1eece6369d76b366af1a48a (patch)
treec3f939b72300a7b348a4be3e265247e19737e3a2
parentfilling in classes (diff)
downloadhomework-8-connormcdowell275-37a384916816c745d1eece6369d76b366af1a48a.tar.xz
homework-8-connormcdowell275-37a384916816c745d1eece6369d76b366af1a48a.zip
test classes created
-rw-r--r--My structures/ContactList.hpp24
-rw-r--r--Project1/main.cpp34
2 files changed, 55 insertions, 3 deletions
diff --git a/My structures/ContactList.hpp b/My structures/ContactList.hpp
index ed3dde0..5287baa 100644
--- a/My structures/ContactList.hpp
+++ b/My structures/ContactList.hpp
@@ -150,15 +150,33 @@ namespace myStructures
template <class CList>
void ContactList<CList>::Append(const CList& data)
{
- // Add to the end of the array
-
- contacts_[size_ - 1] = data;
+ size_t index = 0;
// what ifs
// what if: end of the array is the beginning (empty)
// what if: in the body of the array
+ if(size_ < length_)
+ {
+ index = size_;
+ }
// what if: end of the array
+ //length_ == 10;
+ //size_ == 10;
+ // contacts_[10] is out of bounds
+ if(size_ >= length_)
+ {
+ //increase size of array
+ this = ContactList(contacts_, length_ * 2);
+
+ }
+
+
// what if: the array is full
+
+
+ // Add to the end of the array
+ contacts_[index] = data;
+ size_++;
}
template <class CList>
diff --git a/Project1/main.cpp b/Project1/main.cpp
index e4e969a..b6938d3 100644
--- a/Project1/main.cpp
+++ b/Project1/main.cpp
@@ -13,7 +13,41 @@ using namespace myStructures;
int main()
{
+ contact<int> contact00;
+ contact00.Set_firstName("Jimb");
+ contact00.Set_lastName("Bo");
+ contact00.Set_email("[email protected]");
+ contact00.Set_streetAddress("Jimbbo Street");
+ contact00.Set_city("Lazy Town");
+ contact00.Set_state("LT");
+ contact00.Set_zip(696969);
+ contact<int> contact01;
+ contact01.Set_firstName("Tim");
+ contact01.Set_lastName("Bo");
+ contact01.Set_email("[email protected]");
+ contact01.Set_streetAddress("Immothy Way");
+ contact01.Set_city("Lazy town");
+ contact01.Set_state("LT");
+ contact01.Set_zip(42069);
+
+ contact<int> contact02;
+ contact02.Set_firstName("Rim");
+ contact02.Set_lastName("Bo");
+ contact02.Set_email("[email protected]");
+ contact02.Set_streetAddress("Rim Road");
+ contact02.Set_city("Lazy Town");
+ contact02.Set_state("LT");
+ contact02.Set_zip(55555);
+
+ contact<int> contact03;
+ contact03.Set_firstName("Bimb");
+ contact03.Set_lastName("Bo");
+ contact03.Set_email("[email protected]");
+ contact03.Set_streetAddress("Normal Street");
+ contact03.Set_city("Lazy Town");
+ contact03.Set_state("LT");
+ contact03.Set_zip(77677);
return 0;
}