assgn5/yassign5.cpp
bool read_input(string inputfilename,
	student student_particulars[MAXIMUM_NUMBER_OF_STUDENTS]) {
	
	// Create input file stream
	ifstream inputfile;
	// Open the input file
	inputfile.open(inputfilename.c_str());
	// Assertion to check if the input file exist
	if(inputfile == NULL) {
		cout << "Input file, with the filename " << inputfilename
			<< ", does not exist!" << endl;
		return false;
	}
	
	
	/**
	 * Declare and instantiate some variables to temporarily store data
	 * before processing them
	 */
	// Last name of the student
	string lastname="";
	// First name of the student
	string firstname="";
	// Student's social security number
	string socialsecuritynumber="";
	// Student's phone number in the united states
	string phonenumber="";
	// Student's age
	int studentage=0;
	// Number of errors found in the student record
	int errors=0;
	// Current index in which correct student record should be stored
	int correct_index;
		
	/**
	 * Current index of the record of student paticulars
	 * that is being enumerated
	 */
	int i=0;
	// Start processing the data in the table
	while((inputfile != NULL) && (i<MAXIMUM_NUMBER_OF_STUDENTS)) {
		// Stop processing the input file once its end has been reached
		if ( (inputfile >> lastname	>> firstname >> socialsecuritynumber
			>> phonenumber >> studentage) == NULL) {
			break;
		}
		
		/**
		 * Check if the student particulars are valid...
		 * If any of the student particulars is invalid,
		 * ignore this current line in the input file and
		 * skip to the next
		 */
		if(!check_last_name(lastname)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad last name" << endl;
			cout << "\t\t Last name of the student should only contain "
				<< "alphabets" << endl;
			errors++;
			continue;
		}else if(!check_first_name(firstname)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad first name" << endl;
			cout << "\t\t First name of the student should only contain "
				<< "alphabets" << endl;
			errors++;
			continue;
		}else if(!check_social_security_number(socialsecuritynumber)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad social security number" << endl;
			cout << "\t\t Security numbers should contain dashes at the"
				<< "4th and 7th characters, and digits otherwise" << endl;
			errors++;
			continue;
		}else if(!check_phone_number(phonenumber)) {
			cout << "\t Ignoring Record Number " << i 
				<< " - bad phone number" << endl;
			cout << "\t\t Phone numbers should be given in this format: "
				<< "(XXX)XXX-XXXX, where each X is a digit" << endl;
			errors++;
			continue;
		}else if(!check_age(studentage)) {
			cout << "\t Ignoring Record Number " << i << " - bad age" << endl;
			cout << "\t\t Age of the student should be between 1 and 120, "
				<< "inclusive" << endl;
			errors++;
			continue;
		}
		
		/**
		 * Student's first and last names, social security number, phone
		 * number, and age are valid...
		 * Enter these details into the appropriate place in the records
		 */
		correct_index=i-errors;
		correct_student_records[correct_index].last_name = lastname;
		correct_student_records[correct_index].first_name = firstname;
		correct_student_records[correct_index].social_security_number
			= socialsecuritynumber;
		correct_student_records[correct_index].phone_number = phonenumber;
		correct_student_records[correct_index].age = studentage;
		
		i++;
	}
	
	cout << endl;
	cout << "Processed " << i << " student records" << endl;
	cout << errors << " errors were found" << endl;
	cout << endl;
	// Determine the number of correct student records
	number_correct_records=i-errors;
	
	// Close the input filestream
	inputfile.close();
	
	return true;
}
/**
 * Fuunction to read input from a file and process it
 * #Read the particulars of each student in a line with the following format:
 *	Last_name	First_name	Social_Security_Number	Telephone	Age
 * Assume that the input file will contain data in this format
 * @param inputfilename is the name of the input file
 * @param student student_particulars contains a table of students' particulars
 */
