Help, please

I have to do this program for school and i am completely stuck. Were working on structures and arrays The professor pretty much did the code but I have to complete the functions and im confused. The parts i need to complete are under "// YOU MUST COMPLETE THIS FUNCTION". Help on what to put in these parts is greatly appreciated. here is the purpose of the assignment and the code and the datafile.

The Program
The purpose of this program is to permit the user to display and update a class list. This program will declare structures necessary to store the data, read the data from the data file into the appropriate variable, display the data on-screen in a neatly formatted table, and finally ‘save’ the data back to the data file.
Descripton of Data File program10.txt
Line 1:
Course title, may contain embedded blanks
Line 2:
Instructors last name, no embedded blanks
Subsequent lines:
Student’s ID a 4 digit code.
There are at most 10 student records. Each line of the data file ends with a newline.
Sample data file – you must create your own data file
CMPSC 102 - Introduction to C++ Structures
Watson
1234
3456
9987
7654
8888

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

// File scope constants
const long MAX=10; // Maximum number of records

// Structure to store information about one student
struct Student
{
string ID; // Student ID
}; // Student

// Structure to store information about the entire class of students
// Includes the class title and instructures last name
struct ClassList
{
string classtitle; // Title of class
string instructor; // Last name of instructor
Student students[MAX]; // List of students
long count; // Number of students 0<=count<=MAX
}; // ClassList

// Function prototypes
void readdata(ClassList &);
void displaydata(ClassList);
void savedata(ClassList);
long addstudent(ClassList &,string);

int main()
{
// Declaration of variables
ClassList list; // Complete class list
string ID; // ID of student to add to list
long status; // Status of add

// Read data
cout<<"Reading data. Please wait..."<<endl;
readdata(list);

// Display data
cout<<endl;
displaydata(list);

// Get ID of student to add, quit when "X" or "x" is entered
cout<<"Enter ID of student to add ('X' to terminate) ";
cin>>ID;

// Loop until ID is "X" or "x"
while(ID!="X" && ID!="x")
{
// Clear the screen and print ID
system("cls");
cout<<"Adding ID "<<ID<<endl<<endl;

// Try to add student with this ID
status=addstudent(list,ID);

// Check status and print message
if(status==-1)
{
// Class is full
cout<<"Class is full, could not add student!"<<endl;
}
else if(status==0)
{
// ID already in use
cout<<"ID is already in use. Count not add student!"<<endl;
}
else
{
// Student was added
cout<<"Student was added to the list."<<endl;
}

// Display list and get next student ID to add
cout<<endl;
displaydata(list);
cout<<"Enter ID of student to add ('X' to terminate) ";
cin>>ID;
} // while

// Save data
cout<<endl;
cout<<"Saving data. Please wait..."<<endl;
savedata(list);

// Terminate program
cout<<endl<<"Program has terminated."<<endl;
return 0;
} // main

// Function definitions
void readdata(ClassList &list)
{
// YOU MUST COMPLETE THIS FUNCTION
// Attempt to open data file
ifstream fin("program10.txt");
string temp; // Code read from file

// Read class name and instructor's last name
getline(fin,list.classtitle);
fin>>list.instructor;

// Function reads/stores/counts the ID values
list.count=0;
list[list.count].ID=temp;
list.count++;

// Close file
fin.close();
} // readdata

void displaydata(ClassList list)
{
// Display class name and instructor's last name
cout<<"Course title: "<<list.classtitle<<endl;
cout<<"Instructor: "<<list.instructor<<endl<<endl;

// Print list of IDs
if(list.count==0)
cout<<"No students currently enrolled."<<endl<<endl;
else
{
cout<<"List of student IDs"<<endl;
for(long k=0;k<list.count;k++)
cout<<list.students[k].ID<<endl;
cout<<endl;
} // else
} // displaydata

void savedata(ClassList list)
{
// YOU MUST COMPLETE THIS FUNCTION

} // savedata

long addstudent(ClassList &list,string ID)
{
// YOU MUST COMPLETE THIS FUNCTION
// Attempts to add ID to list
// Returns -1 if list is ALREADY full, 0 if ID is ALREADY in list, 1 if successful
for(long index=0;index<list.count;index++)
{
// Match found?
if(index!=-1||0)

// code is found, return index
return index;
} // for

// code not found, return -1 or 0
return -1||0;
} // addstudent
Topic archived. No new replies allowed.