-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.h
More file actions
72 lines (66 loc) · 3.33 KB
/
Application.h
File metadata and controls
72 lines (66 loc) · 3.33 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
#include<bits/stdc++.h>
using namespace std;
//chatbot
void chatbot(){
string input;
cout<<"Chatbot: Hello! How can I help You?"<<endl;
while(1){
getline(cin, input);
if (input.find("hi") != string::npos || input.find("hello") != string::npos) {
cout << "Chatbot: Hello there!" <<endl;
}
else if(input.find("how are you") != string::npos ){
cout << "Chatbot: I'm good, thank you for asking. How are you?" <<endl;
}
else if(input.find("I am fine how about you?")!=string::npos || input.find("well") !=string::npos){
cout<<"Chatbot: Nice to meet you. Do you have any question?"<<endl;
}
else if(input.find("Describe Tower of Hanoi Problem?") != string::npos ){
cout << "Chatbot: The Tower of Hanoi is a mathematical puzzle that consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk can be moved at a time Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod No disk may be placed on top of a smaller disk The puzzle can be solved using a recursive algorithm. The basic idea is to divide the problem into subproblems by moving the top n-1 disks from the source rod to the auxiliary rod, then moving the nth disk from the source rod to the target rod, and finally moving the n-1 disks from the auxiliary rod to the target rod. The number of moves required to solve a Tower of Hanoi puzzle is 2^n - 1, where n is the number of disks. This can be proven using mathematical induction. The Tower of Hanoi is a classic example of a problem that can be solved using recursion, and it is often used as a teaching tool in computer science and mathematics. It is also used to teach problem-solving and algorithm design, as well as to illustrate the power and the limits of recursion.?" <<endl;
}
else if (input.find("bye") != string::npos || input.find("exit") != string::npos) {
cout << "Chatbot: Goodbye!" << endl;
break;
}
else {
cout << "Chatbot: I'm sorry, I didn't understand what you said. Could you repeat it?" <<endl;
}
}
}
// text editor
class TextEditor {
public:
void openFile(string fileName);
void editFile();
void saveFile();
private:
string fileName;
string fileContent;
};
void TextEditor::openFile(string fileName) {
this->fileName = fileName;
ifstream file(fileName);
string line;
while (getline(file, line)) {
fileContent += line + '\n';
}
file.close();
}
void TextEditor::editFile() {
cout << "File content:\n" << fileContent << std::endl;
cout << "Enter new content (type 'exit' to save and exit):\n";
string newContent;
string line;
while (getline(cin, line)) {
if (line == "exit") {
break;
}
newContent += line + '\n';
}
fileContent = newContent;
}
void TextEditor::saveFile() {
ofstream file(fileName);
file << fileContent;
file.close();
}