code: изменение программы на оригинальную версию(не вариант из 3 лаб.)
Этот коммит содержится в:
8
main.cpp
8
main.cpp
@@ -12,7 +12,6 @@ using namespace std;
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
double USER_BIN_HEIGHT{};
|
||||
};
|
||||
|
||||
Input input_data(istream& stream, bool prompt) {
|
||||
@@ -41,11 +40,6 @@ Input input_data(istream& stream, bool prompt) {
|
||||
}
|
||||
stream >> in.bin_count;
|
||||
|
||||
if (prompt){
|
||||
cerr << "Enter image height: ";
|
||||
}
|
||||
stream >> in.USER_BIN_HEIGHT;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -78,7 +72,7 @@ int main(int argc, char* argv[]){
|
||||
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
show_histogram_svg(bins, in.USER_BIN_HEIGHT);
|
||||
show_histogram_svg(bins);
|
||||
|
||||
|
||||
}
|
||||
|
||||
35
svg.cpp
35
svg.cpp
@@ -26,34 +26,8 @@ void svg_rect(double x, double y, double width, double height){
|
||||
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='#33A220' ></rect>";
|
||||
}
|
||||
|
||||
double calculate_bin_height (const std::vector<std::size_t>& bins, double USER_BIN_HEIGHT, double IMAGE_HEIGHT){
|
||||
|
||||
double BIN_HEIGHT;
|
||||
|
||||
if ( USER_BIN_HEIGHT < 0 ){
|
||||
|
||||
BIN_HEIGHT = 0;
|
||||
|
||||
} else {
|
||||
|
||||
BIN_HEIGHT = USER_BIN_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
auto USER_IMAGE_HEIGHT = bins.size() * BIN_HEIGHT;
|
||||
|
||||
if (USER_IMAGE_HEIGHT > IMAGE_HEIGHT){
|
||||
BIN_HEIGHT = IMAGE_HEIGHT / bins.size();
|
||||
}
|
||||
|
||||
return BIN_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<std::size_t>& bins, double USER_BIN_HEIGHT) {
|
||||
show_histogram_svg(const std::vector<std::size_t>& bins) {
|
||||
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 700;
|
||||
@@ -61,16 +35,13 @@ show_histogram_svg(const std::vector<std::size_t>& bins, double USER_BIN_HEIGHT)
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto BIN_HEIGHT = 50;
|
||||
|
||||
|
||||
|
||||
auto BIN_HEIGHT = calculate_bin_height (bins, USER_BIN_HEIGHT, IMAGE_HEIGHT);
|
||||
|
||||
auto USER_IMAGE_HEIGHT = bins.size() * BIN_HEIGHT;
|
||||
|
||||
|
||||
const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
svg_begin(IMAGE_WIDTH, USER_IMAGE_HEIGHT);
|
||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||
double top = 0;
|
||||
|
||||
|
||||
|
||||
2
svg.h
2
svg.h
@@ -4,6 +4,6 @@
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<std::size_t>& bins, double USER_BIN_HEIGHT);
|
||||
show_histogram_svg(const std::vector<std::size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
||||
|
||||
Ссылка в новой задаче
Block a user