Сравнить коммиты

...

5 Коммитов

Автор SHA1 Сообщение Дата
Карелина Мария ae05dcc45d added personal task
2 лет назад
Карелина Мария 228b12e186 ignore binary files
2 лет назад
Карелина Мария 93c87c538e added curl
2 лет назад
Карелина Мария eb7785e075 added ignoring
2 лет назад
Карелина Мария e51f0f0211 changed input
2 лет назад

3
.gitignore поставляемый

@ -0,0 +1,3 @@
curl/
obj
bin

Двоичные данные
bin/Debug/devlab1.exe

Двоичный файл не отображается.

@ -1,4 +1,3 @@
10
3 3 3 4 4 4 4 4 5 5
3
16

Двоичные данные
bin/Debug/libcurl-x64.dll

Двоичный файл не отображается.

Двоичные данные
bin/Debug/libcurl.dll.a

Двоичный файл не отображается.

Двоичные данные
bin/Debug/unittest.exe

Двоичный файл не отображается.

@ -13,7 +13,13 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add option="-DCURL_STATICLIB" />
<Add directory="curl/curl/include" />
</Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="curl/curl/lib" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/devlab1" prefix_auto="1" extension_auto="1" />
@ -31,9 +37,12 @@
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add directory="curl/include" />
</Compiler>
<Linker>
<Add option="-static-libstdc++" />
<Add library="libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />

@ -1,15 +1,19 @@
# depslib dependency file v1.0
1682334548 source:c:\program files\codeblocks\devlab1\main.cpp
<iostream>
<vector>
<cmath>
1685368116 source:c:\program files\codeblocks\devlab1\main.cpp
<sstream>
<string>
<curl/curl.h>
"text.h"
"histogram.h"
"svg.h"
"histogram_internal.h"
<iostream>
<vector>
1681733870 c:\program files\codeblocks\devlab1\histogram.h
<vector>
1682342839 source:c:\program files\codeblocks\devlab1\histogram.cpp
1685554919 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
<vector>
<iostream>
@ -24,8 +28,106 @@
1682337558 c:\program files\codeblocks\devlab1\svg.h
<vector>
1682339123 source:c:\program files\codeblocks\devlab1\svg.cpp
1685369210 source:c:\program files\codeblocks\devlab1\svg.cpp
"svg.h"
<iostream>
<vector>
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\curl.h
"curlver.h"
"system.h"
<stdio.h>
<limits.h>
<osreldate.h>
<sys/types.h>
<time.h>
<winsock2.h>
<ws2tcpip.h>
<sys/select.h>
<sys/socket.h>
<sys/time.h>
"easy.h"
"multi.h"
"urlapi.h"
"options.h"
"header.h"
"websockets.h"
"typecheck-gcc.h"
1684811606 c:\program files\codeblocks\devlab1\curl\include\curl\curlver.h
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\system.h
<ConditionalMacros.h>
<winsock2.h>
<windows.h>
<ws2tcpip.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1684736752 c:\program files\codeblocks\devlab1\curl\include\curl\easy.h
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\multi.h
"curl.h"
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\urlapi.h
"curl.h"
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\options.h
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\header.h
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\websockets.h
1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\typecheck-gcc.h
1685551862 c:\program files\codeblocks\devlab1\histogram_internal.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\curl.h
"curlver.h"
"system.h"
<stdio.h>
<limits.h>
<osreldate.h>
<sys/types.h>
<time.h>
<winsock2.h>
<ws2tcpip.h>
<sys/select.h>
<sys/socket.h>
<sys/time.h>
"easy.h"
"multi.h"
"urlapi.h"
"options.h"
"header.h"
"websockets.h"
"typecheck-gcc.h"
1684811606 c:\program files\codeblocks\devlab1\curl\curl\include\curl\curlver.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\system.h
<ConditionalMacros.h>
<winsock2.h>
<windows.h>
<ws2tcpip.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1684736752 c:\program files\codeblocks\devlab1\curl\curl\include\curl\easy.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\multi.h
"curl.h"
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\urlapi.h
"curl.h"
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\options.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\header.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\websockets.h
1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\typecheck-gcc.h

