/*	Student Records program */

#include <iostream.h>
//#include <lvp\bool.h>
#include <lvpvector.h>
#include <lvpstring.h>
#include <conio.h>

using namespace std;	// October 5, 2001

struct StudentType {
	lvpstring Last;
	lvpstring First;
	int Class;
};
//--------------------------------------------------------------------------------
void GetStudentData(StudentType &Student)
/*	Obtains values for all data members of Student from user
	Post: Values entered for data members of Student            */
{
	cout << "Enter last name: ";
	cin >> Student.Last;
	cout << "Enter first name: ";
	cin >> Student.First;
	cout << "Enter class: ";
	cin >> Student.Class;
}
//--------------------------------------------------------------------------------
void DisplayStudentData(const StudentType &Student)
/* Displays the data in Student, one element per line
	Post: Data in Student displayed                                */
{
	cout << Student.First << " " << Student.Last << "  " 
		<< Student.Class << endl;
}
//--------------------------------------------------------------------------------
struct SchoolType {
	SchoolType();    // Constructor 
	const int SizeChange;    // Amount to increase array by
	int NumStudents;    // Current number of students
	lvpvector<StudentType> Students;    // Student records
};
//--------------------------------------------------------------------------------
SchoolType::SchoolType()
	: SizeChange(10), Students(10), NumStudents(0)
/*	Start with space for 10 students, increase by SizeChange when needed */
{
}
//--------------------------------------------------------------------------------
void DisplaySchool(const SchoolType &School)
/*	Displays a list of all students in School, one per line
	Post: Elements of School displayed                            */
{
	for (int i=0; i<School.NumStudents; i++)
		DisplayStudentData(School.Students[i]);
}
//--------------------------------------------------------------------------------
void AddStudent(SchoolType &School, const StudentType &NewStudent)
/*	Adds NewStudent to School, increasing size of School.Students if needed
	Post: NewStudent added to School                                                                */
{
	if (School.NumStudents == School.Students.length())
		School.Students.resize(School.NumStudents+School.SizeChange);
	School.Students[School.NumStudents] = NewStudent;
	School.NumStudents++;
}
//--------------------------------------------------------------------------------
int main()
{
	StudentType Student;
	SchoolType School;

	bool Quit=false;
	do {
		cout << "Press choice Add, Display, Quit: ";
		char Choice;
		cin >> Choice;
		cout << endl;
		switch (Choice) {
			case 'A':
			case 'a':	GetStudentData(Student);
							AddStudent(School, Student);
							break;
			case 'D':
			case 'd':	DisplaySchool(School);
							break;
			case 'q':
			case 'Q':	Quit=true; break;
		}
	} while(!Quit);
	return(0);
}

