Question 5a A program which handles text files saves some data on shutodwn and reads it on startup. Two functions, SaveInfo and LoadInfo carry out these tasks, using the file TempInfo.dat. The data is contained in a purpose-designed record ((C++ struct) of type SaveDataType. Incomplete implementations of the two functions are as follows.
void SaveInfo(SaveDataType SaveData)
{ ofstream OutFile;
// Missing statement (a)
if (OutFile)
{
OutFile.write(......); // Incomplete statement (b)
OutFile.write():
}
}
SaveDataType LoadInfo(void)
{ ofstream InFile;
SaveDataType Result;
// Missing statement (c)
if (InFile)
{
// Missing statement (d)
InFile.close();
}
return Result;
}
[5] Question 5b Consider the following program fragment of C++ code, which uses functions from the MT262io library.
int InputInteger;
int Current;
Current=0;
InputInteger=ReadIntPr("Enter your integer: ");
while ((Current*Current) <= InputInteger)
Curent=Current+1;
WriteStringCr("The answer is: ", Current); // Ouput line.
[5] Question 5c Consider the following program fragment of C++ code, which uses functions from the MT262io library. The code is intended to search the array of 16 strings in the array are in alphabetical order. (The algorithm that the code attempts to implement is correct).
int Top; // Line 1
int bottom;
int Here;
boolean Found;
Found=false;
Top = 15;
Bottom = 0;
while Top > Bottom && !Found
{
Here = (Top+Bottom)/2);
if (MyStrings[Here]=WantedString)
Found=true;
else
{
if (MyStrings[Here] = WantedString)
Bottom=Here;
else
Top=Here;
}
}
[5] |