aboutsummaryrefslogtreecommitdiff
path: root/Homework 8/MyStructures
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-03-11 19:50:23 -0700
committerYana Blashchishina <[email protected]>2024-03-11 19:50:23 -0700
commit2a72393c7c7f683c083153b75c578b4cc65f7ff0 (patch)
tree47e24b6016dd0383737214a819eda47fa561068c /Homework 8/MyStructures
parenterrors (diff)
downloadhomework-8-yanablash-2a72393c7c7f683c083153b75c578b4cc65f7ff0.tar.xz
homework-8-yanablash-2a72393c7c7f683c083153b75c578b4cc65f7ff0.zip
promptinput undefined
Diffstat (limited to 'Homework 8/MyStructures')
-rw-r--r--Homework 8/MyStructures/CharArrayHelpers.hpp12
-rw-r--r--Homework 8/MyStructures/Contact.hpp20
-rw-r--r--Homework 8/MyStructures/ContactList.hpp94
3 files changed, 107 insertions, 19 deletions
diff --git a/Homework 8/MyStructures/CharArrayHelpers.hpp b/Homework 8/MyStructures/CharArrayHelpers.hpp
index 62ecedd..570ecc7 100644
--- a/Homework 8/MyStructures/CharArrayHelpers.hpp
+++ b/Homework 8/MyStructures/CharArrayHelpers.hpp
@@ -1,4 +1,13 @@
+#ifndef CHAR_ARRAY_HELPERS_HPP
+#define CHAR_ARRAY_HELPERS_HPP
+
+
+#include <cstring>
#include <iostream>
+
+
+#define MAX_CHAR 100
+
inline bool OverwriteCharArray(char* dest, const char* source, size_t size = MAX_CHAR)
{
size_t newLength = strlen(source);
@@ -15,4 +24,5 @@ inline bool OverwriteCharArray(char* dest, const char* source, size_t size = MAX
return true;
-} \ No newline at end of file
+}
+#endif \ No newline at end of file
diff --git a/Homework 8/MyStructures/Contact.hpp b/Homework 8/MyStructures/Contact.hpp
index f0c632f..46f976a 100644
--- a/Homework 8/MyStructures/Contact.hpp
+++ b/Homework 8/MyStructures/Contact.hpp
@@ -102,13 +102,13 @@ namespace MyStructures
inline Contact::Contact(const Contact& copy) noexcept(false)
{
- OverwriteCharArray(firstName_, rhs.firstName_);
- OverwriteCharArray(lastName_, rhs.lastName_);
- OverwriteCharArray(streetAddress_, rhs.streetAddress_);
- OverwriteCharArray(city_, rhs.city_);
- OverwriteCharArray(state_, rhs.state_);
- OverwriteCharArray(email_, rhs.email_);
- zip_ = rhs.zip_;
+ OverwriteCharArray(firstName_, copy.firstName_);
+ OverwriteCharArray(lastName_, copy.lastName_);
+ OverwriteCharArray(streetAddress_, copy.streetAddress_);
+ OverwriteCharArray(city_, copy.city_);
+ OverwriteCharArray(state_, copy.state_);
+ OverwriteCharArray(email_, copy.email_);
+ zip_ = copy.zip_;
}
@@ -193,6 +193,11 @@ namespace MyStructures
}
+ inline const char* Contact::StreetAddress() const
+ {
+ return nullptr;
+ }
+
inline void Contact::StreetAddress(char* streetAddress)
{
streetAddress_ = streetAddress;
@@ -311,5 +316,6 @@ namespace MyStructures
memset(email_, 0, MAX_CHAR);
}
+
}
#endif \ No newline at end of file
diff --git a/Homework 8/MyStructures/ContactList.hpp b/Homework 8/MyStructures/ContactList.hpp
index 3824a0e..f897b5d 100644
--- a/Homework 8/MyStructures/ContactList.hpp
+++ b/Homework 8/MyStructures/ContactList.hpp
@@ -1,5 +1,5 @@
-#ifndef CONTACT_LIST
-#define CONTACT_LIST
+#ifndef CONTACT_LIST_HPP
+#define CONTACT_LIST_HPP
#include <algorithm>
@@ -66,7 +66,8 @@ namespace MyStructures
template<class C>
void ContactList<C>::ContactDelete(const size_t& elementNumber)
{
- contacts_[elementNumber].Delete();
+ size_t index = elementNumber;
+ contacts_[index].Delete();
}
template <class C>
@@ -80,6 +81,11 @@ namespace MyStructures
}
+ template<class C>
+ inline ContactList<C>::ContactList(size_t length)
+ {
+ }
+
template <class C>
ContactList<C>::ContactList(const C* contacts, const size_t& length, const size_t size)
{
@@ -151,6 +157,7 @@ namespace MyStructures
rhs.contacts_ = nullptr;
}
+ return *this;
}
@@ -265,25 +272,88 @@ namespace MyStructures
template <class C>
void ContactList<C>::RemoveFirst()
{
+ if (Empty()) return;
+ ContactDelete(0);
+ size_--;
}
template <class C>
void ContactList<C>::Extract(const C& data)
{
+ for (size_t i = 0; i < size_; ++i;)
+ {
+ if (contacts_[i] == data)
+ {
+ for (size_t j = i; j < size_ - 1; ++j)
+ {
+ }
+ ContactDelete(size_t - 1);
+ size_--;
+ return;
+ }
+ }
}
template<class C>
inline void ContactList<C>::InsertAfter(const C& data, const C& after)
{
-
+ for (size_t i = 0; i < size_; ++i) {
+ if (contacts_[i] == after) {
+ if (size_ >= length_) {
+
+ ContactList newContacts(length_ * 2);
+ newContacts.size_ = size_;
+ for (size_t j = 0; j < i + 1; ++j) {
+ newContacts.contacts_[j] = contacts_[j];
+ }
+ newContacts.contacts_[i + 1] = data;
+ for (size_t j = i + 2; j < newContacts.size_; ++j) {
+ newContacts.contacts_[j] = contacts_[j - 1];
+ }
+ *this = std::move(newContacts);
+ }
+ else {
+ for (size_t j = size_; j > i + 1; --j) {
+ contacts_[j] = contacts_[j - 1];
+ }
+ contacts_[i + 1] = data;
+ size_++;
+ }
+ return;
+ }
+ }
}
template<class C>
inline void ContactList<C>::InsertBefore(const C& data, const C& before)
{
-
+ for (size_t i = 0; i < size_; ++i) {
+ if (contacts_[i] == before) {
+ if (size_ >= length_) {
+
+ ContactList newContacts(length_ * 2);
+ newContacts.size_ = size_;
+ for (size_t j = 0; j < i; ++j) {
+ newContacts.contacts_[j] = contacts_[j];
+ }
+ newContacts.contacts_[i] = data;
+ for (size_t j = i + 1; j < newContacts.size_; ++j) {
+ newContacts.contacts_[j] = contacts_[j - 1];
+ }
+ *this = std::move(newContacts);
+ }
+ else {
+ for (size_t j = size_; j > i; --j) {
+ contacts_[j] = contacts_[j - 1];
+ }
+ contacts_[i] = data;
+ size_++;
+ }
+ return;
+ }
+ }
}
template <class C>
@@ -304,13 +374,13 @@ namespace MyStructures
template <class C>
C ContactList<C>::Last() const
{
- return contacts_[size_];
+ return contacts_[size_ - 1];
}
template <class C>
C& ContactList<C>::First()
{
- return contacts_[0];
+ return contacts_[size_ - 1];
}
template <class C>
@@ -320,15 +390,16 @@ namespace MyStructures
}
template<class C>
- inline C& ContactList<C>::operator[](const int& index)
+ C& ContactList<C>::operator[](const int& index)
{
if (index < 0 || index >= static_cast<int>(length_))
{
- cerr << "The index exceeds the array length" << endl;
+ Contact emptyContact;
+ std::cerr << "The index exceeds the array length" << endl;
return emptyContact;
}
- Contact contact = contacts_[index];
- return contact;
+
+ return contacts_[index];
}
template <class C>
@@ -392,6 +463,7 @@ namespace MyStructures
return storage;
}
+
};
#endif \ No newline at end of file