forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackOverflowDemo.cpp
More file actions
67 lines (54 loc) · 2.1 KB
/
StackOverflowDemo.cpp
File metadata and controls
67 lines (54 loc) · 2.1 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
#include "StackOverflow.hpp"
#include <iostream>
int main() {
StackOverflow stackoverflow;
// Register users
User* user1 = stackoverflow.registerUser("john_doe", "john@email.com");
User* user2 = stackoverflow.registerUser("alice_smith", "alice@email.com");
User* user3 = stackoverflow.registerUser("bob_wilson", "bob@email.com");
std::cout << "Initial users:" << std::endl;
stackoverflow.displayUserProfile(user1->getUserId());
// Add questions
std::vector<std::string> tags = {"c++", "programming"};
Post* question1 = stackoverflow.addQuestion(
user1->getUserId(),
"How do I use smart pointers in C++?",
tags
);
// Add answers
Post* answer1 = stackoverflow.addAnswer(
user2->getUserId(),
question1->getPostId(),
"Smart pointers automatically manage memory for you..."
);
Post* answer2 = stackoverflow.addAnswer(
user3->getUserId(),
question1->getPostId(),
"There are three main types of smart pointers..."
);
// Add comments
stackoverflow.addComment(
user1->getUserId(),
answer1->getPostId(),
"Thanks, that's helpful!"
);
// Vote on posts
stackoverflow.votePost(user2->getUserId(), question1->getPostId());
stackoverflow.votePost(user3->getUserId(), answer1->getPostId());
stackoverflow.votePost(user1->getUserId(), answer2->getPostId());
// Accept answer
stackoverflow.acceptAnswer(user1->getUserId(), answer1->getPostId());
// Display results
std::cout << "\nQuestion with answers:" << std::endl;
stackoverflow.displayQuestion(question1->getPostId());
std::cout << "\nUser profiles after activity:" << std::endl;
stackoverflow.displayUserProfile(user1->getUserId());
stackoverflow.displayUserProfile(user2->getUserId());
// Search questions
std::cout << "\nSearching for C++ questions:" << std::endl;
auto results = stackoverflow.searchQuestions("c++");
for (const auto& question : results) {
question->displayInfo();
}
return 0;
}