Fuunction to read input from a file and process it
#Read the particulars of each student in a line with the following format:
Last_name       First_name      Social_Security_Number  Telephone       Age
Assume that the input file will contain data in this format
@param inputfilename is the name of the input file
@param student student_particulars contains a table of students' particulars
Fuunction to read input from a file and process it #Read the particulars of each student in a line with the following format : Last_name First_name Social_Security_Number Telephone Age Assume that the input file will contain data in this format @param inputfilename is the name of the input file @param student student_particulars contains a table of students ' particulars
bool read_input(string inputfilename,
	student student_particulars[MAXIMUM_NUMBER_OF_STUDENTS]) {
	ifstream inputfile;
	inputfile.open(inputfilename.c_str());
	if(inputfile == NULL) {
		cout << "Input file, with the filename " << inputfilename
			<< ", does not exist!" << endl;
		return false;
	}
	string lastname="";
	string firstname="";
	string socialsecuritynumber="";
	string phonenumber="";
	int studentage=0;
	int errors=0;
	int correct_index;
	int i=0;
	while((inputfile != NULL) && (i<MAXIMUM_NUMBER_OF_STUDENTS)) {
		if ( (inputfile >> lastname	>> firstname >> socialsecuritynumber
			>> phonenumber >> studentage) == NULL) {
			break;
		}
		if(!check_last_name(lastname)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad last name" << endl;
			cout << "\t\t Last name of the student should only contain "
				<< "alphabets" << endl;
			errors++;
			continue;
		}else if(!check_first_name(firstname)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad first name" << endl;
			cout << "\t\t First name of the student should only contain "
				<< "alphabets" << endl;
			errors++;
			continue;
		}else if(!check_social_security_number(socialsecuritynumber)) {
			cout << "\t Ignoring Record Number " << i <<
				" - bad social security number" << endl;
			cout << "\t\t Security numbers should contain dashes at the"
				<< "4th and 7th characters, and digits otherwise" << endl;
			errors++;
			continue;
		}else if(!check_phone_number(phonenumber)) {
			cout << "\t Ignoring Record Number " << i 
				<< " - bad phone number" << endl;
			cout << "\t\t Phone numbers should be given in this format: "
				<< "(XXX)XXX-XXXX, where each X is a digit" << endl;
			errors++;
			continue;
		}else if(!check_age(studentage)) {
			cout << "\t Ignoring Record Number " << i << " - bad age" << endl;
			cout << "\t\t Age of the student should be between 1 and 120, "
				<< "inclusive" << endl;
			errors++;
			continue;
		}
		correct_index=i-errors;
		correct_student_records[correct_index].last_name = lastname;
		correct_student_records[correct_index].first_name = firstname;
		correct_student_records[correct_index].social_security_number
			= socialsecuritynumber;
		correct_student_records[correct_index].phone_number = phonenumber;
		correct_student_records[correct_index].age = studentage;
		i++;
	}
	cout << endl;
	cout << "Processed " << i << " student records" << endl;
	cout << errors << " errors were found" << endl;
	cout << endl;
	number_correct_records=i-errors;
	inputfile.close();
	return true;
}
bool read_input ( string inputfilename , student student_particulars [ MAXIMUM_NUMBER_OF_STUDENTS ] ) { ifstream inputfile ; inputfile . open ( inputfilename . c_str ( ) ) ; if ( inputfile == NULL ) { cout << " " << inputfilename << " " << endl ; return false ; } string lastname = " " ; string firstname = " " ; string socialsecuritynumber = " " ; string phonenumber = " " ; int studentage = 0 ; int errors = 0 ; int correct_index ; int i = 0 ; while ( ( inputfile != NULL ) && ( i < MAXIMUM_NUMBER_OF_STUDENTS ) ) { if ( ( inputfile >> lastname >> firstname >> socialsecuritynumber >> phonenumber >> studentage ) == NULL ) { break ; } if ( ! check_last_name ( lastname ) ) { cout << " \t " << i << " " << endl ; cout << " \t \t " << " " << endl ; errors ++ ; continue ; } else if ( ! check_first_name ( firstname ) ) { cout << " \t " << i << " " << endl ; cout << " \t \t " << " " << endl ; errors ++ ; continue ; } else if ( ! check_social_security_number ( socialsecuritynumber ) ) { cout << " \t " << i << " " << endl ; cout << " \t \t " << " " << endl ; errors ++ ; continue ; } else if ( ! check_phone_number ( phonenumber ) ) { cout << " \t " << i << " " << endl ; cout << " \t \t " << " " << endl ; errors ++ ; continue ; } else if ( ! check_age ( studentage ) ) { cout << " \t " << i << " " << endl ; cout << " \t \t " << " " << endl ; errors ++ ; continue ; } correct_index = i - errors ; correct_student_records [ correct_index ] . last_name = lastname ; correct_student_records [ correct_index ] . first_name = firstname ; correct_student_records [ correct_index ] . social_security_number = socialsecuritynumber ; correct_student_records [ correct_index ] . phone_number = phonenumber ; correct_student_records [ correct_index ] . age = studentage ; i ++ ; } cout << endl ; cout << " " << i << " " << endl ; cout << errors << " " << endl ; cout << endl ; number_correct_records = i - errors ; inputfile . close ( ) ; return true ; }
Fuunction to read input from a file and process it
 #Read the particulars of each student in a line with the following format:
      Last_name       First_name      Social_Security_Number  Telephone       Age
 Assume that the input file will contain data in this format
 @param inputfilename is the name of the input file
 @param student student_particulars contains a table of students' particulars
Fuunction to read input from a file and process it #Read the particulars of each student in a line with the following format : Last_name First_name Social_Security_Number Telephone Age Assume that the input file will contain data in this format @param inputfilename is the name of the input file @param student student_particulars contains a table of students ' particulars
// Create input file stream // Open the input file // Assertion to check if the input file exist /**
	 * Declare and instantiate some variables to temporarily store data
	 * before processing them
	 */ // Last name of the student // First name of the student // Student's social security number // Student's phone number in the united states // Student's age // Number of errors found in the student record // Current index in which correct student record should be stored /**
	 * Current index of the record of student paticulars
	 * that is being enumerated
	 */ // Start processing the data in the table // Stop processing the input file once its end has been reached /**
		 * Check if the student particulars are valid...
		 * If any of the student particulars is invalid,
		 * ignore this current line in the input file and
		 * skip to the next
		 */ /**
		 * Student's first and last names, social security number, phone
		 * number, and age are valid...
		 * Enter these details into the appropriate place in the records
		 */ // Determine the number of correct student records // Close the input filestream