저는 C++ 프로그래밍에 상당히 익숙합니다. 텍스트 파일의 숫자를 오름차순으로 정렬하는 코딩에 도움이 필요하므로 중간 값을 취할 수는 있지만 어떻게 수행해야할지 모르겠습니다.텍스트 파일에서 오름차순으로 데이터를 정렬하려면 어떻게합니까?
여기에 지금까지 내 코드입니다 : 사전에
//Create a Vector to hold a set of exam scores.Write a program to do the following tasks: 1. Read exam scores into a vector from Scores.txt
//2. Display scores in rows of five(5) scores.
//3. Calculate average score and display.
//4. Find the median score and display.
//5. Compute the Standard Deviation and display
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{ const int array_size = 36; // array size
int numbers[array_size]; //array with 36 elements
int count = 0;
int column_count = 5;
ifstream inputfile; //input file into stream object
//open file
inputfile.open("Scores.txt");
//read file
while (count < array_size && inputfile >> numbers[count])
count++;
//close file
inputfile.close();
//display numbers read
for (count = 0; count < array_size; count++) {
cout << numbers[count] << " ";
if (count % column_count == column_count - 1) {
cout << "\n";
}
}
//find the average
double average; //average
double total = 0; //initialize accumulator
cout << "\nAverage:\n";
for (count = 0; count < array_size; count++)
total += numbers[count];
average = total/array_size;
cout << average << " ";
cout << endl;
//find the median
std::sort(numbers.begin(), numbers.end(), std::greater<int>());
system ("pause");
return 0;
}
감사합니다!
직접 정렬 알고리즘을 작성해야합니까? – evanmcdonnal
시도한 것을 게시하십시오. – user93353