aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--My structures/Contact.hpp29
-rw-r--r--My structures/ContactList.hpp47
-rw-r--r--Project1/main.cpp8
3 files changed, 55 insertions, 29 deletions
diff --git a/My structures/Contact.hpp b/My structures/Contact.hpp
index 15c8317..7a230d7 100644
--- a/My structures/Contact.hpp
+++ b/My structures/Contact.hpp
@@ -2,6 +2,10 @@
#define CONTACT_HPP
#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
using namespace std;
namespace myStructures
@@ -12,6 +16,7 @@ namespace myStructures
public:
// constructors and destructors.
contact() = default;
+ contact(size_t a, string firstName, string lastName, string streetAddress, string city, string state, int zip, string email);
~contact() = default;
@@ -57,7 +62,7 @@ namespace myStructures
private:
size_t _a = 0;
// _a functions as delete bool. if a = 1, the slot is overwritten
- int _id;
+ /*int _id;*/
string _firstName;
string _lastName;
string _streetAddress;
@@ -72,6 +77,13 @@ namespace myStructures
// constructor defs for CLASS CONTACT
template <class C>
+ contact<C>::contact(size_t a, string firstName, string lastName, string streetAddress, string city, string state,
+ int zip, string email)
+ {
+
+ }
+
+ template <class C>
contact<C>::contact(const contact& copy)
{
*this = copy;
@@ -205,26 +217,15 @@ namespace myStructures
}
template <class C>
- size_t contact<C>::Get_id()
- {
- return _id;
- }
- template <class C>
- void contact<C>::Set_id(size_t id)
- {
- _id = id;
- }
-
- template <class C>
void contact<C>::print()
{
- cout << "Contact number: " << _id << endl;
+ //cout << "Contact number: " << _id << endl;
cout << "Full name: " << _firstName << " " << _lastName << endl;
+ cout << "Email: " << _email << endl;
cout << "Street Address: " << _streetAddress << endl;
cout << "City: " << _city << endl;
cout << "State: " << _state << endl;
cout << "Zip code: " << _zip << endl;
- cout << "Email: " << _email << endl;
}
}
diff --git a/My structures/ContactList.hpp b/My structures/ContactList.hpp
index 5287baa..2f55ac7 100644
--- a/My structures/ContactList.hpp
+++ b/My structures/ContactList.hpp
@@ -2,6 +2,12 @@
#define CONTACT_LIST_HPP
#include <algorithm>
+#include "Contact.hpp"
+#include <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
// NOTE: ALL USES OF TERM LIST REFER TO A SHORTHAND FORM OF ContactList, NOT AN ACTUAL LIST.
// ContactList's DATA SAVING IS IN AN ARRAY FORMAT
@@ -12,13 +18,14 @@ namespace myStructures
class ContactList
{
public:
- ContactList() = default;
ContactList(size_t length); //Creates contact list of this size
+ ContactList() = default;
+
ContactList(const CList* contacts, const size_t& length); //Makes a copy of another contact list
~ContactList();
ContactList(const ContactList& copy); //deep copy constructor
- ContactList& operator=(const ContactList& rhs); //deep copy assignment
+ ContactList& operator=(ContactList& rhs); //deep copy assignment
ContactList(ContactList&& move) noexcept; //reference(move) constructor
ContactList& operator=(ContactList&& rhs) noexcept; //reference(move) assignment
@@ -41,19 +48,20 @@ namespace myStructures
CList First() const; // returns first contact copy
CList& operator[](const int& index); // returns contact reference via [] overload
- CList operator[](const int& index) const; // returns contact copy via [] overload
+ CList operator[](int& index); // returns contact copy via [] overload
explicit operator bool() const; // overloads ContactList to return true/false as boolean
// operator
bool operator==(const ContactList<CList>& rhs) const; //if(newContactList == oldContactList)
bool Empty() const; // is the list empty?
-
+
+ CList* AllocateContactList(const size_t& length);
+
private:
CList* contacts_{ nullptr };
- size_t length_{ 0 }; // entire length of array
- size_t size_{ 0 }; // number of actual elements
-
- CList* AllocateContactList(const size_t& length);
+ size_t length_{ 10 }; // entire length of array
+ size_t size_{ 1 }; // number of actual elements
+
};
@@ -94,7 +102,7 @@ namespace myStructures
}
template <class CList>
- ContactList<CList>& ContactList<CList>::operator=(const ContactList& rhs)
+ ContactList<CList>& ContactList<CList>::operator=( ContactList& rhs)
{
if (this != &rhs)
{
@@ -138,7 +146,10 @@ namespace myStructures
template <class CList>
void ContactList<CList>::Print() const
{
-
+ for(auto i = 0u; i < length_; i++)
+ {
+ contacts_[i].print();
+ }
}
template <class CList>
@@ -154,8 +165,12 @@ namespace myStructures
// what ifs
// what if: end of the array is the beginning (empty)
+ if (size_ == 0)
+ {
+ index = 0;
+ }
// what if: in the body of the array
- if(size_ < length_)
+ if(size_ > 0 && size_ < length_)
{
index = size_;
}
@@ -166,8 +181,10 @@ namespace myStructures
if(size_ >= length_)
{
//increase size of array
- this = ContactList(contacts_, length_ * 2);
+ //*this = ContactList(contacts_, length_ * 2);
+ ContactList newContacts(contacts_, length_ * 2);
+ *this = newContacts;
}
@@ -248,13 +265,13 @@ namespace myStructures
template <class CList>
CList& ContactList<CList>::operator[](const int& index)
{
-
+ return contacts_[index];
}
template <class CList>
- CList ContactList<CList>::operator[](const int& index) const
+ CList ContactList<CList>::operator[](int& index)
{
-
+ return *this;
}
template <class CList>
diff --git a/Project1/main.cpp b/Project1/main.cpp
index b6938d3..9d22cd8 100644
--- a/Project1/main.cpp
+++ b/Project1/main.cpp
@@ -3,6 +3,7 @@
// class: CST116 at OIT
// reason: refactoring address book program that used .h and .cpp files with classes into a similar program using .hpp files (assignment 8)
#include "Contact.hpp"
+#include "ContactList.hpp"
#include <iostream>
using std::cin;
@@ -13,6 +14,7 @@ using namespace myStructures;
int main()
{
+
contact<int> contact00;
contact00.Set_firstName("Jimb");
contact00.Set_lastName("Bo");
@@ -49,6 +51,12 @@ int main()
contact03.Set_state("LT");
contact03.Set_zip(77677);
+ ContactList<contact<int>> addressBook;
+
+ addressBook.Append(contact00);
+
+ addressBook.Print();
+
return 0;
}