diff --git a/Assignment 1 (C++)/Assignment 1 (C++).cpp b/Assignment 1 (C++)/Assignment 1 (C++).cpp index e87eab6..a4b8d34 100644 --- a/Assignment 1 (C++)/Assignment 1 (C++).cpp +++ b/Assignment 1 (C++)/Assignment 1 (C++).cpp @@ -1,13 +1,69 @@ -// Assignment 1 (C++).cpp : This file contains the 'main' function. Program execution begins and ends there. +// Assignment 1 (C++).cpp : This file contains the 'main' function. Program execution begins and ends there. // #include +#include +#include int main() { - std::cout << "Hello World!\n"; + std::cout << "┌────────────────────────────────────────────────┐\n"; + std::cout << "│ 159.341 2021 Semester 1, Assignment 1 (C++) │\n"; + std::cout << "│ Submitted by Brychan Dempsey, 14299890 │\n"; + std::cout << "└────────────────────────────────────────────────┘\n"; + + bool exit = false; + while (!exit) { + std::vector MemoryChars(1024); // Pre-reserve + + } } +struct MemoryStream { +private: + long position = 0; + long length = 0; + std::vector chars; + + bool ensureCapacity(long step) { + // Size exceeds the bounds of the vector, resize + if (position + step >= chars.size()) { + chars.resize(position + step); + } + } + +public: + MemoryStream(long Reserved) { + chars.assign(Reserved, 0); + } + + char ReadChar() { + if (++position >= length) return -1; + return chars[position]; + } + + char PeekChar() { + char result = ReadChar(); + position--; + return result; + } + + bool writeChar(char c) { + ensureCapacity(1); + if (position == length) length++; + chars[++position] = c; + } + + bool writeChars(char* c, int count) { + ensureCapacity(count); + if (position >= length - count) length = position + count; + for (int i = 0; i < count; i++) + { + chars[i + position] = *(c + i); + } + } +}; + // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu