rendered paste body#include <iostream>#include <fstream>#include <string>#include <vector>#include "diver.h"using namespace std;std::istream& read_points (std::istream& in, double d[]);double totalScore(vector<double> points, double difficulty);void updateRecord( fstream &updateFile, int id, int round, double score );int main(int argc, char *argv[]){ for(int i=0; i < argc; i++) cout << argv[i] << endl; if (argc < 3){ cout << "Invalid parameters" << endl; return 0; } // tempvariabler string temp; char temp2; double temp3; double difficulty = 0; int id = 0; int round; // öppna fil ifstream textFile ( argv[2] , ifstream::in ); // läs första raden (omgångens namn) textFile >> temp; textFile >> round; cout << "Runda: " << round << endl; while (!textFile.eof()) { vector<double> points; textFile >> temp2; textFile >> temp2; textFile >> id; textFile >> difficulty; while (textFile >> temp3){ points.push_back(temp3); } if (!textFile.eof()){ textFile.clear(); } // utskrift cout << "ID: " << id << ", diff: " << difficulty << ", points: "; for (int i=0; i<5; i++) cout << points[i] << " "; double totals = totalScore(points, difficulty); cout << " = " << totals; cout << endl; // uppdatera binärfilen fstream binFile( argv[1], ios::in | ios::out | ios::binary ); updateRecord(binFile, id, round, totals); binFile.close(); } textFile.close(); return(0);}double totalScore(vector<double> points, double difficulty){ double min = points.at(0); double max = points.at(0); double sum = 0; for (int i=0; i<7; i++){ if (points.at(i) < min) min = points.at(i); if (points.at(i) > max) max = points.at(i); sum += points.at(i); } return ((sum - min - max) * 3 * difficulty) / 5;}void updateRecord( fstream &updateFile, int id, int round, double score ){ // temporär "diver" Diver the_diver; // flytta till sökt post updateFile.seekg(( id - 1 ) * sizeof( Diver ) ); //läs posten updateFile.read( reinterpret_cast< char * >( &the_diver ), sizeof( Diver ) ); // uppdatera posten the_diver.update(round, score); //flytta filpekaren för att skriva tillbaka posten updateFile.seekp( ( id - 1 ) * sizeof( Diver ) ); // skriv tillbaka posten updateFile.write( reinterpret_cast< const char * >( &the_diver ), sizeof( Diver ) );}