build:6 варинат
Этот коммит содержится в:
@@ -7,8 +7,9 @@ using namespace std;
|
||||
|
||||
void
|
||||
find_minmax(const vector<double>& numbers, double& min, double& max){
|
||||
if (numbers.size() >=1){
|
||||
min = numbers[0];
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for(size_t i=0; i < numbers.size(); i++){
|
||||
if (numbers[i] < min)
|
||||
{
|
||||
@@ -18,7 +19,7 @@ find_minmax(const vector<double>& numbers, double& min, double& max){
|
||||
{
|
||||
max = numbers[i];
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ void
|
||||
find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
|
||||
@@ -32,7 +32,15 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="input_colors_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
||||
21
main.cpp
21
main.cpp
@@ -11,8 +11,8 @@ using namespace std;
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
string stroke;
|
||||
string fill;
|
||||
vector<string> stroke;
|
||||
vector<string> fill;
|
||||
};
|
||||
|
||||
Input
|
||||
@@ -34,20 +34,25 @@ input_data(){
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.bin_count;
|
||||
|
||||
cerr << "Enter color: ";
|
||||
cin >> in.stroke;
|
||||
|
||||
cerr << "Enter color to fill: ";
|
||||
cin >> in.fill;
|
||||
in.stroke.resize(in.bin_count);
|
||||
in.fill.resize(in.bin_count);
|
||||
for (size_t i=0;i<in.bin_count;i++){
|
||||
cerr <<"Enter stroke in format RGB:";
|
||||
cin >>in.stroke[i];
|
||||
cerr <<"Enter fill in format RGB:";
|
||||
cin >>in.fill[i];
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
auto in = input_data();
|
||||
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_svg(bins, in.stroke, in.fill);
|
||||
show_histogram_svg(bins,in.stroke,in.fill);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
31
svg.cpp
31
svg.cpp
@@ -29,28 +29,9 @@ void
|
||||
svg_rect(double x, double y, double width, double height, string stroke = "chartreuse", string fill = "plum"){
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
|
||||
}
|
||||
|
||||
void
|
||||
input_colors(string &colors_stroke, string &colors_fill){
|
||||
string color_personal;
|
||||
cout << "Do you want to change colors? Yes/No" << endl;
|
||||
cin >> color_personal;
|
||||
while ((color_personal != "No") && (color_personal != "Yes")){
|
||||
cout << "WRONG ANSWER! Try again!" << endl;
|
||||
cin >> color_personal;
|
||||
}
|
||||
if (color_personal == "No"){
|
||||
return;
|
||||
}
|
||||
else {
|
||||
cout << "What color for a stroke do you want?" << endl;
|
||||
cin >> colors_stroke;
|
||||
cout << "What color to fill do you want?" << endl;
|
||||
cin >> colors_fill;
|
||||
}
|
||||
return;
|
||||
}
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
|
||||
show_histogram_svg(const vector<size_t>& bins, const vector<string>& stroke,const vector<string>& fill) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
@@ -67,10 +48,10 @@ show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
|
||||
maxel = bin;
|
||||
}
|
||||
}
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = (( IMAGE_WIDTH - TEXT_WIDTH ) / BLOCK_WIDTH ) * ( bin / maxel );
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
|
||||
for (size_t i=0; i<bins.size(); i++) {
|
||||
const double bin_width = (( IMAGE_WIDTH - TEXT_WIDTH ) / BLOCK_WIDTH ) * ( bins[i] / maxel );
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke[i], fill[i]);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
|
||||
2
svg.h
2
svg.h
@@ -3,5 +3,5 @@
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins, std::string stroke, std::string fill);
|
||||
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<std::string>& stroke, const std::vector<std::string>& fill);
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="doctest.h" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="input_colors_internal.h" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
49
unittest.cpp
49
unittest.cpp
@@ -2,23 +2,6 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "input_colors_internal.h"
|
||||
|
||||
TEST_CASE("Mistakes in spelling") {
|
||||
std::string colors_stroke = "black";
|
||||
std::string colors_fill = "green";
|
||||
input_colors(colors_stroke, colors_fill);
|
||||
CHECK(colors_stroke == "yellow");
|
||||
CHECK(colors_fill == "pink");
|
||||
}
|
||||
|
||||
TEST_CASE("The answer is No") {
|
||||
std::string colors_stroke = "black";
|
||||
std::string colors_fill = "green";
|
||||
input_colors(colors_stroke, colors_fill);
|
||||
CHECK(colors_stroke == "black");
|
||||
CHECK(colors_fill == "green");
|
||||
}
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
@@ -28,18 +11,32 @@ TEST_CASE("distinct positive numbers") {
|
||||
CHECK(max == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("empty vector"){
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 0, 0 }, min, max);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("same elements"){
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({ 1, 1 }, min, max);
|
||||
CHECK(min == max);
|
||||
CHECK(max == min);
|
||||
}
|
||||
|
||||
TEST_CASE("only one number"){
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("distinct negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-1, -2}, min, max);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
}
|
||||
TEST_CASE("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user