-
Notifications
You must be signed in to change notification settings - Fork 280
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
Лабораторная №1 #913
Changes from 32 commits
c124473
2d52e79
a4acaf5
adb3536
4526f58
79076e5
b558160
6090e0d
32abf47
bbe290d
97bc114
d491ad0
fca58ef
4cb0093
13ff811
ed64e44
cc7bdea
80a9cfd
d89e3b7
85e5d3d
5bfae02
521f87e
19e4e8e
98f380c
b382fd0
86c69ec
3cdae8e
dc2d45d
d816e1c
1184dd4
8cf2890
45b0f8e
1dde670
6db0bfd
288bf94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ Release/* | |
.vs/* | ||
build/* | ||
.vscode/* | ||
cmake-build-debug |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output не нужно создавать в каталоге с исходниками |
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 |
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 GitHub Actions / cpp-linterRun clang-format on Lab1/lab1.cpp
|
||
#include <iostream> | ||
#include <map> | ||
#include "array.h" | ||
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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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 |
This file was deleted.
This file was deleted.
This file was deleted.
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
#include "array.h" | ||
|
||
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; | ||
} |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эти файлы не нужно выкладывать.