LoadCallDB reads call records from an open ifstream (istream to be general) unti
ID: 3716671 • Letter: L
Question
LoadCallDB reads call records from an open ifstream (istream to be general) until there is no more data or an error occurs. This function uses a loop. On each iteration, it will read the three fields as strings, call the validate functions you wrote in Lab 1, and if the data passes validation and there is room left in the array, fill in the first unused Call record with the data you read. This function will return the count of records that failed validation or which would not fit in the array because there was no room left.
This is what I have so far:
void LoadCallDb(Call& call, istream& string)
{
string callTime;
string duration;
string e164;
while (f!fin.eof())
{
fin >> callTime >> duration >> e164;
if (callDb.numCalls < MAXCALLS)
{
if (IsValidDate && IsValidPhone && IsLocalPhone)
{
callTime......//Dont know what to do next
}
}
}
}
Explanation / Answer
void LoadCallDb(Call& call, istream& fin)
{
string callTime;
string duration;
string e164;
int failed = 0;
int i=0;
while (!fin.eof())
{
fin >> callTime >> duration >> e164;
if (callDb.numCalls < MAXCALLS)
{
if (IsValidDate && IsValidPhone && IsLocalPhone)
{
// find the first unused call record
while(callDb[i].isFree()) {
i ++;
}
// now insert the data
callDb[i].insert(callTime, duration, e164);
}
} else {
failed ++;
}
}
}
Please note that this answer might not be precise since you need to provide the overall imlementation to get a more precise result.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.