|  |  |  | @ -6,6 +6,8 @@ | 
			
		
	
		
			
				
					|  |  |  |  | #include <text.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <svg.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <curl/curl.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <sstream> | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | using namespace std; | 
			
		
	
	
		
			
				
					|  |  |  | @ -21,9 +23,9 @@ struct Input { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | Input | 
			
		
	
		
			
				
					|  |  |  |  | input_data(istream& in, bool prompt) { | 
			
		
	
		
			
				
					|  |  |  |  |     if (prompt == true) { | 
			
		
	
		
			
				
					|  |  |  |  |     if (prompt == true){ | 
			
		
	
		
			
				
					|  |  |  |  |     size_t number_count; | 
			
		
	
		
			
				
					|  |  |  |  |     cerr << "amount of numbers"; | 
			
		
	
		
			
				
					|  |  |  |  |     cerr << "input number count"; | 
			
		
	
		
			
				
					|  |  |  |  |     in >> number_count; | 
			
		
	
		
			
				
					|  |  |  |  |     Input inn; | 
			
		
	
		
			
				
					|  |  |  |  |     inn.numbers.resize(number_count); | 
			
		
	
	
		
			
				
					|  |  |  | @ -34,14 +36,13 @@ input_data(istream& in, bool prompt) { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | size_t bin_count; | 
			
		
	
		
			
				
					|  |  |  |  | cerr << "amount of baskets"; | 
			
		
	
		
			
				
					|  |  |  |  | cerr << "input amount of bins"; | 
			
		
	
		
			
				
					|  |  |  |  | in >> inn.bin_count; | 
			
		
	
		
			
				
					|  |  |  |  | return inn; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     else if (prompt == false) { | 
			
		
	
		
			
				
					|  |  |  |  |     else { | 
			
		
	
		
			
				
					|  |  |  |  |     size_t number_count; | 
			
		
	
		
			
				
					|  |  |  |  |     cout << "amount of numbers"; | 
			
		
	
		
			
				
					|  |  |  |  |     cout << "input number count"; | 
			
		
	
		
			
				
					|  |  |  |  |     in >> number_count; | 
			
		
	
		
			
				
					|  |  |  |  |     Input inn; | 
			
		
	
		
			
				
					|  |  |  |  |     inn.numbers.resize(number_count); | 
			
		
	
	
		
			
				
					|  |  |  | @ -51,36 +52,59 @@ return inn; | 
			
		
	
		
			
				
					|  |  |  |  |         in >> inn.numbers[i]; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | size_t bin_count; | 
			
		
	
		
			
				
					|  |  |  |  | cout << "input baskets"; | 
			
		
	
		
			
				
					|  |  |  |  | in >> inn.bin_count; | 
			
		
	
		
			
				
					|  |  |  |  | return inn; | 
			
		
	
		
			
				
					|  |  |  |  |     size_t bin_count; | 
			
		
	
		
			
				
					|  |  |  |  |     cout << "input amount of bins"; | 
			
		
	
		
			
				
					|  |  |  |  |     in >> inn.bin_count; | 
			
		
	
		
			
				
					|  |  |  |  |     return inn; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | static 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 | 
			
		
	
		
			
				
					|  |  |  |  | download(const string& address) { | 
			
		
	
		
			
				
					|  |  |  |  |     stringstream buffer; | 
			
		
	
		
			
				
					|  |  |  |  |     CURL* curl = curl_easy_init(); | 
			
		
	
		
			
				
					|  |  |  |  |     if(curl) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         CURLcode res; | 
			
		
	
		
			
				
					|  |  |  |  |         const char* res2; | 
			
		
	
		
			
				
					|  |  |  |  |         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!=0) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             res2=curl_easy_strerror(res); | 
			
		
	
		
			
				
					|  |  |  |  |             cout<<res2<<endl; | 
			
		
	
		
			
				
					|  |  |  |  |             exit(1); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         curl_easy_cleanup(curl); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     curl_global_init(CURL_GLOBAL_ALL); | 
			
		
	
		
			
				
					|  |  |  |  |     return input_data(buffer, true); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int main(int argc, char* argv[]) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     Input in; | 
			
		
	
		
			
				
					|  |  |  |  |     CURL *curl = curl_easy_init(); | 
			
		
	
		
			
				
					|  |  |  |  |     if (argc > 1) { | 
			
		
	
		
			
				
					|  |  |  |  |     if(curl) { | 
			
		
	
		
			
				
					|  |  |  |  |     CURLcode res; | 
			
		
	
		
			
				
					|  |  |  |  |     curl_easy_setopt(curl, CURLOPT_URL, "http://uit.mpei.ru/study/courses/cs/lab03/marks.txt"); | 
			
		
	
		
			
				
					|  |  |  |  |     res = curl_easy_perform(curl); | 
			
		
	
		
			
				
					|  |  |  |  |     curl_easy_cleanup(curl); | 
			
		
	
		
			
				
					|  |  |  |  |     cout << res; | 
			
		
	
		
			
				
					|  |  |  |  |         return 0; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |      in = download(argv[1]); | 
			
		
	
		
			
				
					|  |  |  |  |     } else { | 
			
		
	
		
			
				
					|  |  |  |  |         in = input_data(cin, true); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     bool flag; | 
			
		
	
		
			
				
					|  |  |  |  |     bool prompt; | 
			
		
	
		
			
				
					|  |  |  |  |     prompt = true; | 
			
		
	
		
			
				
					|  |  |  |  |     auto inn = input_data(cin, prompt); | 
			
		
	
		
			
				
					|  |  |  |  |     auto bins = make_histogram(inn.numbers, inn.bin_count, flag); | 
			
		
	
		
			
				
					|  |  |  |  |     auto procent = make_histogram_proc(inn.numbers, inn.bin_count, bins); | 
			
		
	
		
			
				
					|  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
			
				
					|  |  |  |  |     auto procent = make_histogram_proc(in.numbers, in.bin_count, bins); | 
			
		
	
		
			
				
					|  |  |  |  |     show_histogram_svg(bins, procent); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     return 0; | 
			
		
	
	
		
			
				
					|  |  |  | 
 |