Tips for Lab Chapter 8

Lesson 8-2

Ex. 2

int main()
{
	ifstream inData;
	inData.open("data.in");
	
	//Pass the input file variable inData to Print() function
	//and let the function read the data item
	Print(inData);
}

void Print(ifstream & myInput)
{
	string name;
	string address;
	
	//myInput is now "pointing" to data.in file
	myInput >> name;
	...
}

Lesson 8-3

Ex 1:


void Print(int numSigns)
{
	//First, consider printing a rectangle (numSigns x numSigns/2)

	//Use double loops: the outer loop controls printing rows and 
	//the inner loop prints columns

	int row = 0;
	int col;

	while(row < numSigns/2)
	{
		col = 0;
		while(col < numSigns)
		{
			//Since it is a "frame," print all signs on the first and last 
			//rows. On the middle rows, print signs only on the first and 
			//last column and white spaces elsewhere. 
		}
	} 
}