-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-contact.h
99 lines (95 loc) · 4.04 KB
/
remove-contact.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <conio.h>
#include<windows.h>
#include <bits/stdc++.h>
using namespace std;
void gotoRemove(short int x, short int y)
{
COORD p = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
}
class RemoveContact
{
private:
string line;
string name;
string decision;
ifstream in;
ofstream out;
bool contactDeleted = false;
public:
RemoveContact()
{
system("cls");
cout << endl;
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| PHONEBOOK MANAGEMENT SYSTEM |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| One Place To Manage All Your Contacts |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| DELETE EXISTING CONTACTS |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| Enter the name of the contact you |\n";
cout << "\t\t\t\t| want to delete: |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
gotoRemove(51, 10);
getline(cin >> ws, name);
transform(name.begin(), name.end(), name.begin(), ::tolower);
in.open("contact-list.txt");
out.open("temp.txt");
while (getline(in, line))
{
string g = line;
transform(g.begin(), g.end(), g.begin(), ::tolower);
if (g.find(name) != string::npos)
{
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| You are about to Delete a contact |\n";
cout << "\t\t\t\t| Are You Sure? (Yes/No) : |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
gotoRemove(60, 13);
cin >> decision;
if (decision == "Yes")
{
contactDeleted = true;
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| CONTACT DELETED..!! |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
getch();
}
else
{
contactDeleted = true;
out << line << "\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| CONTACT DELETION ABORTED..!! |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
getch();
}
}
else
{
out << line << "\n";
}
}
if (!contactDeleted)
{
cout << "\t\t\t\t----------------------------------------------------------------\n";
cout << "\t\t\t\t| No Contacts Found..!! |\n";
cout << "\t\t\t\t| Deletion Aborted..!! |\n";
cout << "\t\t\t\t----------------------------------------------------------------\n";
getch();
}
}
~RemoveContact()
{
in.close();
out.close();
remove("contact-list.txt");
rename("temp.txt", "contact-list.txt");
}
};