aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Homework 6/Homework 6/Contacts.cpp75
-rw-r--r--Homework 6/Homework 6/Contacts.h18
-rw-r--r--Homework 6/Homework 6/program.cpp35
3 files changed, 92 insertions, 36 deletions
diff --git a/Homework 6/Homework 6/Contacts.cpp b/Homework 6/Homework 6/Contacts.cpp
index 284eeee..5fee9b0 100644
--- a/Homework 6/Homework 6/Contacts.cpp
+++ b/Homework 6/Homework 6/Contacts.cpp
@@ -1,50 +1,71 @@
#include <iostream>
#include "Contacts.h"
+#include <string>
using std::cout;
using std::cin;
using std::endl;
-Contact InputNewContacts()
+Contact InputNewContacts()
{
- Contact newContact = {};
+ Contact newContact = {};
- cout << "Name: ";
- cin >> newContact.Name;
+ cout << "Name: ";
+ cin >> newContact.Name;
+
+ cout << "Email: ";
+ cin >> newContact.Email;
+
+ cout << "Street Address: ";
+ cin >> newContact.StreetAddress;
- cout << "Email: ";
- cin >> newContact.Email;
+ cout << "City: ";
+ cin >> newContact.City;
- cout << "Street Address: ";
- cin >> newContact.StreetAddress;
+ cout << "State: ";
+ cin >> newContact.State;
- cout << "City: ";
- cin >> newContact.City;
+ cout << "Zip: ";
+ cin >> newContact.Zip;
- cout << "State: ";
- cin >> newContact.State;
-
- cout << "Zip: ";
- cin >> newContact.Zip;
-
- return newContact;
+ return newContact;
}
-void PrintContacts(Contact(&contacts)[10])
+void PrintContacts(Contact(&contacts)[10])
{
- for (auto &x : contacts)
- {
- cout << "\nName: " << x.Name << endl;
+ for (auto& x : contacts)
+ {
+ cout << "\nName: \n" << x.Name << endl;
+
+ cout << "\nEmail: \n" << x.Email << endl;
+
+ cout << "\nStreet Address: \n" << x.StreetAddress << endl;
- cout << "\nEmail: " << x.Email << endl;
+ cout << "\nCity: \n" << x.City << endl;
- cout << "\nStreet Address: " << x.StreetAddress << endl;
+ cout << "\nState: \n" << x.State << endl;
- cout << "\nCity: " << x.City << endl;
+ cout << "\nZip: \n" << x.Zip << endl;
+ }
+}
+
+void PrintContacts(Contact* contacts, int size)
+{
+ for (int i = 0; i < size; ++i) {
+ if (!contacts[i].name.empty()) {
+ std::cout << i << ": " << contacts[i].name << " - " << contacts[i].phone_number << std::endl;
+ }
+ }
+}
- cout << "\nState: " << x.State << endl;
+void deleteContact(Contact*& contacts, int& size, int index) {
+ if (index < 0 || index >= size) {
+ std::cerr << "Invalid index." << std::endl;
+ return;
+ }
- cout << "\nZip: " << x.Zip << endl;
- }
+ contacts[index].name = ""; // Mark as deleted
+ contacts[index].phone_number = "";
+ // Optionally, we could also decrease the array size and reallocate the memory
}
diff --git a/Homework 6/Homework 6/Contacts.h b/Homework 6/Homework 6/Contacts.h
index eadf34d..861a333 100644
--- a/Homework 6/Homework 6/Contacts.h
+++ b/Homework 6/Homework 6/Contacts.h
@@ -1,6 +1,15 @@
#ifndef CONTACTS_H
#define CONTACTS_H
+//
+//struct Contact
+//{
+// std::string name;
+// std::string phone_number;
+// // additional contact details can be added here
+//};
+
+
struct Contact
{
@@ -11,10 +20,17 @@ struct Contact
char State[25] = {};
int Zip = 0;
+ std::string name;
+ std::string phone_number;
+
};
Contact InputNewContacts();
void PrintContacts(Contact(&contacts)[10]);
-#endif // !CONTACTS_H
+void PrintContacts(Contact* contacts, int size);
+
+void deleteContact(Contact*& contacts, int& size, int index);
+
+#endif // !CONTACTS_H \ No newline at end of file
diff --git a/Homework 6/Homework 6/program.cpp b/Homework 6/Homework 6/program.cpp
index b2388e3..aa93fc2 100644
--- a/Homework 6/Homework 6/program.cpp
+++ b/Homework 6/Homework 6/program.cpp
@@ -14,27 +14,29 @@ using std::cin;
using std::endl;
-const int MAX = 10;
+const int MAX = 15;
+const int arraySize = 3;
-int main()
-{
-#include "Contacts.h"
-
+int main() {
Contact contacts[MAX] = {};
int numberOfContacts = 0;
char c = 'n';
do {
- system("cls");
+
cout << "A: Input New Contact\n";
+
cout << "B: Update Contact\n";
+
cout << "C: Print Contacts\n";
+
cout << "Press 'x' to Exit\n";
-
+
+
std::cin >> c;
- switch (c)
+ switch (c)
{
case 'A':
contacts[numberOfContacts] = InputNewContacts();
@@ -61,6 +63,23 @@ int main()
cout << "\nThat was a bad input\n";
}
} while (c != 'x');
+
+ int arraySize = 3, usedSize = 1;
+
+ Contact* contact = new Contact[arraySize];
+ // Add some contacts
+ // Example of adding contacts
+ // addContact(contacts, arraySize, usedSize, {"John Doe", "123-456-7890"});
+ // addContact(contacts, arraySize, usedSize, {"Jane Smith", "987-654-3210"});
+
+ // Example deletion process
+ // printContacts(contacts, usedSize);
+ // deleteContact(contacts, usedSize, 1);
+
+ // Cleanup
+ delete[] contact;
+
+
return 0;
}