-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (43 loc) · 1.59 KB
/
main.cpp
File metadata and controls
53 lines (43 loc) · 1.59 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
#include "Learn_CPP.h"
#include <iostream>
#include <unordered_map>
using namespace std;
extern std::unordered_map<std::string, Topic> getArrayTopics();
extern std::unordered_map<std::string, Topic> getFunctionTopics();
extern std::unordered_map<std::string, Topic> getPointerTopics();
extern std::unordered_map<std::string, Topic> getLoopTopics();
std::unordered_map<std::string, Topic> initializeTopics() {
auto topics = getArrayTopics();
auto functionTopics = getFunctionTopics();
auto pointerTopics = getPointerTopics();
auto loopTopics = getLoopTopics();
// Merge all topics into one map
topics.insert(functionTopics.begin(), functionTopics.end());
topics.insert(pointerTopics.begin(), pointerTopics.end());
topics.insert(loopTopics.begin(), loopTopics.end());
return topics;
}
void showTopicDetails(const std::unordered_map<std::string, Topic>& topics, const std::string& topicName) {
auto it = topics.find(topicName);
if (it != topics.end()) {
const auto& topic = it->second;
cout << "---- " << topicName << " ----\n";
cout << "Description: " << topic.description << "\n\n";
cout << topic.syntax << "\n\n";
cout << topic.exampleCode << "\n";
} else {
cout << "Topic not found!\n";
}
}
int main() {
auto topics = initializeTopics();
cout << "Available Topics:\n";
for (const auto& topic : topics) {
cout << "- " << topic.first << "\n";
}
cout << "\nEnter the topic you want to learn: ";
string topicName;
cin >> topicName;
showTopicDetails(topics, topicName);
return 0;
}