aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-02-26 20:52:30 -0800
committerYana Blashchishina <[email protected]>2024-02-26 20:52:30 -0800
commit4d8e73c8ce4d94828f9f492ac7e51c686e7783ab (patch)
tree7d329dc4eb031f8367516f5d734727db67f57d6e
parentinit (diff)
downloadhomework-7-yanablash-4d8e73c8ce4d94828f9f492ac7e51c686e7783ab.tar.xz
homework-7-yanablash-4d8e73c8ce4d94828f9f492ac7e51c686e7783ab.zip
forgot to commit, almost done
-rw-r--r--Homework7/Homework7/ContactList.cpp66
-rw-r--r--Homework7/Homework7/ContactList.h16
-rw-r--r--Homework7/Homework7/contact.h62
-rw-r--r--Homework7/Homework7/contacts.cpp96
-rw-r--r--Homework7/Homework7/main.cpp40
5 files changed, 156 insertions, 124 deletions
diff --git a/Homework7/Homework7/ContactList.cpp b/Homework7/Homework7/ContactList.cpp
index 69691b3..b934182 100644
--- a/Homework7/Homework7/ContactList.cpp
+++ b/Homework7/Homework7/ContactList.cpp
@@ -1,7 +1,69 @@
#include "ContactList.h"
-Contact::ContactList()
+
+
+ContactList::ContactList(const size_t& size)
+{
+
+ length_ = size;
+ contacts_ = AllocateContactList(size);
+}
+
+ContactList::~ContactList()
+{
+ delete[]contacts_;
+ contacts_ = nullptr;
+}
+
+void ContactList::DeleteContact(Contact& contact)
+{
+ for (size_t i = 0; i < length_; ++i) {
+ if (&contact == &contacts_[i]) {
+
+ delete& contacts_[i];
+
+ return;
+ }
+ }
+}
+
+void ContactList::CopyList(const Contact* contacts, const size_t& length)
+{
+ length_ = length;
+ contacts_ = AllocateContactList(length);
+
+ for (auto i = 0u; i < length; ++i)
+ {
+ contacts_[i] = contacts[i];
+ }
+}
+
+void ContactList::AddContact(const Contact& contact)
+{
+ contacts_[size_++] = contact;
+}
+
+void ContactList::Print() const
+{
+ for (auto i = 0u; i < size_; ++i)
+ {
+ contacts_[i].Print();
+ }
+}
+
+size_t ContactList::GetSize() const
+{
+ return size_;
+}
+
+Contact* ContactList::AllocateContactList(const size_t& size)
{
+ Contact* contacts = nullptr;
+
+ length_ = size;
+
+ contacts = new Contact[size];
+ return contacts;
-} \ No newline at end of file
+}
diff --git a/Homework7/Homework7/ContactList.h b/Homework7/Homework7/ContactList.h
index afbdbe3..cf0b711 100644
--- a/Homework7/Homework7/ContactList.h
+++ b/Homework7/Homework7/ContactList.h
@@ -3,30 +3,26 @@
#include "contact.h"
-class Contact {
+class ContactList {
public:
ContactList() = default;
+ ContactList(const size_t& size);
~ContactList();
- void DeleteContact(Contact& contact);
-
- void CopyList(const Contact* contacts, const size_t& size);
+ void DeleteContact(Contact& contact);
+ void CopyList(const Contact* contacts, const size_t& length);
void AddContact(const Contact& contact);
-
void Print() const;
-
- size_t Size() const;
+ size_t GetSize() const;
private:
Contact* contacts_{ nullptr };
-
size_t length_{ 0 };
-
size_t size_{ 0 };
-
+ Contact* AllocateContactList(const size_t& size);
};
diff --git a/Homework7/Homework7/contact.h b/Homework7/Homework7/contact.h
index 1515461..a32cfa9 100644
--- a/Homework7/Homework7/contact.h
+++ b/Homework7/Homework7/contact.h
@@ -3,53 +3,43 @@
class Contact {
-public:
- Contact();
- Contact(const char* firstName, const char* lastName, const char* streetAddress, const char* city, const char* state, int zip, const char* email);
-
- ~Contact();
-
-
- void Print();
-
-
-
- const char* GetFirstName();
- void SetFirstName(const char* firstName);
-
- const char* GetLastName();
- void SetLastName(const char* lastName);
-
- const char* GetStreetAddress();
- void SetStreetAddress(const char* streetAddress);
-
- const char* GetCity();
- void SetCity(const char* city);
+private:
+ char* _firstName{};
+ char* _lastName{};
+ char* _streetAddress{};
+ char* _city{};
+ char* _state{};
+ int _zip;
+ char* _email{};
- const char* GetState();
- void SetState(const char* state);
+public:
+ Contact();
+ ~Contact();
- int GetZip();
- void SetZip(int zip);
+ const char* getFirstName();
+ void setFirstName(const char* firstName);
+ const char* getLastName();
+ void setLastName(const char* lastName);
- const char* GetEmail();
- void SetEmail(const char* email);
+ const char* getStreetAddress();
+ void setStreetAddress(const char* streetAddress);
+ const char* getCity();
+ void setCity(const char* city);
+ const char* getState();
+ void setState(const char* state);
-private:
+ const int getZip();
+ void setZip(int zip);
+ const char* getEmail();
+ void setEmail(const char* email);
- const char* _firstName{ };
- const char* _lastName{ };
- const char* _streetAddress{ };
- const char* _city{ };
- const char* _state{ };
- int _zip{ 0 };
- const char* _email{ };
+ void Print() const;
diff --git a/Homework7/Homework7/contacts.cpp b/Homework7/Homework7/contacts.cpp
index 54a9de6..ba2b08c 100644
--- a/Homework7/Homework7/contacts.cpp
+++ b/Homework7/Homework7/contacts.cpp
@@ -1,89 +1,81 @@
-#include "contactList.h"
+#include "contact.h"
#include <iostream>
-Contact::Contact() { }
+Contact::Contact() {
-Contact::Contact(const char* firstName, const char* lastName, const char* streetAddress, const char* city, const char* state, int zip, const char* email) {
- _firstName = firstName;
- _lastName = lastName;
- _streetAddress = streetAddress;
- _city = city;
- _state = state;
- _zip = zip;
- _email = email;
}
-Contact::~Contact() { }
+Contact::~Contact() {
+}
-void Contact::Print() {
- std::cout << "First Name: " << _firstName << std::endl;
- std::cout << "Last Name: " << _lastName << std::endl;
- std::cout << "Street Address: " << _streetAddress << std::endl;
- std::cout << "City: " << _city << std::endl;
- std::cout << "State: " << _state << std::endl;
- std::cout << "Zip: " << _zip << std::endl;
- std::cout << "Email: " << _email << std::endl;
+const char* Contact::getFirstName() {
+ return _firstName;
}
+void Contact::setFirstName(const char* firstName) {
+ _firstName = const_cast<char*>(firstName);
+}
+const char* Contact::getLastName() {
+ return _lastName;
+}
+void Contact::setLastName(const char* lastName) {
-void Contact::SetFirstName(const char* firstName) {
- _firstName = firstName;
+ _lastName = const_cast<char*>(lastName);
}
-const char* Contact::GetFirstName() {
- return _firstName;
+const char* Contact::getStreetAddress() {
+ return _streetAddress;
}
-void Contact::SetLastName(const char* lastName) {
- _lastName = lastName;
+void Contact::setStreetAddress(const char* streetAddress) {
+ _streetAddress = const_cast<char*>(streetAddress);
}
-const char* Contact::GetLastName() {
- return _lastName;
+const char* Contact::getCity() {
+ return _city;
}
-
-
-const char* Contact::GetStreetAddress() {
- return _streetAddress;
+void Contact::setCity(const char* city) {
+ _city = const_cast<char*>(city);
}
-void Contact::SetStreetAddress(const char* streetAddress) {
- _streetAddress = streetAddress;
+const char* Contact::getState() {
+ return _state;
}
-const char* Contact::GetCity() {
- return _city;
-}
-void Contact::SetCity(const char* city) {
- _city = city;
+void Contact::setState(const char* state) {
+ _state = const_cast<char*>(state);
}
-const char* Contact::GetState() {
- return _state;
-}
-void Contact::SetState(const char* state) {
- _state = state;
-}
-int Contact::GetZip() {
- return _zip;
+const int Contact::getZip() {
+ return _zip;
}
-void Contact::SetZip(int zip) {
- _zip = zip;
+void Contact::setZip(int zip) {
+ _zip = zip;
}
-const char* Contact::GetEmail() {
- return _email;
+const char* Contact::getEmail() {
+ return _email;
}
-void Contact::SetEmail(const char* email) {
- _email = email;
+void Contact::setEmail(const char* email) {
+ _email = const_cast<char*>(email);
}
+
+void Contact::Print() const {
+ std::cout << "First Name: " << _firstName << std::endl;
+ std::cout << "Last Name: " << _lastName << std::endl;
+ std::cout << "Street Address: " << _streetAddress << std::endl;
+ std::cout << "City: " << _city << std::endl;
+ std::cout << "State: " << _state << std::endl;
+ std::cout << "ZIP: " << _zip << std::endl;
+ std::cout << "Email: " << _email << std::endl;
+} \ No newline at end of file
diff --git a/Homework7/Homework7/main.cpp b/Homework7/Homework7/main.cpp
index 34127e7..b183ab2 100644
--- a/Homework7/Homework7/main.cpp
+++ b/Homework7/Homework7/main.cpp
@@ -3,41 +3,33 @@
// Class: CST116
// Assignment: Homework 7
-#include "contactList.h"
+#include "ContactList.h"
#include<iostream>
int main() {
- Contact newContact;
+ Contact myContact;
- std::cout << newContact.GetFirstName();
+ myContact.setFirstName("Yana");
+ myContact.setLastName("Blashchishina");
+ myContact.setStreetAddress("123 seasame street");
+ myContact.setCity("Not Portland");
+ myContact.setState("OR");
+ myContact.setZip(92312);
+ myContact.setEmail("meow.com");
+ myContact.Print();
- newContact.GetFirstName();
- newContact.SetFirstName("Yana");
- newContact.GetLastName();
- newContact.SetLastName("Blashchishina");
+
- newContact.GetStreetAddress();
- newContact.SetStreetAddress("123 Sesame Street");
-
- newContact.GetCity();
- newContact.SetCity("Not Portland");
-
- newContact.GetState();
- newContact.SetState("Not California");
-
- newContact.GetZip();
- newContact.SetZip(97089);
-
-
- newContact.GetEmail();
- newContact.SetEmail("meow.gmail.com");
-
- newContact.Print();
+ ContactList contacts(3);
+ contacts.AddContact(myContact);
+
+
+ contacts.Print();
return 0;