Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Release/*
.vs/*
build/*
.vscode/*
.idea
out/*
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ else()
add_compile_options(-Wall -Wextra -Wpedantic -Wno-gnu-empty-struct -Wno-unused-parameter)
endif()

add_subdirectory(LibraryC)
add_subdirectory(LibraryCPP)
#add_subdirectory(LibraryC)
#add_subdirectory(LibraryCPP)
add_subdirectory(LibraryCPPClass)
add_subdirectory(LibraryCPPTemplate)
#add_subdirectory(LibraryCPPTemplate)

add_subdirectory(Lab1C)
#add_subdirectory(Lab1CPP)
#add_subdirectory(Lab2CPP)
#add_subdirectory(Lab3CPP)
#add_subdirectory(Lab4CPP)
add_subdirectory(Lab5CPP)
6 changes: 0 additions & 6 deletions Lab1C/CMakeLists.txt

This file was deleted.

40 changes: 0 additions & 40 deletions Lab1C/lab1.c

This file was deleted.

8 changes: 8 additions & 0 deletions Lab1CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_executable(Lab1CPP main.cpp)
target_include_directories (Lab1CPP PUBLIC ../LibraryCPPClass)
target_link_libraries(Lab1CPP LibraryCPPClass)

add_test(NAME Test_1 COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)
set_tests_properties(Test_1 PROPERTIES PASS_REGULAR_EXPRESSION "0 1 2 3 4 5 6 7 8 9.*1 2 3 4")
add_test(NAME Test_2 COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input2.txt)
set_tests_properties(Test_2 PROPERTIES PASS_REGULAR_EXPRESSION "22 33 44 88.*3 4")
File renamed without changes.
4 changes: 4 additions & 0 deletions Lab1CPP/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
6
22 13 33 44 90 88
6
11 2 3 4 11 2
88 changes: 88 additions & 0 deletions Lab1CPP/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "array.h"
#include <iostream>
#include <fstream>

using namespace std;

bool is_palindrome(int n) {
if (n < 10) return true;
int start = n;
int reversed = 0;
while (n > 0) {
reversed = reversed * 10 + n % 10;
n /= 10;
}
return start == reversed;
}

int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "Error: File not specified" << endl;
return 1;
}

std::ifstream file(argv[1]);

if (!file.is_open()) {
cout << "Error: Cannot open file " << argv[1] << endl;
return 1;
}

int size1;
file >> size1;

Array arr1(size1);
size_t num = 0;
for (int i = 0; i < size1; i++) {
int temp;
file >> temp;
if (is_palindrome(temp)) {
arr1.set(num, temp);
num++;
}
}

for (size_t i = 0; i < num; i++) {
for (size_t j = 0; j < num - i - 1; j++) {
if (arr1.get(j) > arr1.get(j + 1)) {
int a = arr1.get(j);
int b = arr1.get(j + 1);
swap(a, b);
arr1.set(j, a);
arr1.set(j + 1, b);
}
}
}

for (size_t i = 0; i < num; i++) {
cout << arr1.get(i) << " ";
}
cout << endl;

int size2;
file >> size2;

Array arr2(size2);
for (size_t i = 0; i < arr2.size(); i++) {
int val;
file >> val;
arr2.set(i, val);
}


for (size_t i = 0; i < arr2.size(); i++) {
int count = 0;
for (size_t j = 0; j < arr2.size(); j++) {
if (arr2.get(i) == arr2.get(j)) count++;
}
if (count == 1) {
cout << arr2.get(i) << " ";
}
}

file.close();

return 0;
}


14 changes: 14 additions & 0 deletions Lab2CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(Lab2CPP main.cpp)
target_include_directories (Lab2CPP PUBLIC ../LibraryCPPClass)
target_link_libraries(Lab2CPP LibraryCPPClass)

add_test(NAME Test_1 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input1_2.txt)
set_tests_properties(Test_1 PROPERTIES PASS_REGULAR_EXPRESSION "PUSH 1.*PUSH 2.*PUSH 3.*POP A.*POP B.*MUL A, B.*PUSH A.*POP A.*POP B.*ADD A, B.*PUSH A")
add_test(NAME Test_2 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input2_2.txt)
set_tests_properties(Test_2 PROPERTIES PASS_REGULAR_EXPRESSION "PUSH 1.*PUSH 2.*POP A.*POP B.*ADD A, B.*PUSH A.*PUSH 3.*POP A.*POP B.*MUL A, B.*PUSH A")
add_test(NAME Test_3 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input3_2.txt)
set_tests_properties(Test_3 PROPERTIES PASS_REGULAR_EXPRESSION "PUSH 2.*PUSH 3.*POP A.*POP B.*MUL A, B.*PUSH A.*PUSH 4.*PUSH 5.*POP A.*POP B.*MUL A, B.*PUSH A.*POP A.*POP B.*ADD A, B.*PUSH A")
add_test(NAME Test_4 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input4_2.txt)
set_tests_properties(Test_4 PROPERTIES PASS_REGULAR_EXPRESSION "PUSH 5.*PUSH 3.*POP A.*POP B.*ADD A, B.*PUSH A.*PUSH 2.*PUSH 1.*POP A.*POP B.*ADD A, B.*PUSH A.*POP A.*POP B.*MUL A, B.*PUSH A")
add_test(NAME Test_5 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input5_2.txt)
set_tests_properties(Test_5 PROPERTIES PASS_REGULAR_EXPRESSION "PUSH 5.*PUSH 3.*POP A.*POP B.*SUB A, B.*PUSH A.*PUSH 2.*POP A.*POP B.*MUL A, B.*PUSH A.*PUSH 1.*POP A.*POP B.*ADD A, B.*PUSH A")
1 change: 1 addition & 0 deletions Lab2CPP/input1_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1+2*3
1 change: 1 addition & 0 deletions Lab2CPP/input2_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1+2)*3
1 change: 1 addition & 0 deletions Lab2CPP/input3_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2*3+4*5
1 change: 1 addition & 0 deletions Lab2CPP/input4_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(5+3)*(2+1)
1 change: 1 addition & 0 deletions Lab2CPP/input5_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(5-3)*2+1
127 changes: 127 additions & 0 deletions Lab2CPP/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cctype>
#include <stdexcept>
#include "stack.h"

using namespace std;

typedef vector<string> str_vector;

int priority(char op) {
if (op == '*') return 2;
return 1;
}

str_vector convertToAssembly(const string& expression) {
str_vector assembly;
Stack ops;
string number;

for (size_t i = 0; i < expression.length(); ++i) {
char c = expression[i];

if (isdigit(c)) {
number += c;
}
else {
if (!number.empty()) {
assembly.push_back("PUSH " + number);
number.clear();
}

if (c == '(') {
ops.push('(');
}
else if (c == ')') {
while (!ops.empty() && (char)ops.get() != '(') {
char op = (char)ops.get();
ops.pop();

assembly.push_back("POP A");
assembly.push_back("POP B");
if (op == '+') {
assembly.push_back("ADD A, B");
}
else if (op == '-') {
assembly.push_back("SUB A, B");
}
else {
assembly.push_back("MUL A, B");
}
assembly.push_back("PUSH A");
}
if (!ops.empty()) ops.pop();
}
else if (c == '+' || c == '-' || c == '*') {
while (!ops.empty() && (char)ops.get() != '(' &&
priority((char)ops.get()) >= priority(c)) {
char op = (char)ops.get();
ops.pop();

assembly.push_back("POP A");
assembly.push_back("POP B");
if (op == '+') {
assembly.push_back("ADD A, B");
}
else if (op == '-') {
assembly.push_back("SUB A, B");
}
else {
assembly.push_back("MUL A, B");
}
assembly.push_back("PUSH A");
}
ops.push(c);
}
}
}

if (!number.empty()) {
assembly.push_back("PUSH " + number);
}

while (!ops.empty()) {
char op = (char)ops.get();
ops.pop();

assembly.push_back("POP A");
assembly.push_back("POP B");
if (op == '+') {
assembly.push_back("ADD A, B");
}
else if (op == '-') {
assembly.push_back("SUB A, B");
}
else {
assembly.push_back("MUL A, B");
}
assembly.push_back("PUSH A");
}

return assembly;
}

int main(int argc, char* argv[]) {
try {
if (argc != 2) return 1;

ifstream input(argv[1]);
if (!input.is_open()) return 1;

string expression;
getline(input, expression);

str_vector result = convertToAssembly(expression);
for (size_t i = 0; i < result.size(); ++i) {
cout << result[i] << endl;
}
}
catch (...) {
return 1;
}

return 0;
}
14 changes: 14 additions & 0 deletions Lab3CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(Lab3CPP main.cpp)
target_include_directories (Lab3CPP PUBLIC ../LibraryCPP)
target_link_libraries(Lab3CPP LibraryCPP)

add_test(NAME Test_1 COMMAND Lab3CPP ${CMAKE_CURRENT_SOURCE_DIR}/input1_3.txt)
set_tests_properties(Test_1 PROPERTIES PASS_REGULAR_EXPRESSION "######.*#xxxX#.*#x####.*#xxxY#.*######")
add_test(NAME Test_2 COMMAND Lab3CPP ${CMAKE_CURRENT_SOURCE_DIR}/input2_3.txt)
set_tests_properties(Test_2 PROPERTIES PASS_REGULAR_EXPRESSION "IMPOSSIBLE")
add_test(NAME Test_3 COMMAND Lab3CPP ${CMAKE_CURRENT_SOURCE_DIR}/input3_3.txt)
set_tests_properties(Test_3 PROPERTIES PASS_REGULAR_EXPRESSION "######.*#Yxxx#.*####x#.*#Xxxx#.*######")
add_test(NAME Test_4 COMMAND Lab3CPP ${CMAKE_CURRENT_SOURCE_DIR}/input4_3.txt)
set_tests_properties(Test_4 PROPERTIES PASS_REGULAR_EXPRESSION "#######.*#Yxx#.#.*#.#x#.#.*#..x.##.*###x#.#.*#Xxx..#.*#######")
add_test(NAME Test_5 COMMAND Lab3CPP ${CMAKE_CURRENT_SOURCE_DIR}/input5_3.txt)
set_tests_properties(Test_5 PROPERTIES PASS_REGULAR_EXPRESSION "IMPOSSIBLE")
5 changes: 5 additions & 0 deletions Lab3CPP/input1_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
######
#...X#
#.####
#...Y#
######
5 changes: 5 additions & 0 deletions Lab3CPP/input2_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
######
#...X#
######
#...Y#
######
5 changes: 5 additions & 0 deletions Lab3CPP/input3_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
######
#Y...#
####.#
#X...#
######
7 changes: 7 additions & 0 deletions Lab3CPP/input4_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#######
#Y..#.#
#.#.#.#
#....##
###.#.#
#X....#
#######
7 changes: 7 additions & 0 deletions Lab3CPP/input5_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#######
#Y.##.#
###.#.#
##...##
###.#.#
#X....#
#######
Loading