cs162/assignments/assignment1/magic.cpp
/*********************************************************************
 * ** Function: print_or_file_effect_student
 * ** Description: This function creates the correct array based on if the user is a student or not and then gives the user the option to print or save the outcome
 * ** Parameters: int numb_spells, int poisons, int bubbles, int memory_losses, int fires, spell *bubble, spell *memory_loss, spell *fire
 * ** Pre-Conditions: user has selected to sort by effect and is a student
 * ** Post-Conditions: prints or saves outcome correctly
 * *********************************************************************/
print_or_file_effect_student
Description: This function creates the correct array based on if the user is a student or not and then gives the user the option to print or save the outcome
Parameters: int numb_spells, int poisons, int bubbles, int memory_losses, int fires, spell *bubble, spell *memory_loss, spell *fire
Pre-Conditions: user has selected to sort by effect and is a student
Post-Conditions: prints or saves outcome correctly
print_or_file_effect_student Description : This function creates the correct array based on if the user is a student or not and then gives the user the option to print or save the outcome Parameters : int numb_spells int poisons int bubbles int memory_losses int fires spell * bubble spell * memory_loss spell * fire Pre - Conditions : user has selected to sort by effect and is a student Post - Conditions : prints or saves outcome correctly
void print_or_file_effect_student(int numb_spells, int poisons, int deaths, int bubbles, int memory_losses, int fires, spell *bubble, spell *memory_loss, spell *fire) {
	int choice = 1;
	cout << endl;
	cout << "How would you like the information recorded?" << endl;
	cout << "Print to screen (Press 1)" << endl;
	cout << "Print to file (Press 2)" << endl;
	cin >> choice;	
	int num = numb_spells - (poisons + deaths);
	spell *temp = new spell[num];
	int index3 = 0;
	for(int i = 0; i < bubbles; i++) {
		temp[index3] = bubble[i];
		index3++;
	}
	for(int i = 0; i < memory_losses; i++) {
		temp[index3] = memory_loss[i];
		index3++;
	}
	for(int i = 0; i < fires; i++) {
		temp[index3] = fire[i];
		index3++;
	}	
	if(choice == 1) {
		cout << endl;
		for(int i = 0; i < num; i++) {
			cout << temp[i].effect << " " << temp[i].name << endl;
		}
	}
	else {
		string file_name;
		cout << "Name of file: ";
		cin >> file_name;
		ofstream fout;
		do {
			fout.open(file_name.c_str(), ios::out | ios::trunc);
		} while(!fout.is_open());
		for(int i = 0; i < num; i++) {
			fout << temp[i].effect << " " << temp[i].name << endl;
		}
		cout << "File successfully created!" << endl;
		fout.close();
	}
	delete [] temp;
	temp = NULL;
}
void print_or_file_effect_student ( int numb_spells , int poisons , int deaths , int bubbles , int memory_losses , int fires , spell * bubble , spell * memory_loss , spell * fire ) { int choice = 1 ; cout << endl ; cout << " " << endl ; cout << " " << endl ; cout << " " << endl ; cin >> choice ; int num = numb_spells - ( poisons + deaths ) ; spell * temp = new spell [ num ] ; int index3 = 0 ; for ( int i = 0 ; i < bubbles ; i ++ ) { temp [ index3 ] = bubble [ i ] ; index3 ++ ; } for ( int i = 0 ; i < memory_losses ; i ++ ) { temp [ index3 ] = memory_loss [ i ] ; index3 ++ ; } for ( int i = 0 ; i < fires ; i ++ ) { temp [ index3 ] = fire [ i ] ; index3 ++ ; } if ( choice == 1 ) { cout << endl ; for ( int i = 0 ; i < num ; i ++ ) { cout << temp [ i ] . effect << " " << temp [ i ] . name << endl ; } } else { string file_name ; cout << " " ; cin >> file_name ; ofstream fout ; do { fout . open ( file_name . c_str ( ) , ios :: out | ios :: trunc ) ; } while ( ! fout . is_open ( ) ) ; for ( int i = 0 ; i < num ; i ++ ) { fout << temp [ i ] . effect << " " << temp [ i ] . name << endl ; } cout << " " << endl ; fout . close ( ) ; } delete [ ] temp ; temp = NULL ; }
** Function: print_or_file_effect_student
 ** Description: This function creates the correct array based on if the user is a student or not and then gives the user the option to print or save the outcome
 ** Parameters: int numb_spells, int poisons, int bubbles, int memory_losses, int fires, spell *bubble, spell *memory_loss, spell *fire
 ** Pre-Conditions: user has selected to sort by effect and is a student
 ** Post-Conditions: prints or saves outcome correctly
** Function : print_or_file_effect_student ** Description : This function creates the correct array based on if the user is a student or not and then gives the user the option to print or save the outcome ** Parameters : int numb_spells int poisons int bubbles int memory_losses int fires spell * bubble spell * memory_loss spell * fire ** Pre - Conditions : user has selected to sort by effect and is a student ** Post - Conditions : prints or saves outcome correctly