cs162/assignments/assignment1/magic.cpp
/*********************************************************************
 * ** Function: print_or_file_effect
 * ** Description: This function will print to screen or save to file an array of spells that have been sorted according to the users' status.
 * ** Parameters: spellbook *temp, int num_books
 * ** Pre-Conditions: user selected to print/save spells by effect
 * ** Post-Conditions: spells are printed/saved in order of effect
 * *********************************************************************/
print_or_file_effect
Description: This function will print to screen or save to file an array of spells that have been sorted according to the users' status.
Parameters: spellbook *temp, int num_books
Pre-Conditions: user selected to print/save spells by effect
Post-Conditions: spells are printed/saved in order of effect
print_or_file_effect Description : This function will print to screen or save to file an array of spells that have been sorted according to the users ' status . Parameters : spellbook * temp int num_books Pre - Conditions : user selected to print / save spells by effect Post - Conditions : spells are printed / saved in order of effect
void print_or_file_effect(spellbook *temp, int num_books) {
	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;
	if(choice == 1) {
		cout << endl;
		for(int i = 0; i < num_books; i++) {
			for(int j = 0; j < temp[i].num_spells; j++) {
				cout << temp[i].s[j].effect << " " << temp[i].s[j].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_books; i++) {
			for(int j = 0; j < temp[i].num_spells; j++) {
				fout << temp[i].s[j].effect << " " << temp[i].s[j].name << endl;
			}
		}
		cout << "File successfully created!" << endl;
		fout.close();
	}
}
void print_or_file_effect ( spellbook * temp , int num_books ) { int choice = 1 ; cout << endl ; cout << " " << endl ; cout << " " << endl ; cout << " " << endl ; cin >> choice ; if ( choice == 1 ) { cout << endl ; for ( int i = 0 ; i < num_books ; i ++ ) { for ( int j = 0 ; j < temp [ i ] . num_spells ; j ++ ) { cout << temp [ i ] . s [ j ] . effect << " " << temp [ i ] . s [ j ] . 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_books ; i ++ ) { for ( int j = 0 ; j < temp [ i ] . num_spells ; j ++ ) { fout << temp [ i ] . s [ j ] . effect << " " << temp [ i ] . s [ j ] . name << endl ; } } cout << " " << endl ; fout . close ( ) ; } }
** Function: print_or_file_effect
 ** Description: This function will print to screen or save to file an array of spells that have been sorted according to the users' status.
** Function : print_or_file_effect ** Description : This function will print to screen or save to file an array of spells that have been sorted according to the users ' status .