-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (39 loc) · 1.23 KB
/
Copy pathmain.cpp
File metadata and controls
46 lines (39 loc) · 1.23 KB
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
#include "include/PhoneDirectory.h"
#include <iostream>
#include <cstdlib>
using namespace PhoneBook;
void printUsage() {
std::cout << "Usage: ./projektcpp [add|remove|display|find|sort] [name] [phone]" << std::endl;
}
int main(int argc, char* argv[]) {
Directory phoneDirectory;
if (argc < 2) {
printUsage();
return 1;
}
std::string command = argv[1];
if (command == "add" && argc == 4) {
std::string name = argv[2];
std::string phone = argv[3];
phoneDirectory.addEntry(name, phone);
} else if (command == "remove" && argc == 3) {
std::string name = argv[2];
phoneDirectory.removeEntry(name);
} else if (command == "display") {
phoneDirectory.displayEntries();
} else if (command == "find" && argc == 3) {
std::string name = argv[2];
Entry* entry = phoneDirectory.findEntry(name);
if (entry) {
std::cout << "Found: Name: " << entry->first << ", Phone: " << entry->second << std::endl;
} else {
std::cout << "Entry not found." << std::endl;
}
} else if (command == "sort") {
phoneDirectory.sortEntries();
} else {
printUsage();
return 1;
}
return 0;
}