code: my var
Этот коммит содержится в:
@@ -42,3 +42,4 @@ std::vector <std::size_t> make_histogram( const std::vector<double> &numbers, st
|
|||||||
}
|
}
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
lab1.cbp
5
lab1.cbp
@@ -17,6 +17,7 @@
|
|||||||
<Linker>
|
<Linker>
|
||||||
<Add option="-static-libstdc++" />
|
<Add option="-static-libstdc++" />
|
||||||
<Add option="-static-libgcc" />
|
<Add option="-static-libgcc" />
|
||||||
|
<Add option="-static" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release">
|
<Target title="Release">
|
||||||
@@ -36,6 +37,10 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename="aver.cpp" />
|
||||||
|
<Unit filename="aver.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="doctest.h" />
|
<Unit filename="doctest.h" />
|
||||||
<Unit filename="histogram.cpp" />
|
<Unit filename="histogram.cpp" />
|
||||||
<Unit filename="histogram.h" />
|
<Unit filename="histogram.h" />
|
||||||
|
|||||||
3
main.cpp
3
main.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "aver.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -40,8 +41,6 @@ Input input_data() {
|
|||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
Input in = input_data();
|
Input in = input_data();
|
||||||
|
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
|
|||||||
17
svg.cpp
17
svg.cpp
@@ -1,6 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "aver.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
svg_begin(double width, double height) {
|
svg_begin(double width, double height) {
|
||||||
@@ -22,10 +25,15 @@ svg_text(double left, double baseline, std::string text) {
|
|||||||
std::cout << "<text x='" << left << "' y='"<< baseline << "' > " << text << " </text>";
|
std::cout << "<text x='" << left << "' y='"<< baseline << "' > " << text << " </text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
void svg_rect(double x, double y, double width, double height){
|
void svg_rect(double x, double y, double width, double height,int res){
|
||||||
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='#33A220' ></rect>";
|
if(res == 1){
|
||||||
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='green' fill='#008000' ></rect>";
|
||||||
|
}if(res==2){
|
||||||
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='red' fill='#FF0000 ' ></rect>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(const std::vector <std::size_t> &bins) {
|
show_histogram_svg(const std::vector <std::size_t> &bins) {
|
||||||
|
|
||||||
@@ -47,11 +55,12 @@ show_histogram_svg(const std::vector <std::size_t> &bins) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (maxbin<=76){
|
if (maxbin<=76){
|
||||||
for (std::size_t i=0; i < bins.size(); i++) {
|
for (std::size_t i=0; i < bins.size(); i++) {
|
||||||
double bin_width = BLOCK_WIDTH * bins[i];
|
double bin_width = BLOCK_WIDTH * bins[i];
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,compareHeightToAverage(bins,i));
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
@@ -59,7 +68,7 @@ show_histogram_svg(const std::vector <std::size_t> &bins) {
|
|||||||
for (std::size_t i=0; i < bins.size(); i++) {
|
for (std::size_t i=0; i < bins.size(); i++) {
|
||||||
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
|
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,compareHeightToAverage(bins,i));
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
|
|||||||
@@ -31,9 +31,12 @@
|
|||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename="aver.cpp" />
|
||||||
|
<Unit filename="aver.h" />
|
||||||
<Unit filename="histogram.cpp" />
|
<Unit filename="histogram.cpp" />
|
||||||
<Unit filename="histogram.h" />
|
<Unit filename="histogram.h" />
|
||||||
<Unit filename="histogram_internal.h" />
|
<Unit filename="histogram_internal.h" />
|
||||||
|
<Unit filename="test my var.cpp" />
|
||||||
<Unit filename="unittest.cpp" />
|
<Unit filename="unittest.cpp" />
|
||||||
<Extensions />
|
<Extensions />
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
14
unittest.cpp
14
unittest.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include "doctest.h"
|
#include "doctest.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
|
#include "aver.h"
|
||||||
|
|
||||||
TEST_CASE("distinct positive numbers") {
|
TEST_CASE("distinct positive numbers") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
@@ -47,3 +48,16 @@ TEST_CASE("empty array") {
|
|||||||
CHECK(min == 0);
|
CHECK(min == 0);
|
||||||
CHECK(max == 0);
|
CHECK(max == 0);
|
||||||
}
|
}
|
||||||
|
TEST_CASE("my var 1") {
|
||||||
|
int a=compareHeightToAverage({1,1,2},1);
|
||||||
|
CHECK(a == 1);
|
||||||
|
}
|
||||||
|
TEST_CASE("my var 2") {
|
||||||
|
int a=compareHeightToAverage({1,1,2},2);
|
||||||
|
CHECK(a == 2);
|
||||||
|
}
|
||||||
|
TEST_CASE("my var 3") {
|
||||||
|
int a=compareHeightToAverage({2,1,1},3);
|
||||||
|
CHECK(a == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user