aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraquelc <[email protected]>2024-03-16 20:45:05 -0700
committerraquelc <[email protected]>2024-03-16 20:45:05 -0700
commit9ef3c244c913934759a6cb5dde556e16d4dc3771 (patch)
tree6a3cb35927f6742b794e985a52617f21cbdd9ada
parentdelete fun (diff)
downloadhomework-6-raquel191-9ef3c244c913934759a6cb5dde556e16d4dc3771.tar.xz
homework-6-raquel191-9ef3c244c913934759a6cb5dde556e16d4dc3771.zip
delete commitHEADmain
-rw-r--r--hw6/hw6/contacts.cpp24
-rw-r--r--hw6/hw6/contacts.h2
-rw-r--r--hw6/hw6/program.cpp16
3 files changed, 32 insertions, 10 deletions
diff --git a/hw6/hw6/contacts.cpp b/hw6/hw6/contacts.cpp
index 6341407..e424a6b 100644
--- a/hw6/hw6/contacts.cpp
+++ b/hw6/hw6/contacts.cpp
@@ -53,7 +53,7 @@ void update(contact(&contacts)[10]) {
Printcontacts(contacts);
int num = 0;
- cout << "Contacts nummbers start from 0." << endl;
+ cout << "Contacts numbers start from 0." << endl;
cout << "Enter contact number to update" << endl;
cin >> num;
@@ -70,14 +70,30 @@ void Delete(contact(&contacts)[10]) {
cout << "Contacts nummbers start from 0." << endl;
cout << "Enter number of contact you wish to delete: " << endl;
cin >> number;
+
+
+
for (int i = number - 1; i < number; i++) {
contacts[number] = contacts[number + 1];
}
- number--;
-
- //contacts[number] =
+ number --;
}
+/*
+ void Double(int*&contacts, contact max[3]) {
+ int* newcontacts = nullptr;
+ newcontacts = new int[max * 2];
+ for (auto i = 0u; i < 3; ++i) {
+ newcontacts[i] = contacts[i];
+ }
+ delete[] contacts;
+ contacts = newcontacts;
+ max *= 2;
+
+}
+*/
+
+
diff --git a/hw6/hw6/contacts.h b/hw6/hw6/contacts.h
index fc66fe0..d5bae47 100644
--- a/hw6/hw6/contacts.h
+++ b/hw6/hw6/contacts.h
@@ -22,4 +22,6 @@ void update(contact(&contacts)[10]);
void Delete(contact(&contacts)[10]);
+//void Double(int*& contacts, contact max[3]);
+
#endif
diff --git a/hw6/hw6/program.cpp b/hw6/hw6/program.cpp
index cec8fd0..d02097d 100644
--- a/hw6/hw6/program.cpp
+++ b/hw6/hw6/program.cpp
@@ -11,12 +11,13 @@ using std::cin;
using std::endl;
const int Max = 10;
+//const int* Max= new int[3];
contact contacts[Max] = {};
int numberofcontacts = 0;
//int* array = new int[3];
-int* newcontacts = new int[3];
+
@@ -25,17 +26,18 @@ char c = 'n';
int main() {
- /*if (newcontacts 3) {
- if (auto i = 0u; i < 3; ++i) {
- newcontacts = new int[3 * 2];
- }
+
+ /*for (int i = 0; i < 3; i++) {
+ newcontacts[i] = i;
+ cout << "newcontact[" << i << "] = " << newcontacts[i] << endl;
}*/
+
do {
//system("cls");
cout << "A. Input New Contact\n";
cout << "B. Update contacts\n";
cout << "C. Print contacts\n";
- cout << "D. Delete a contacat\n";
+ cout << "D. Delete a contact\n";
cout << "press 'x' to exit\n";
std::cin >> c;
@@ -68,6 +70,8 @@ int main() {
case 'D':
Delete(contacts);
+ contacts[numberofcontacts--];
+
break;
case 'x':