CS210 LAB 3
Sample Solution
Stepwise Refinement
 
Refinements
Notes
Process student data

    Initialise Data 
    Input Data
    Find Data
    Output Data

Struct Student{

};

const int MAX_ENTRIES

//function prototypes

struct SData[MAX_ENTRIES]
int numEntries = 0;

Initialise Data
    Initialise all struct array elements
s.FirstName = " ".
Input Data
    Prompt user for data
    Read data into struct
    Read struct into array element
Cout<<"Enter Firstname";
Getline(cin, s.FirstName);
ReadData(Sdata[numEntries])
numEntries++;
Find Data
    Accept string
    Search-for-name
string name;
getline(cin,name)
Search-for-name
    Compare FirstName in each array 
    position with string.
    Output name if found
bool found = false; int i;

if(name == Sdata[i].FirstName{
    …}

Output Data
    Print all Records
 
Print all Records
    For each array element
    Print a record
for(i=0;i<numEntries;i++)
     PrintData(Sdata[i]);
Print a Record Cout<<"name: "<<s.FirstName
Cout<<"name: "<<s.LastName
 
You may have a different sequence for the refinement. This is one example ofa refinement which shows a good decomposition of the steps for the program. The notes column need not contain a lot of detail. Refinement need not include pseudocode for all steps.