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

...

6 Коммитов

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

@ -0,0 +1,2 @@
/bin
/obj

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -0,0 +1,66 @@
#include <iostream>
#include <vector>
#include <cmath>
#include "histogam.h"
#include "histogam_internal.h"
#include <conio.h>
using namespace std;
void find_minmax(vector<double> numbers, double& min, double& max) {
min = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] < min) {
min = numbers[i];
}
}
max = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}
}
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
vector<size_t> bins(bin_count);
vector<size_t> binss(bin_count);
double max, min;
find_minmax(numbers, min, max);
double bin_size = (max / min) / 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 = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count - 1]++;
}
}
int max_count = bins[0];
for (size_t i = 0; i < bin_count; i++) {
if (bins[i] > max_count) {
max_count = bins[i];
}
}
if (max_count > 76) {
for (size_t i = 0; i < bin_count; i++) {
int count = bins[i];
size_t height = 76 * (static_cast<double>(count) / max_count);
bins[i] = height;
}
}
return bins;
}

@ -0,0 +1,9 @@
#ifndef HISTOGAM_H_INCLUDED
#define HISTOGAM_H_INCLUDED
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);
#endif // HISTOGAM_H_INCLUDED

@ -0,0 +1,7 @@
#ifndef HISTOGAM_INTERNAL_H_INCLUDED
#define HISTOGAM_INTERNAL_H_INCLUDED
#include <vector>
void find_minmax(std::vector<double> numbers, double& min, double& max);
#endif // HISTOGAM_INTERNAL_H_INCLUDED

@ -0,0 +1,49 @@
# depslib dependency file v1.0
1676294754 source:l:\i êóðñ\À-2-22\Ëåäîâñêîé\ëàá1\lab1\main.cpp
<iostream>
<vector>
1682281166 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\main.cpp
<iostream>
<vector>
<cmath>
<string>
"histogam.h"
"text.h"
"svg.h"
<conio.h>
1682273839 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
<vector>
1682280773 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
<iostream>
<vector>
<cmath>
"histogam.h"
"histogam_internal.h"
<conio.h>
1682280773 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.cpp
<iostream>
<vector>
<cmath>
"text.h"
<conio.h>
1682273447 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.h
<vector>
1682273796 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
<vector>
1682280585 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.cpp
<math.h>
<iostream>
<conio.h>
<vector>
<string>
"svg.h"
1682280301 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.h

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="296" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -1,85 +1,40 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include "histogam.h"
#include "text.h"
#include "svg.h"
#include <conio.h>
using namespace std;
int main()
{
double n;
size_t number_count, bin_count;
cerr<<"Enter number cout:";
cin>>number_count;
vector<double> numbers(number_count);
for (int i =0;i<number_count;i++){
cin>>numbers[i];
}
cerr<<"Enter bin_count";
cin>>bin_count;
vector<size_t> bins(bin_count);
double min = numbers[0];
double max = numbers[0];
for (double x : numbers){
if (x<min){
min=x;
}
else if (x>max){
max=x;
}
}
double bin_size= (max-min)/bin_count;
struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data() {
size_t number_count;
cin >> number_count;
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count - 1]++;
}
cin >> in.numbers[i];
}
size_t maxbin=0;
for (size_t i=0; i<bin_count; i++){
if (maxbin< bins[i]){
maxbin=bins[i];
}
}
size_t k=0;
for (size_t i=0; i<bin_count; i++){
if (bins[i]<100){
cout<<" ";
}
if (bins[i]<10){
cout<<" ";
}
cout<<" "<<bins[i]<<"|";
size_t count = bins[i];
if (maxbin>=76){
size_t height= 76*(static_cast<double>(count)/maxbin);
for (size_t j=0; j<bins[i]; j++){
if (j<height)
cout<<"*";
else
break;
}
}
else{
for (size_t j=0; j<bins[i]; j++){
cout<<"*";
}
}
cout<<endl;
if (k < bin_count - 1){
auto step = min + (k + 1) * bin_size;
cout.precision(3);
cout<<step;
k+=1;
cout<<endl;
}
}
return 0;
cout << "Enter number of bins";
cin >> in.bin_count;
return in;
}
int main()
{
Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
}

@ -0,0 +1,37 @@
#include <math.h>
#include <iostream>
#include <conio.h>
#include <vector>
#include <string>
#include "svg.h"
using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_end() {
cout << "</svg>\n";
}
void
svg_text(double left, double baseline, string text) {
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
}
void
show_histogram_svg(const vector<size_t>& bins) {
svg_begin(400, 300);
svg_text(20, 20, to_string(bins[0]));
svg_end();
}

@ -0,0 +1,7 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
void
show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H_INCLUDED

@ -0,0 +1,22 @@
#include <iostream>
#include <vector>
#include <cmath>
#include "text.h"
#include <conio.h>
using namespace std;
void show_histogram_text(vector <size_t> bins, size_t bin_count ) {
for (size_t i = 0; i < bin_count; i++) {
if (bins[i] < 100) {
cout << " ";
}
if (bins[i] < 10) {
cout << " ";
}
cout << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++) {
cout << "*";
}
cout << "\n";
}
}

@ -0,0 +1,8 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void show_histogram_text(std::vector <size_t> bins, size_t bin_count );
#endif // TEXT_H_INCLUDED

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="unittest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,17 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogam_internal.h"
#include <vector>
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
std::vector<double>f{1,2};
CHECK(f.size() != 0);
CHECK(f.size() != 1);
find_minmax(f, min, max);
CHECK(min == 1);
CHECK(max == 2);
CHECK(min != max);
}

@ -0,0 +1,64 @@
# depslib dependency file v1.0
1682273864 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
<iostream>
<vector>
<cmath>
"histogam.h"
"histogam_internal.h"
1682273839 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
<vector>
1682273796 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
<vector>
1682276727 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\unittest.cpp
"doctest.h"
"histogam_internal.h"
<vector>
1682274769 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
Загрузка…
Отмена
Сохранить