Programming and Graphics

(Kiana) #1

6.12 The class of runners 179


The implementation of the parametered constructor is:


runner::runner(string runnername, string runnercountry,
double runnertime)
{
name = runnername;
country = runnercountry;
time = runnertime;
}

The purpose of the parametered constructor is to evaluate the private fields
“name”, “country”, and “time” describing each runner.


The implementation of the “read” function is:


void runner::read()
{
cout << " Please enter the runner’s name: ";
getline (cin, name);
cout << " Please enter the runner’s country: ";
getline(cin, country);
cout << " Please enter the runner’s time: ";
cin >> time;
string remainder;
getline (cin, remainder);
}

The implementation of the “getname” function is:


string runner::getname() const
{
return name;
}

The implementation of the “getcountry” function is:


string runner::getcountry() const
{
return name;
}

The implementation of the “gettime” function is:


double runner::gettime() const
{
return time;
}
Free download pdf