@ -2,19 +2,14 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="145" topLine="0" />
</Cursor>
</File>
<File name="doctest.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.cpp" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="565" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2104" topLine="81" />
<Cursor1 position="69" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -22,29 +17,29 @@
<Cursor1 position="160" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="139" topLine="0" />
<Cursor1 position="1580" topLine="62" />
</Cursor>
</File>
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="69" topLine="0" />
<Cursor1 position="145" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<File name="text.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="544" topLine="17" />
<Cursor1 position="342" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="876" topLine="13" />
<Cursor1 position="139" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="1598" topLine="57" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -3,17 +3,22 @@
#include <iostream>
using namespace std;
bool
find_minmax(const vector<double>& numbers, double& min, double& max)
find_minmax(const vector<double>& numbers, double& min1, double& max1)
{
for (size_t i = 0; i < numbers.size(); i++)
{
cerr<<numbers[i]<<endl;
}
if(numbers.empty())
return false;
min = numbers[0];
max = numbers[0];
min1 = numbers[0];
max1 = numbers[0];
for ( size_t i=0; i < numbers.size(); i++)
{
if (numbers[i] > max) max=numbers[i];
if (numbers[i] < min) min=numbers[i];
if (numbers[i] > max1) max1=numbers[i];
if (numbers[i] < min1) min1=numbers[i];
}
return true;
@ -22,27 +27,23 @@ std::vector<long long unsigned int>
make_histogram(const vector<double> &numbers,size_t bin_count)
{
float lo,hi,dif;
double min, max;
if(!find_minmax(numbers, min, max))
return 1;
vector <size_t> bins(bin_count) ;
dif=(max - min)/bin_count;
for(int i=0; i < numbers.size(); i++)
{
bool found = false;
for (size_t j=0; (j < bin_count-1)&&(!found); j++)
{
lo= min + j*dif;
hi= min + (j+1)*dif;
if ((lo <= numbers[i]) && (numbers[i] <hi ))
{
bins[j]++;
found = true;
}
double min1, max1;
find_minmax(numbers,min1, max1);
// if(!find_minmax(numbers, min, max))
// return 1;
vector <size_t> bins(bin_count);
dif=(max1 - min1)/bin_count;
for (size_t i = 0; i < numbers.size(); i++) {
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
auto lo = min1 + j * dif;
auto hi = min1 + (j + 1) * dif;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
if (!found)
}
if (found == false)
{
bins[bin_count - 1]++;
}

@ -1,6 +1,6 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
bool
find_minmax(const std::vector<double>& numbers, double& min, double& max);
find_minmax(const std::vector<double>& numbers, double& min1, double& max1);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -1,8 +1,12 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <string>
#include <curl/curl.h>
#include "text.h"
#include "histogram.h"
#include "svg.h"
#include "histogram_internal.h"
#include <iostream>
#include <vector>
using namespace std;
@ -11,35 +15,84 @@ struct Input
vector<double> numbers;
int bin_count;
};
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx)
{
size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
}
Input
input_data()
input_data(istream& in, bool prompt)
{
size_t number_count=0;
cerr<<"amount of numbers is ";
cin >> number_count;
Input in;
in.numbers.resize(number_count);
cerr<<"let's intro numbers ";
size_t number_count;
in >> number_count;
Input inp;
inp.numbers.resize(number_count);
if (prompt)
{
std::cerr << "enter bin_count";
}
inp.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++)
{
cin >> in.numbers[i];
in >> inp.numbers[i];
}
size_t bin_count=0;
cerr<<"amount of bins is ";
cin >> in.bin_count;
return in;
}
//4199705
//0x71fdf8
//4199705
int main()
in >> inp.bin_count;
return inp;
}
Input
download(const string& address)
{
auto in = input_data();
stringstream buffer;
CURL* curl = curl_easy_init();
if (curl)
{
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if((res == CURLE_OK) &&
!curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip) && ip) {
cerr<<("IP: %s\n", ip);
}
if (res != 0)
{
cout << curl_easy_strerror(res);
exit(1);
}
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}
//std::cout<<in.bin_count<<endl;
int
main(int argc, char* argv[])
{
Input in;
if (argc > 1)
{
in = download(argv[1]);
}
else
{
in = input_data(cin, true);
}
auto bins = make_histogram(in.numbers, in.bin_count);

Двоичные данные
obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/main.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/svg.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/text.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/unittest.o

Двоичный файл не отображается.

@ -4,21 +4,7 @@
using namespace std;
bool inbl(const int& BLOCK_WIDTH)
{
if (BLOCK_WIDTH>30)
{
cerr<< "too big, please make it smaller\n";
return false;
}
if (BLOCK_WIDTH<3)
{
cerr<< "too small, please make it bigger\n";
return false;
}
return true;
}
void
svg_begin(double width, double height)
@ -56,7 +42,7 @@ show_histogram_svg(vector<long long unsigned int> & bins)
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto BLOCK_WIDTH = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto MAX_ASTERISK1 = 30;
@ -73,14 +59,7 @@ show_histogram_svg(vector<long long unsigned int> & bins)
int i = 0;
int BLOCK_WIDTH;
while (true){
cerr << "block width: ";
cin >> BLOCK_WIDTH;
if(inbl(BLOCK_WIDTH))
break;
}
auto maxb1 = maxb * BLOCK_WIDTH;
@ -99,8 +78,8 @@ show_histogram_svg(vector<long long unsigned int> & bins)
}
else
bin_width = BLOCK_WIDTH * bin;
cerr << "\n" << bin_width << "\n";
//cerr << "\n" << bin << "\n";
// cerr << "\n" << bin_width << "\n";
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));

Загрузка…
Отмена
Сохранить