aboutsummaryrefslogtreecommitdiff
path: root/Homework8/MyStructures
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-03-09 13:30:44 -0800
committerrPatrickWarner <[email protected]>2024-03-09 13:30:44 -0800
commit61d278d69bba29cce0fec8dc0a75c528b1b95b71 (patch)
tree41ab75825e25885a5bb978db8bcfb3954e9b62fa /Homework8/MyStructures
parentmore changes/coming along (diff)
downloadhomework-8-reecepwarner-61d278d69bba29cce0fec8dc0a75c528b1b95b71.tar.xz
homework-8-reecepwarner-61d278d69bba29cce0fec8dc0a75c528b1b95b71.zip
some changes
Diffstat (limited to 'Homework8/MyStructures')
-rw-r--r--Homework8/MyStructures/ContactList.hpp31
-rw-r--r--Homework8/MyStructures/MenuHelper.hpp176
2 files changed, 112 insertions, 95 deletions
diff --git a/Homework8/MyStructures/ContactList.hpp b/Homework8/MyStructures/ContactList.hpp
index bc2240f..b324064 100644
--- a/Homework8/MyStructures/ContactList.hpp
+++ b/Homework8/MyStructures/ContactList.hpp
@@ -28,7 +28,7 @@ namespace MyStructures
void Prepend(const C& data); //add contact as the first item
void RemoveLast(); //remove last
void RemoveFirst(); //remove first
- void Extract(const C& data); //delete this data
+ void Extract(const C& data); //delete this data, slash collecting its data
void InsertAfter(const C& data, const C& after); //Insert contact data after 'after'
void InsertBefore(const C& data, const C& before); //Insert contact data before 'before'
void Clear(); //deletes all contacts, empties list, nothing left
@@ -209,11 +209,6 @@ namespace MyStructures
if (Empty())
{
- if (contacts_ == nullptr)
- {
-
- }
-
Append(data);
size_++;
return;
@@ -285,6 +280,10 @@ namespace MyStructures
template<class C>
void ContactList<C>::InsertAfter(const C& data, const C& after)
{
+ if (Empty()) return;
+
+ //if full, double size
+
}
template<class C>
void ContactList<C>::InsertBefore(const C& data, const C& before)
@@ -319,27 +318,41 @@ namespace MyStructures
template<class C>
inline C ContactList<C>::Last() const
{
- return C();
+ return contacts_[size_-1];
}
template<class C>
inline C& ContactList<C>::First()
{
+ return contacts_[0];
// TODO: insert return statement here
}
template<class C>
inline C ContactList<C>::First() const
{
- return C();
+ return contacts_[0];
}
template<class C>
inline C& ContactList<C>::operator[](const int& index)
{
+ if (index < 0 || index >= static_cast<int>(length_))
+ {
+ Contact EmptyContact;
+ cout << "The index exceeds the array length!!" << endl;
+ return EmptyContact;
+ }
+ return contacts_[index];
// TODO: insert return statement here
}
template<class C>
inline C ContactList<C>::operator[](const int& index) const
{
- return index;
+ if (index < 0 || index >= static_cast<int>(size_))
+ {
+ cout << "The index exceeds the array length!!" << endl;
+ return NULL;
+ }
+
+ return contacts_[index];
}
template<class C>
inline ContactList<C>::operator bool() const
diff --git a/Homework8/MyStructures/MenuHelper.hpp b/Homework8/MyStructures/MenuHelper.hpp
index f13656e..bb5a70d 100644
--- a/Homework8/MyStructures/MenuHelper.hpp
+++ b/Homework8/MyStructures/MenuHelper.hpp
@@ -4,64 +4,63 @@
#define _CRT_SECURE_NO_WARNINGS
#include "ContactList.hpp"
-using namespace MyStructures;
+namespace MyStructures
+{
+ void MainMenu();
+ Contact InputContact();
-void MainMenu();
+ char* PromptCharInput(const char* prompt, long long maxlen);
-Contact InputContact();
+ int InputInt(const char* prompt);
-char* PromptCharInput(const char* prompt, long long maxlen);
+ void PrintContact(ContactList<Contact>& contacts);
-int InputInt(const char* prompt);
+ Contact NewContact();
-void PrintContact(ContactList<Contact>& contacts);
+ void PrintContact(ContactList<Contact>& contacts);
-Contact NewContact();
+ bool OverWriteCharArray();
-void PrintContact(ContactList<Contact>& contacts);
+ void MainMenu()
+ {
+ char Options = '\0';
-bool OverWriteCharArray();
-void MainMenu()
-{
- char Options = '\0';
-
+ do
+ {
+ std::cout << "Welcome to the contacts menu\n"
+ << "1)Add New Contact\n"
+ << "2)Print All Contacts\n"
+ << "3)Delete Contact\n"
+ << "4)Exit\n";
+ std::cin >> Options;
+ switch (Options)
+ {
+ case('1'):
+
+ break;
+ case('2'):
+ //PrintContact(contacts);
+ break;
+ case('3'):
+ //contacts.DeleteContact("Which contact would you like to delete?", contacts);
+ break;
+ case('4'):
+ std::cout << "Thank you, have a great day!" << std::endl;
+
+ break;
+ default:
+ std::cout << "Invalid Input, Try Again!" << std::endl;
+ }
+
+ } while (Options != '4');
+ }
- do
+ Contact InputContact()
{
- std::cout << "Welcome to the contacts menu\n"
- << "1)Add New Contact\n"
- << "2)Print All Contacts\n"
- << "3)Delete Contact\n"
- << "4)Exit\n";
- std::cin >> Options;
- switch (Options)
- {
- case('1'):
-
- break;
- case('2'):
- //PrintContact(contacts);
- break;
- case('3'):
- //contacts.DeleteContact("Which contact would you like to delete?", contacts);
- break;
- case('4'):
- std::cout << "Thank you, have a great day!" << std::endl;
-
- break;
- default:
- std::cout << "Invalid Input, Try Again!" << std::endl;
- }
- } while (Options != '4');
-}
-Contact InputContact()
-{
-
-
Contact newContact;
newContact.SetFirstName(PromptCharInput("What is your first name?", 101));
@@ -77,69 +76,74 @@ Contact InputContact()
-}
+ }
-void PrintContact(ContactList<Contact>& contacts)
-{
- contacts.PrintList();
-}
+ void PrintContact(ContactList<Contact>& contacts)
+ {
+ contacts.PrintList();
+ }
-inline bool OverWriteCharArray()
-{
- return false;
-}
+ inline bool OverWriteCharArray()
+ {
+ return false;
+ }
-Contact NewContact()
-{
- Contact newContact;
+ Contact NewContact()
+ {
+ Contact newContact;
- return newContact;
-}
+ return newContact;
+ }
-char* PromptCharInput(const char* prompt, long long maxlen)
-{
- std::cout.flush();
- std::cout << prompt << std::endl;
-
- char* input = new char[maxlen];
- cin >> input;
- while (!std::cin)
+ char* PromptCharInput(const char* prompt, long long maxlen)
{
- cout << prompt << std::endl;
- cin.clear();
-
- cin.ignore(MAX_STREAM_SIZE, '\n');
- cin.get(input, MAX_STREAM_SIZE, '\n');
- }
-
- return input;
+ std::cout.flush();
+ std::cout << prompt << std::endl;
-}
-int InputInt(const char* prompt)
-{
- std::cout << prompt << std::endl;
+ char* input = new char[maxlen];
+ cin >> input;
+ while (!std::cin)
+ {
+ cout << prompt << std::endl;
+ cin.clear();
- std::cout.flush();
+ cin.ignore(MAX_STREAM_SIZE, '\n');
+ cin.get(input, MAX_STREAM_SIZE, '\n');
+ }
- int data = 0;
- std::cin >> data;
+ return input;
- while (!std::cin)
+ }
+ int InputInt(const char* prompt)
{
std::cout << prompt << std::endl;
- std::cin.clear();
- cin.ignore(MAX_STREAM_SIZE, '\n');
+ std::cout.flush();
+
+ int data = 0;
std::cin >> data;
+ while (!std::cin)
+ {
+ std::cout << prompt << std::endl;
+ std::cin.clear();
+
+ cin.ignore(MAX_STREAM_SIZE, '\n');
+ std::cin >> data;
+
+ }
+
+ return data;
}
- return data;
-}
+
+
+
+};