updated filestructure and gitignore. uploading exam progress

This commit is contained in:
Christopher Sanden
2025-11-05 20:09:06 +01:00
parent 120334d964
commit 57187357c3
106 changed files with 12958 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# "ON" = build Option 1, "OFF" = build Option 2.
option(BUILD_ASSIGNMENT_01_OPTION_1 "Build Assignment Option 1 (Standard)" ON)
add_executable(Assignment-01
main.cpp
)
# Conditionally add the correct source file
if(BUILD_ASSIGNMENT_01_OPTION_1)
# If ON, add option1.cpp and define 'ASSIGNMENT_OPTION=1' for C++
target_sources(Assignment-01
PRIVATE
option1.cpp
option1.h
)
target_compile_definitions(Assignment-01 PRIVATE "ASSIGNMENT_01_OPTION=1")
else()
# If OFF, add option2.cpp and define 'ASSIGNMENT_OPTION=2' for C++
target_sources(Assignment-01
PRIVATE
option2.cpp
option2.h
)
target_compile_definitions(Assignment-01 PRIVATE "ASSIGNMENT_01_OPTION=2")
endif()
target_link_libraries(Assignment-01
PRIVATE
SharedLib
)
add_custom_command(TARGET Assignment-01 POST_BUILD
# Add a custom command here if needed
COMMAND ${CMAKE_COMMAND} -E echo "Assignment-01 post-build step"
)

View File

@@ -0,0 +1,60 @@
// Mandatory-02.cpp : Defines the entry point for the application.
//
/*
Dear Student,
Remember to follow the coding standards and best practices discussed
in the portfolio assignment document.
Good luck with your portfolio!
NB: Do not delete the code below that prints the assignment and option info!
---------------------------------------------------------------------
*** HOW TO SWITCH BETWEEN OPTION 1 AND OPTION 2 ***
---------------------------------------------------------------------
You CANNOT switch options by changing this file.
1. Go to the 'CMakeLists.txt' file for this assignment.
2. Find the line:
option(BUILD_ASSIGNMENT_OPTION_1 "..." ON)
3. Change 'ON' (for Option 1) to 'OFF' (for Option 2).
*** VERY IMPORTANT: After changing the option ***
Your project will NOT update until you re-run the CMake configuration.
To force an update (e.g., in Visual Studio):
- Right-click the 'CMakeLists.txt' file and select 'Configure Cache'.
- OR, simply delete the 'out' / 'build' folder and rebuild the project.
---------------------------------------------------------------------
*/
#include <iostream>
#include <string_view>
static constexpr std::string_view AssignmentName = "Category 1: Lists, Stacks, & Queues";
#if ASSIGNMENT_01_OPTION == 1
#include "option1.h"
static constexpr std::string_view AssignmentOption = "Option 1 (Standard): Console Text Editor.";
#elif ASSIGNMENT_01_OPTION == 2
#include "option2.h"
static constexpr std::string_view AssignmentOption = "Option 2 (Advanced): Console Music Player.";
#endif
int main(int argc, char* argv[])
{
int appStatus = 0;
std::cout << AssignmentName << std::endl;
std::cout << AssignmentOption << std::endl;
// Create only core or common code in main.cpp
// Use the option header files to implement the specific assignment option logic
appStatus = RunApp();
return appStatus;
}

View File

@@ -0,0 +1,109 @@
// Option 1 (Standard): Console Text Editor.
//
#include "option1.h"
#include <iostream>
#include "TDoublyLinkedList.h"
#include "TQueue.h"
#include "TStack.h"
#include "Utils.h"
TDoublyLinkedList document;
TQueue printQueue;
TStack undoStack, redoStack;
bool running = true;
int lastIndex = 0;
std::string deletedLine;
void Undo()
{
if (!undoStack.IsEmpty()) {
const auto action = undoStack.Pop();
if (action.action == INSERT){
document.Remove(action.index);
}
else{
document.InsertAtIndex(action.index, action.text);
}
redoStack.Push(action);
}
}
void Redo()
{
if (!redoStack.IsEmpty()) {
const auto action = redoStack.Pop();
if (action.action == INSERT) {
document.InsertAtIndex(action.index, action.text);
}
else {
document.Remove(action.index);
}
undoStack.Push(action);
}
}
int RunApp()
{
// Implement the Console Text Editor application logic here
while (running) {
switch (Utils::Choice()) {
case 1: {
std::cout << "----------Add line----------" << std::endl;
lastIndex = Utils::Insert(document, undoStack, redoStack, lastIndex);
break;
}
case 2: {
std::cout << "----------Remove line----------" << std::endl;
Utils::PrintList(document);
lastIndex = Utils::RemoveLine(document, undoStack, redoStack, lastIndex);
break;
}
case 3: {
std::cout << "----------Current document----------" << std::endl;
for (int i = 0; i < document.GetSize(); i++)
std::cout << i + 1 << ". " << document.GetAtIndex(i) << std::endl;
std::cout << "------------------------------------\n\n";
break;
}
case 4: {
for (int i = 0; i < document.GetSize(); ++i)
printQueue.Enqueue(document.GetAtIndex(i));
std::cout << "----------Printing queue-----------" << std::endl;
while (!printQueue.IsEmpty())
std::cout << printQueue.Dequeue() << std::endl;
std::cout << "------------------------------------\n\n";
break;
}
case 5: {
std::cout << "----------UNDO----------" <<std::endl;
Undo();
break;
}
case 6: {
std::cout << "----------REDO----------" <<std::endl;
Redo();
break;
}
case 0: {
std::cout << "----------Exiting...----------" << std::endl;
running = false;
break;
}
default: {
std::cout << "Invalid input, please pick a number..." << std::endl;
break;
}
}
}
return 0;
}

View File

@@ -0,0 +1,11 @@
// option1.h : Option 1 (Standard): Console Text Editor.
#pragma once
#ifndef OPTION1_H
#define OPTION1_H
int RunApp();
#endif // OPTION1_H

View File

@@ -0,0 +1,19 @@
// Option 2 (Advanced): Console Music Player.
#include <iostream>
#include "option2.h"
static bool SongReadCallback(const int aIndex, const int aTotalCount, const std::string& aArtist, const std::string& aTitle, const std::string& aYear, const std::string& aGenre, const std::string& aSource) {
// Implement the logic to process each song read from the file
// For example, print the song details to the console
std::cout << "Song " << (aIndex + 1) << " of " << aTotalCount << ":\n";
std::cout << " Artist: " << aArtist << "\n";
std::cout << " Title: " << aTitle << "\n";
std::cout << " Year: " << aYear << "\n";
std::cout << " Genre: " << aGenre << "\n";
std::cout << " Source: " << aSource << "\n\n";
// Return true to continue reading more songs
return true;
}

View File

@@ -0,0 +1,10 @@
// option1.h : Option 2 (Advanced): Console Music Player.
#pragma once
#ifndef OPTION2_H
#define OPTION2_H
int RunApp();
#endif // OPTION2_H