Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Лабораторная №1 #913

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c124473
add fio
sudo-odner Sep 9, 2024
2d52e79
add array on C++, passed the tests
sudo-odner Sep 9, 2024
a4acaf5
add array and list. In Library CPP class
sudo-odner Sep 16, 2024
adb3536
fix list.cpp. Add queue.cpp
sudo-odner Sep 16, 2024
4526f58
add stack
sudo-odner Sep 16, 2024
79076e5
add vector. Delete changes in tests file
sudo-odner Sep 16, 2024
b558160
add vector. Delete changes in tests file
sudo-odner Sep 16, 2024
6090e0d
complete lab1
sudo-odner Sep 20, 2024
32abf47
fix and rewrite copy constructor
sudo-odner Sep 20, 2024
bbe290d
delete trash
sudo-odner Sep 20, 2024
97bc114
fix error
sudo-odner Sep 20, 2024
d491ad0
fix bug wiht delete array
sudo-odner Sep 20, 2024
fca58ef
fix bug with delete help array in lab1
sudo-odner Sep 20, 2024
4cb0093
fix bug with delete list lab1
sudo-odner Sep 20, 2024
13ff811
fix bug sintax
sudo-odner Sep 20, 2024
ed64e44
fix bug delete list
sudo-odner Sep 20, 2024
cc7bdea
fix bug delete list
sudo-odner Sep 20, 2024
80a9cfd
fix bug delete list
sudo-odner Sep 20, 2024
d89e3b7
fix bug delete list
sudo-odner Sep 20, 2024
85e5d3d
fix bug delete list
sudo-odner Sep 20, 2024
5bfae02
fix bug delete list
sudo-odner Sep 20, 2024
521f87e
test
sudo-odner Sep 20, 2024
19e4e8e
fix bug delete list
sudo-odner Sep 20, 2024
98f380c
fix list
sudo-odner Sep 20, 2024
b382fd0
fix list
sudo-odner Sep 20, 2024
86c69ec
fix list
sudo-odner Sep 20, 2024
3cdae8e
fix list
sudo-odner Sep 20, 2024
dc2d45d
fix list
sudo-odner Sep 20, 2024
d816e1c
fix list and array
sudo-odner Sep 23, 2024
1184dd4
change stack and queue used List
sudo-odner Sep 23, 2024
8cf2890
fix bag and add check empty in queue
sudo-odner Sep 23, 2024
45b0f8e
deleted
sudo-odner Sep 25, 2024
1dde670
[Lab1] удалил реализацию LibraryCPP
sudo-odner Oct 4, 2024
6db0bfd
[Lab1] done lab 1
sudo-odner Oct 4, 2024
288bf94
[Lab1] fix bug
sudo-odner Oct 7, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Release/*
.vs/*
build/*
.vscode/*
cmake-build-debug
8 changes: 8 additions & 0 deletions .idea/.gitignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эти файлы не нужно выкладывать.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/Algorithms.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ project(Algorithms)

enable_testing()
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
set(CMAKE_CXX_STANDARD 11)
if (MSVC)
# needs at least cmake 3.15
add_compile_options(/W4 /WX)
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(Lab1)
5 changes: 5 additions & 0 deletions Lab1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(Lab1 lab1.cpp)
target_include_directories(Lab1 PUBLIC ../LibraryCPPClass)
target_link_libraries(Lab1 LibraryCPPClass)

add_test(NAME TestLab1 COMMAND Lab1 ${CMAKE_CURRENT_SOURCE_DIR}/input.txt ${CMAKE_CURRENT_SOURCE_DIR}/output.txt)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output не нужно создавать в каталоге с исходниками

4 changes: 4 additions & 0 deletions Lab1/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
365
4 47 87 61 100 29 86 90 27 12 3 47 16 67 80 31 74 48 1 11 64 80 49 70 57 61 29 89 12 33 39 56 77 31 28 51 82 8 8 62 27 87 92 78 64 74 42 41 35 68 21 17 24 51 71 6 11 19 18 60 75 4 41 89 56 38 38 77 91 30 80 72 96 63 16 70 90 28 12 66 11 45 94 4 13 79 75 28 88 80 76 50 77 93 34 76 9 52 38 13 31 59 18 3 57 1 51 49 71 79 67 74 42 26 45 95 42 88 42 6 11 61 28 66 52 92 89 1 61 50 56 8 4 98 73 26 72 96 82 29 76 20 77 99 31 85 96 47 23 74 94 2 43 44 97 78 6 69 74 17 7 33 65 68 91 31 30 29 20 49 67 63 44 31 26 54 25 51 60 73 34 10 77 37 60 90 14 29 2 13 91 12 12 59 19 46 87 72 30 56 37 74 77 30 9 81 91 91 63 21 89 18 88 27 58 93 42 13 36 11 8 18 95 67 32 62 66 24 88 53 16 42 90 46 54 82 33 56 21 33 64 61 94 12 47 8 76 43 21 8 45 47 63 74 55 86 52 86 70 64 29 6 98 31 39 8 36 47 96 62 80 90 44 99 69 3 39 12 79 55 73 25 48 99 6 22 49 61 12 67 8 72 77 88 83 77 48 12 63 15 94 4 42 48 13 50 7 56 76 37 88 100 45 62 23 100 48 16 2 10 47 97 30 12 14 52 26 98 58 24 24 50 45 100 36 50 92 41 83 4 10 15 69 68 89 28 6 81 65 7 40 57 74 57 18 6 51 98 50 56 54 8 49 84 52
11
1 2 2 3 2 3 4 4 5 6 1
111 changes: 111 additions & 0 deletions Lab1/lab1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <fstream>

Check notice on line 1 in Lab1/lab1.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on Lab1/lab1.cpp

File Lab1/lab1.cpp does not conform to Custom style guidelines. (lines 1, 7, 8, 9, 11, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 80, 81, 82, 83, 84, 85, 86, 87, 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 106, 107, 108, 109)
#include <iostream>
#include <map>
#include "array.h"

Check failure on line 4 in Lab1/lab1.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Lab1/lab1.cpp:4:10 [clang-diagnostic-error]

'array.h' file not found
using namespace std;

Array *arrayCreateFromInput(std::ifstream& input) {
size_t size;
input >> size;

Array* arr = new Array(size);

for (size_t i = 0; i < size; ++i) {
int value;
input >> value;
arr->set(i, value);
}
return arr;
}
Array *DataDayInMonth(){
Array *monthDay = new Array(12);
monthDay->set(0, 31);
monthDay->set(1, 28);
monthDay->set(2, 31);
monthDay->set(3, 30);
monthDay->set(4, 31);
monthDay->set(5, 30);
monthDay->set(6, 31);
monthDay->set(7, 31);
monthDay->set(8, 30);
monthDay->set(9, 31);
monthDay->set(10, 30);
monthDay->set(11, 31);
return monthDay;
}

void task1(Array *arr) {
Array *sumRainfallInMonth = new Array(12);
Array *dayInMonth = DataDayInMonth();

int month = 0, day = 1, summ = 0;
for (size_t i = 0; i < arr->size(); i++) {
if (day < dayInMonth->get(month)){
summ += arr->get(i);
day++;
} else {
summ += arr->get(i);
sumRainfallInMonth->set(month, summ);
month += 1;
day = 1;
summ = 0;
}
}
// Print answer
for (size_t i = 0; i < 12; i++){
cout << sumRainfallInMonth->get(i) << " ";
}
cout << '\n';
// Delete array
delete sumRainfallInMonth;
delete dayInMonth;
}

void task2(Array *arr) {
map<int, int> mp;
for (size_t i = 0; i < arr->size(); i++) {
mp[arr->get(i)] += 1;
}

// Print answer
map<int, int>::iterator itr;
for (itr = mp.begin(); itr != mp.end(); ++itr){
if (itr->second == 2) {
cout << itr->first << " ";
}
}
cout << '\n';
}

bool test(ifstream& output, const Array& arr){
for(size_t i = 0; i < arr.size(); i++) {
int num;
output >> num;
if(num != arr.get(i)) {
return false;
}
}
return true;
}

int main(int argc, char **argv) {
ifstream input(argv[1]);
ifstream output(argv[2]);
Array *arrTask1 = arrayCreateFromInput(input);
task1(arrTask1);
if(test(output, *arrTask1)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тест должен быть отдельно от программы, которая выводит результат.

return 1;
}

Array *arrTask2 = arrayCreateFromInput(input);
task2(arrTask2);
if(test(output, *arrTask2)) {
return 1;
}

// End function
delete arrTask1;
delete arrTask2;
input.close();
return 0;
}
2 changes: 2 additions & 0 deletions Lab1/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1504 1249 1709 1464 1777 1381 1497 1573 1523 1549 1410 1498
1 3 4
5 changes: 0 additions & 5 deletions Lab1C/CMakeLists.txt

This file was deleted.

4 changes: 0 additions & 4 deletions Lab1C/input.txt

This file was deleted.

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

This file was deleted.

8 changes: 4 additions & 4 deletions LibraryC/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_executable(TestArrayC array.cpp)
target_include_directories(TestArrayC PUBLIC ..)
target_link_libraries(TestArrayC LibraryC)
add_test(TestArrayC TestArrayC)
#add_executable(TestArrayC array.cpp)
#target_include_directories(TestArrayC PUBLIC ..)
#target_link_libraries(TestArrayC LibraryC)
#add_test(TestArrayC TestArrayC)

# add_executable(TestListC list.cpp)
# target_include_directories(TestListC PUBLIC ..)
Expand Down
3 changes: 2 additions & 1 deletion LibraryCPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_library(LibraryCPP STATIC array.cpp list.cpp queue.cpp stack.cpp vector.cpp)
add_library(LibraryCPP STATIC array.cpp list.cpp queue.cpp stack.cpp vector.cpp
../LibraryCPPClass/Tests/array.cpp)

add_subdirectory(Tests)
10 changes: 6 additions & 4 deletions LibraryCPP/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# add_executable(TestArrayCPP array.cpp)
# target_include_directories(TestArrayCPP PUBLIC ..)
# target_link_libraries(TestArrayCPP LibraryCPP)
# add_test(TestArrayCPP TestArrayCPP)
#add_executable(TestArrayCPP array.cpp array.cpp
# ../../LibraryCPPClass/Tests/array.cpp)
#target_include_directories(TestArrayCPP PUBLIC ..)
#target_link_libraries(TestArrayCPP LibraryCPP)
#add_test(TestArrayCPP TestArrayCPP)


# add_executable(TestListCPP list.cpp)
# target_include_directories(TestListCPP PUBLIC ..)
Expand Down
2 changes: 1 addition & 1 deletion LibraryCPP/Tests/array.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <iostream>

Check notice on line 1 in LibraryCPP/Tests/array.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on LibraryCPP/Tests/array.cpp

File LibraryCPP/Tests/array.cpp does not conform to Custom style guidelines. (lines 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26)
#include "array.h"

Check failure on line 2 in LibraryCPP/Tests/array.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

LibraryCPP/Tests/array.cpp:2:10 [clang-diagnostic-error]

'array.h' file not found

int main()
{
Expand All @@ -7,7 +7,7 @@

if (array_size(arr) != 10)
{
std::cout << "Invalid array size\n";
std::cout << "Invalid array size: " << array_size(arr) << "\n";
array_delete(arr);
return 1;
}
Expand Down
32 changes: 16 additions & 16 deletions LibraryCPP/array.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#include "array.h"

Check notice on line 1 in LibraryCPP/array.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on LibraryCPP/array.cpp

File LibraryCPP/array.cpp does not conform to Custom style guidelines. (lines 3, 4, 9, 10, 11, 12, 17, 18, 22, 23, 27, 32, 33)

struct Array
{
struct Array {
size_t size;
Data *arr;
};

// create array
Array *array_create(size_t size)
{
return new Array;
Array *array_create(size_t size) {
Array *newArray = new Array;
newArray->size = size;
newArray->arr = (Data*) new Data[size];
return newArray;
}

// delete array, free memory
void array_delete(Array *arr)
{
delete arr;
void array_delete(Array *arr) {
delete[] arr;
}

// returns specified array element
Data array_get(const Array *arr, size_t index)
{
return (Data)0;
Data array_get(const Array *arr, size_t index) {
return (Data) arr->arr[index];
}

// sets the specified array element to the value
void array_set(Array *arr, size_t index, Data value)
{
void array_set(Array *arr, size_t index, Data value){
arr->arr[index] = value;
}

// returns array size
size_t array_size(const Array *arr)
{
return 0;
size_t array_size(const Array *arr){
return arr->size;
}
3 changes: 1 addition & 2 deletions LibraryCPP/list.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstddef>

Check notice on line 1 in LibraryCPP/list.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on LibraryCPP/list.cpp

File LibraryCPP/list.cpp does not conform to Custom style guidelines. (lines 1, 4, 5, 8, 9, 12, 13, 14, 17, 18, 19, 23, 24, 25, 28, 29, 30, 33, 34, 35, 38, 39, 40, 43, 44, 45, 48, 49, 53, 54, 55, 58, 59)
#include "list.h"

struct ListItem
Expand Down Expand Up @@ -55,7 +55,6 @@
return NULL;
}

ListItem *list_erase_next(List *list, ListItem *item)
{
ListItem *list_erase_next(List *list, ListItem *item) {
return NULL;
}
2 changes: 1 addition & 1 deletion LibraryCPPClass/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_library(LibraryCPPClass STATIC array.cpp list.cpp queue.cpp stack.cpp vector.cpp)
add_library(LibraryCPPClass STATIC array.cpp)

add_subdirectory(Tests)
Loading
Loading