Question: I'm new to C++ and only know basic. How can I collect data in the input file with this function? bool data(Racer a[], unsigned& n)
I'm new to C++ and only know basic. How can I collect data in the input file with this function?
bool data(Racer a[], unsigned& n) { }
------------------------------------------ we have the struct:
#include
using namespace std;
struct Racer {
string name; //name of racer
string country; //country of racer
unsigned timeInMinute; //time in minutes taken by the racer
unsigned year; //year of race
};
bool data(Racer a[], unsigned& n);
void print_data(const Racer a[], unsigned n);
-------test.txt------
Vincenzo, Italy, 89h59, 2014 Cadel, Australia, 86h12, 2011
--------main.txt-----
#include
#include
#include
#include "library.h"
using namespace std;
int main() {
//creat a size to 50 for array
const unsigned SIZE = 50;
//create a racer object array of size 50
Racer racers[SIZE];
//initialize number of racer read from file to 0
unsigned num_racers = 0;
//read data from the file
if (!data(racers, num_racers)) {
cout << "Cant open the file" << endl;
return 1;
}
//print the racer information
print_data(racers,num_racers);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
