-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.cpp
More file actions
89 lines (66 loc) · 2.06 KB
/
Copy pathmessage.cpp
File metadata and controls
89 lines (66 loc) · 2.06 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "message.h"
using namespace std;
BaseMessage::BaseMessage(int senderId) : senderId(senderId) {
auto now = chrono::system_clock::now();
sentDate = chrono::system_clock::to_time_t(now);
}
int BaseMessage::getSenderId() const { return senderId; }
int BaseMessage::getDate() const { return sentDate; }
void BaseMessage::printDate() const {
cout << ctime(&this->sentDate);
}
SimpleMessage::SimpleMessage(int senderId, const char *msg) : BaseMessage(senderId) {
strncpy(message, msg, 200);
}
SimpleMessage::~SimpleMessage() {
}
void SimpleMessage::display() const {
printDate();
cout << " | Sender ID: " << senderId << " | Message: " << message << endl;
}
PostMessage::PostMessage(int senderId, const char *msg, const char *imgPath)
: SimpleMessage(senderId, msg) {
strncpy(imagePath, imgPath, 200);
}
PostMessage::~PostMessage() {
// The PostMessage destructor
}
void PostMessage::display() const {
SimpleMessage::display();
cout << " | Image Path: " << imagePath << endl;
}
VoteMessage::VoteMessage(int senderId, const char *voteTitle, const char optionsArray[][200], int count)
: BaseMessage(senderId), optionCount(count) {
strncpy(title, voteTitle, 200);
for (int i = 0; i < count; i++) {
strncpy(options[i], optionsArray[i], 200);
}
}
VoteMessage::~VoteMessage() {
// The destructor
}
void VoteMessage::display() const {
printDate();
cout << " | Sender ID: " << senderId << " | Vote Title: " << title << endl;
for (int i = 0; i < optionCount; i++) {
cout << " Option " << i + 1 << ": " << options[i] << endl;
}
}
Messenger::Messenger() : messageCount(0) {}
Messenger::~Messenger() {
for (int i = 0; i < messageCount; i++) {
delete messages[i];
}
}
void Messenger::addMessage(BaseMessage *message) {
if (messageCount < 100) {
messages[messageCount++] = message;
} else {
cout << "Message limit reached!" << endl;
}
}
void Messenger::displayChat() const {
for (int i = 0; i < messageCount; i++) {
messages[i]->display();
}
}