Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming
diff options
context:
space:
mode:
Commit51ff352a533ff14e9961deb642d110f2d5dc843c (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-31 10:32:53 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-31 10:32:53 +0300
Filesb8bbd97e8a238d58873b777acc4134cf822e69e4 /Year 1/Object-oriented Programming
uni-projects-51ff352a533ff14e9961deb642d110f2d5dc843c.tar
uni-projects-51ff352a533ff14e9961deb642d110f2d5dc843c.tar.gz
uni-projects-51ff352a533ff14e9961deb642d110f2d5dc843c.zip
Parenta6fb61db10a93801065d34d19fb6d7166511e58d (diff)
Completed first lecture homework
1 files changed, 65 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/lecture-hw1.cpp65
diff --git a/Year 1/Object-oriented Programming/lecture-hw1.cpp b/Year 1/Object-oriented Programming/lecture-hw1.cpp
new file mode 100644
index 0000000..d3ded74
--- /dev/null
+++ b/Year 1/Object-oriented Programming/lecture-hw1.cpp
@@ -0,0 +1,65 @@
+#include <iostream>
+#include <cstring>
+
+class Command
+{
+ char name;
+
+public:
+ Command(char name);
+ char getName() const;
+};
+
+Command::Command(char name)
+{
+ this->name = name;
+}
+
+char Command::getName() const
+{
+ return name;
+}
+
+class CommandList
+{
+ Command** commands;
+ int commandCount;
+
+public:
+ CommandList(const char* commands);
+ ~CommandList();
+
+ void printAll() const;
+};
+
+CommandList::CommandList(const char* commands)
+{
+ commandCount = strlen(commands);
+ this->commands = new Command*[commandCount];
+
+ for (int i = 0; i < commandCount; i++)
+ {
+ Command* ptr = new Command(commands[i]);
+ this->commands[i] = ptr;
+ }
+}
+
+CommandList::~CommandList()
+{
+ for (int i = 0; i < commandCount; i++)
+ delete commands[i];
+ delete[] commands;
+}
+
+void CommandList::printAll() const
+{
+ for (int i = 0; i < commandCount; i++)
+ std::cout << commands[i]->getName() << " ";
+ std::cout << std::endl;
+}
+
+int main()
+{
+ CommandList cl("abcdefghijklmnop");
+ cl.printAll();
+}