Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <sstream>
- #import <cmath>
- using namespace std;
- std::vector<int> readFile(const std::string &filePath) {
- ifstream in_file;
- in_file.open(filePath);
- std::vector<int> numbers;
- std::string line;
- while(std::getline(in_file,line,'r')){
- numbers.push_back(std::stoi(ligne));
- }
- return numbers;
- }
- float computeMean(std::vector<int> numbers)
- {
- if(numbers()) return 0;
- float total = 0;
- for (int number : numbers) {
- total += number;
- }
- return (total / numbers.size());
- }
- float computeVariance(float mean, std::vector<int> numbers)
- {
- float result = 0;
- for(int number : numbers)
- {
- result += (number - mean)*(number - mean);
- }
- return result / (numbers.size() - 1);
- }
- int main() {
- std::cout << "Veuillez entrer le nom du fichier (donnees.csv) :" << std::endl;
- std::string filePath;
- std::cin >> filePath;
- std::vector<int> numbers = readFile(filePath);
- float mean = computeMean(numbers);
- float variance = computeVariance(mean, numbers);
- float standardDeviation = sqrt(variance);
- std::cout << std::to_string(numbers.size()) + " données : ";
- std::string data;
- for(int number : numbers) {
- data += std::to_string(data) + ", ";
- }
- data = data.substr(0, data.length()-2);
- std::cout << data << std::endl;
- std::cout << "Moyenne : " << std::to_string(mean) << std::endl;
- std::cout << "Variance : " << std::to_string(variance) << std::endl;
- std::cout << "Écart Type : " << std::to_string(standardDeviation) << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment