Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <chrono>
- #include <random>
- #include <iomanip>
- #include <fstream>
- constexpr auto low_score = 4;
- constexpr auto high_score = 10;
- constexpr auto numJudges = 5;
- double getScore(std::default_random_engine dre, std::uniform_int_distribution<int> di)
- {
- std::vector<int> scores(numJudges);//to record the scores
- std::generate(scores.begin(), scores.end(), [&]{ return di(dre);});//generates 5 random nos b/w 4 and 10
- std::sort(scores.begin(), scores.end());//sort the scores generated
- std::vector<int> truncatedScores {&scores[1], &scores[scores.size()-1]};
- //truncated vector removing the min and max scores
- return static_cast<double>(std::accumulate(truncatedScores.begin(), truncatedScores.end(),0))/3;
- //average of the truncated scores
- }
- int main()
- {
- auto seed = std::chrono::system_clock::now().time_since_epoch().count();//seed
- std::default_random_engine dre(seed);//engine
- std::uniform_int_distribution<int> di(low_score,high_score);//distribution based on low and hi scores
- // getScore(dre, di);
- std::ofstream fout{"D:\\test.txt"};//file to send scores to
- std::cout << "How many performers? \n";
- size_t performers{};
- std::cin >> performers;
- std::vector<double> scores;//vector to record individual scoreas
- for (size_t i = 0; i < performers; ++i)scores.push_back(std::move(getScore(dre, di)));
- // std::generate(scores.begin(), scores.end(), getScore);
- for (const auto& elem : scores)
- {
- std::cout << std::setprecision(3) << elem << "\n";//print to screen
- fout << std::setprecision(3) << elem << "\n";//print to file
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment