// Ch. 13 Demo Program #6
// Mr. Minich
// Purpose - to demonstrate passing struct's as const reference parameters. 

// YOU MUST DELETE THE CONST KEYWORDS IN ORDER TO SUCCESSFULLY COMPILE & 
//    EXECUTE THIS PROGRAM

#include <iostream.h>

struct student
{
	int examScore;			// student's exam score
	char firstInitial;		// student's first initial
	char secondInitial;		// student's second initial
};

void display1(student &);		// used to demonstrate the danger of not using const 
					//   reference parameters
void display2(const student &);		// used to demonstrate the caution of using const 
					//   reference parameters

// struct's should be passed by reference to save memory, however as we will see, it
//    may be wise to pass structs as const reference parameters to avoid accidentally
//    modifying data


int main()
{
	student teachersPet;		// used to demonstrate use of const reference 
					//    parameters

	teachersPet.firstInitial = 'J';
	teachersPet.secondInitial = 'D';
	teachersPet.examScore = 99;

	cout << "With display1, the teacher's pet info is:\t";
	
	display1(teachersPet);

	cout << "With display2, the teacher's pet info is:\t";
	
	display2(teachersPet);

	return 0;

}// end of main

void display1(student & incoming)
{
	cout << incoming.firstInitial << incoming.secondInitial << " scored " << incoming.examScore << endl;
}// end of display1

void display2(const student & incoming)
// const is to be used in front of a parameter if you do not intend to modify the 
//   value of its corresponding argument in the calling function. 
{
	incoming.examScore += 10;	// accidental modification of examScore
	
	cout << incoming.firstInitial << incoming.secondInitial << "scored " << incoming.examScore << endl;
}// end of display1