Skip to content
Closed

ok #4

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/codeball.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Codeball
on:
pull_request: {}
pull_request_review_comment:
types: [created, edited]

jobs:
codeball_job:
runs-on: ubuntu-latest
name: Codeball
steps:
- name: Codeball
uses: sturdy-dev/codeball-action@v2
with:
# For all configuration options see https://github.com/sturdy-dev/codeball-action/blob/v2/action.yml
approvePullRequests: "true"
labelPullRequestsWhenApproved: "true"
labelPullRequestsWhenReviewNeeded: "false"
failJobsWhenReviewNeeded: "false"
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp"
}
}
2 changes: 1 addition & 1 deletion E-Commerce App V1.0/Loading.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>
#include <ctime> // Time
#include <windows.h> // Loading

using namespace std;
void gotoXY(int x, int y) {
//'COORD' is a built in function for positioning the objects
COORD d;
Expand Down
6 changes: 6 additions & 0 deletions E-Commerce App V1.0/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
g++ -std=c++17 *.cpp -o main
run:
./main.exe
remove:
rm -f *.exe *.gch
8 changes: 8 additions & 0 deletions OOP1-Lab1/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
circle-build:
g++ -std=c++17 Circle.cpp -o circle
circle-run:
./circle.exe
circle-remove:
rm -f circle.exe
circle-delete:
del circle.exe
54 changes: 54 additions & 0 deletions hello-world/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"files.associations": {
"ostream": "cpp",
"xstring": "cpp",
"algorithm": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"optional": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}
49 changes: 49 additions & 0 deletions hello-world/ExpenseSheet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "ExpenseSheet.h"

bool ExpenseSheet::Add(std::string_view label, double value)
{
Entry e;
e.label = label;
e.value = value;

bool canInsert = std::find(m_entrys.begin(), m_entrys.end(), e) == m_entrys.end();
if (canInsert)
{
m_entrys.push_back(std::move(e));
}

return canInsert;
}

bool ExpenseSheet::Del(std::string_view label)
{
Entry e;
e.label = label;
auto element = std::find(m_entrys.begin(), m_entrys.end(), e);
if (element != m_entrys.end())
{
m_entrys.erase(element);
return true;
}

return false;
}

void ExpenseSheet::List(std::ostream& os) const
{
size_t idx = 0;
for (const Entry& e : m_entrys)
{
os << "(" << idx++ << ") " << e.label << " " << e.value << std::endl;
}
}

double ExpenseSheet::Eval() const
{
double value = 0.;
for (const Entry& e : m_entrys)
{
value += e.value;
}
return value;
}
37 changes: 37 additions & 0 deletions hello-world/ExpenseSheet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <vector>
#include <string>
#include <ostream>
#include <iomanip>
#include <algorithm>
#include <string_view>

class ExpenseSheet
{
public:
struct Entry
{
std::string label;
double value = 0.;

inline bool operator==(const Entry& rhs) const
{
return label == rhs.label;
}
};

public:
ExpenseSheet() = default;
ExpenseSheet(const ExpenseSheet&) = default;

ExpenseSheet& operator=(const ExpenseSheet&) = default;

bool Add(std::string_view label, double value);
bool Del(std::string_view label);
void List(std::ostream& os) const;
double Eval() const;

private:
std::vector<Entry> m_entrys;
};
78 changes: 78 additions & 0 deletions hello-world/InputArguments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "InputArguments.h"

InputArguments::InputArguments(std::string_view line)
{
enum class State
{
ReadyForText,
TextBegin,
TextBeginIgnoreSpaces,
} state = State::ReadyForText;

std::stringstream ss;
for (char c : line)
{
switch (state)
{
case State::ReadyForText:
switch (c)
{
case ' ':
break;
case '"':
state = State::TextBeginIgnoreSpaces;
break;
default:
ss << c;
state = State::TextBegin;
break;
}
break;

case State::TextBegin:
switch (c)
{
case ' ':
m_args.push_back(ss.str());
ss.str("");
state = State::ReadyForText;
break;
default:
ss << c;
break;
}
break;
case State::TextBeginIgnoreSpaces:
switch (c)
{
case '"':
m_args.push_back(ss.str());
ss.str("");
state = State::ReadyForText;
break;
default:
ss << c;
break;
}
break;
}
}

if (state == State::TextBegin)
{
m_args.push_back(ss.str());
}
}

InputArguments InputArguments::Subset(size_t offset, size_t count)
{
InputArguments subset;

auto it = m_args.begin() + offset;
while (count-- && it != m_args.end())
{
subset.m_args.push_back(*(it++));
}

return subset;
}
25 changes: 25 additions & 0 deletions hello-world/InputArguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <vector>
#include <string>
#include <sstream>
#include <string_view>

class InputArguments
{
public:
InputArguments() = default;
InputArguments(const InputArguments&) = default;
InputArguments(std::string_view line);

InputArguments& operator=(const InputArguments&) = default;

InputArguments Subset(size_t offset, size_t count = std::numeric_limits<size_t>::max());

inline size_t Count() const { return m_args.size(); }
inline const std::string& Get(size_t idx) const { return m_args[idx]; }
inline const std::string& operator[](size_t idx) const { return Get(idx); }

private:
std::vector<std::string> m_args;
};
87 changes: 87 additions & 0 deletions hello-world/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "ExpenseSheet.h"
#include "InputArguments.h"

#include <string>
#include <iomanip>
#include <iostream>
#include <algorithm>

int main()
{
std::string line;
ExpenseSheet expenses;

while (true)
{
// Getting user input
std::cout << "> ";
std::getline(std::cin, line);
InputArguments inArgs(line);

std::string cmd = inArgs[0];
std::transform(cmd.begin(), cmd.end(), cmd.begin(), [](char c) { return std::tolower(c); });
auto args = inArgs.Subset(1);

// Check the commd
if (cmd == "add")
{
if (args.Count() == 2 || args.Count() == 3)
{
const auto& label = args[0];
double value;
if (args.Count() == 2)
{
value = atof(args[1].c_str()) * -1.;
}
else
{
value = atof(args[2].c_str());
if (args[1] != "+")
{
value *= -1.;
}
}

if (!expenses.Add(label, value))
{
std::cout << "Failed to add!" << std::endl;
}
}
else
{
std::cout << "Usage: add <label> (+/-) <value>" << std::endl;
}
}
else if (cmd == "del")
{
if (args.Count() == 1)
{
if (!expenses.Del(args[0]))
{
std::cout << "Failed to delete!" << std::endl;
}
}
else
{
std::cout << "Usage: del <label>" << std::endl;
}
}
else if (cmd == "list")
{
expenses.List(std::cout);
}
else if (cmd == "eval")
{
auto value = expenses.Eval();
std::cout << "TOTAL: " << value << std::endl;
}
else if (cmd == "exit")
{
break;
}
else
{
std::cout << "Command \"" << cmd << "\" is unknown!" << std::endl;
}
}
}
Loading