-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmp_cpp.cpp
More file actions
74 lines (61 loc) · 2.62 KB
/
cmp_cpp.cpp
File metadata and controls
74 lines (61 loc) · 2.62 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
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "responses.h"
#include "greetings.h"
#include "jokes.h"
#include "commands.h"
std::string getResponse(const std::string& userInput);
int main() {
std::cout << "Welcome to the Conversation AI!" << std::endl;
while (true) {
std::cout << "> ";
std::string userInput;
std::getline(std::cin, userInput);
if (userInput == "exit") {
std::cout << "Goodbye!" << std::endl;
break;
}
std::string response = getResponse(userInput);
std::cout << response << std::endl;
}
return 0;
}
std::string getResponse(const std::string& userInput) {
// Convert user input to lowercase
std::string lowerInput = userInput;
std::transform(lowerInput.begin(), lowerInput.end(), lowerInput.begin(), ::tolower);
if (lowerInput == "hi" || lowerInput == "hey" || lowerInput == "howdy") {
return getRandomGreetingResponse();
}
// Check for jokes keyword
if (lowerInput == "joke") {
return getRandomJokeResponse();
}
// Check for "cmd" command
if (lowerInput.find("cmd") == 0) {
return getCommandResponse(userInput);
}
// Handle other responses based on user input
if (responses.find(lowerInput) != responses.end()) {
return responses[lowerInput];
}
if (lowerInput == "help") {
std::cout << "Welcome to the Command Execution Program!" << std::endl;
std::cout << "\nThis program allows you to execute various commands. You can use the following commands:" << std::endl;
std::cout << "\n1. `cmd`: List available commands." << std::endl;
std::cout << " - Example: `cmd`" << std::endl;
std::cout << "\n2. `command1`: Execute command 1." << std::endl;
std::cout << " - Example: `cmd command1`" << std::endl;
std::cout << "\n3. `command2`: Execute command 2." << std::endl;
std::cout << " - Example: `cmd command2`" << std::endl;
std::cout << "\n4. `command3`: Execute command 3." << std::endl;
std::cout << " - Example: `cmd command3`" << std::endl;
std::cout << "\nTo execute a command, simply enter `cmd` followed by the desired command name. If you're unsure about available commands, enter `cmd` to see the list." << std::endl;
std::cout << "\nEnter `exit` to exit the program." << std::endl;
std::cout << "\nFeel free to explore and try out the commands! If you have any questions or need assistance, please let us know." << std::endl;
return "";
}
return "I'm not sure how to respond to that.";
}