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
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ 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)
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.

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

add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)
set_property(TEST TestLab1CPP PROPERTY PASS_REGULAR_EXPRESSION "change of sign: 0 unique values: 1 2 3 4 ")

add_test(NAME TestLab1CPP2 COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/test2.txt)
set_property(TEST TestLab1CPP2 PROPERTY PASS_REGULAR_EXPRESSION "change of sign: 1 unique values: -1 2 3 4 6 0 ")

add_test(NAME TestLab1CPP3 COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/test3.txt)
set_property(TEST TestLab1CPP3 PROPERTY PASS_REGULAR_EXPRESSION "change of sign: 2 unique values: -1 2 3 4 6 0 -9 ")
File renamed without changes.
87 changes: 87 additions & 0 deletions Lab1CPP/lab1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <iostream>
#include <fstream>
#include <string>
#include "array.h"

using namespace std;


Array *array_create_and_read(istream &input)
{
int n;
input >> n;
/* Create array */
Array *arr = array_create(n);
/* Read array data */
for (int i = 0 ; i < n ; ++i)
{
int x;
input >> x;
array_set(arr, i, x);
}
return arr;
}

void task1(Array *arr) {
if (arr == nullptr || array_size(arr) < 2) return;

int signChanges = 0;
int prevSign = (array_get(arr, 0) >= 0) ? 1 : -1;

for (size_t i = 1; i < array_size(arr); i++) {
int currentSign = (array_get(arr, i) >= 0) ? 1 : -1;

if (currentSign != prevSign) {
signChanges++;
prevSign = currentSign;
}
}

cout << "change of sign: " << signChanges;
}

void task2(Array *arr)
{
cout << " unique values: ";
if (arr == nullptr || array_size(arr) == 0) return;

for (size_t i = 0; i < array_size(arr); i++){
int count = 0;
for (size_t j = 0; j < array_size(arr); j++){
if(array_get(arr, i) == array_get(arr, j)){
count++;
}
if(count == 2){
break;
}
}
if(count == 1){
cout << array_get(arr, i) << " ";
}

}

}


int main(int argc, char **argv){
if (argc < 2) {
cerr << "Usage: " << argv[0] << " <input_file>" << endl;
return 1;
}
ifstream FILE(argv[1]);
if (!FILE.is_open()){
return -1;
}
Array *arr = array_create_and_read(FILE);
task1(arr);
array_delete(arr);
/* Create another array here */
arr = array_create_and_read(FILE);
task2(arr);
array_delete(arr);


FILE.close();
cout << "\n";
}
4 changes: 4 additions & 0 deletions Lab1CPP/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
6
-1 -1 0 0 1 1
8
-1 2 3 4 5 5 6 0
4 changes: 4 additions & 0 deletions Lab1CPP/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
9
0 0 -1 -1 0 0 1 1 0
9
-1 2 3 4 5 5 6 0 -9
36 changes: 36 additions & 0 deletions Lab2CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
add_executable(Lab2CPP lab2.cpp)
target_include_directories(Lab2CPP PUBLIC ../LibraryCPP)
target_link_libraries(Lab2CPP LibraryCPP)

add_test(NAME your_first_test COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text1.txt)
set_property(TEST your_first_test PROPERTY PASS_REGULAR_EXPRESSION "1.*3.*2")

add_test(NAME your_second_test COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text2.txt)
set_property(TEST your_second_test PROPERTY PASS_REGULAR_EXPRESSION "1.*2.*3.*6")

add_test(NAME test_summ COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text3.txt)
set_property(TEST test_summ PROPERTY PASS_REGULAR_EXPRESSION "3.*18")

add_test(NAME test_division COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text4.txt)
set_property(TEST test_division PROPERTY PASS_REGULAR_EXPRESSION "1.*1.*1.*2.*2")

add_test(NAME test_division_by_zero COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text4-1.txt)
set_property(TEST test_division_by_zero PROPERTY PASS_REGULAR_EXPRESSION "division by zero error.*stack empty")

add_test(NAME test_remainder COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text5.txt)
set_property(TEST test_remainder PROPERTY PASS_REGULAR_EXPRESSION "1.*0")

add_test(NAME test_dup COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text6.txt)
set_property(TEST test_dup PROPERTY PASS_REGULAR_EXPRESSION "3.*3.*2")

add_test(NAME test_swap COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text7.txt)
set_property(TEST test_swap PROPERTY PASS_REGULAR_EXPRESSION "1.*2.*0.*1")

add_test(NAME test_drop COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text8.txt)
set_property(TEST test_drop PROPERTY PASS_REGULAR_EXPRESSION "1")

add_test(NAME test_over COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text9.txt)
set_property(TEST test_over PROPERTY PASS_REGULAR_EXPRESSION "9.*5.*5")

add_test(NAME test_rot COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/TestTXT/text10.txt)
set_property(TEST test_rot PROPERTY PASS_REGULAR_EXPRESSION "8.*0.*9.*7.*6.*5.*4.*3.*2.*1")
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 rot . . .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 4 5 6 7 8 9 0 rot . . . . . . . . . .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 dup . 2 dup . 3 dup . + + .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 + . 9 9 + .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text4-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 0 / .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1 / . 2 2 / . 3 3 / . 4 2 / . 5 2 / .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3 2 % . 9 9 * 9 + 9 + 1 + 5 5 + % .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 3 dup . . .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 swap . . 0 1 swap . .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 drop .
1 change: 1 addition & 0 deletions Lab2CPP/TestTXT/text9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 9 over . . .
Loading