assgn9/StudentDB.cpp
bool StudentDB::add_student(Student * student_details) {
	// Pointer to traverse the list
	//student_element *current;
	// Pointer just before current
	//student_element *trail_current;
		
	// Allocate a new student_element
	//student_element *newelement = new student_element();
	// Place the student pointer into "value" and hook up the pointers
	//newelement->value = student_details;
	//newelement->next = NULL;

	// List is empty and uninitialized
	Student_list_pointer p = database.begin();
	
	if(get_number_correct_records()==0) {
		database.push_back(student_details);
		increment_index_of_last_element();
		set_number_correct_records(get_index_of_last_element()+1);
//cout<<"if statement"<<endl;
		return true;
	}
	
	while(p != database.end()) {
		if(strcmp((*p)->get_ssn().c_str(),
			student_details->get_ssn().c_str()) >0) {
			
			database.insert(p, student_details);
//cout<<"while-if statement"<<endl;
			return true;
		}else if(strcmp((*p)->get_ssn().c_str(),
			student_details->get_ssn().c_str()) == 0) {
			
			cout << "A student with the social security number, "
				<< (*p)->get_ssn()
				<< ", already exists in the database"
				<< endl;
			return false;
		}
		p++;
//cout<<"while-p++"<<endl;
	}
//cout<<"end while loop"<<endl;
	database.push_back(student_details);
	increment_index_of_last_element();
	set_number_correct_records(get_index_of_last_element()+1);
	return true;
}
/**
 * Function to add a student's particulars to the database
 * @param student_details contain the student's particulars
 * @param student student_particulars contain the database
 * If this student's social security number is not found in the database,
 * then the student is added to the database
 * Else, the user is informed that another student has the same social security
 * number as this student. Hence, this student's record cnnot be added to the
 * database.
 */
Function to add a student's particulars to the database
@param student_details contain the student's particulars
@param student student_particulars contain the database
If this student's social security number is not found in the database,
then the student is added to the database
Else, the user is informed that another student has the same social security
number as this student. Hence, this student's record cnnot be added to the
database.
Function to add a student ' s particulars to the database @param student_details contain the student ' s particulars @param student student_particulars contain the database If this student ' s social security number is not found in the database then the student is added to the database Else the user is informed that another student has the same social security number as this student . Hence this student ' s record cnnot be added to the database .
bool StudentDB::add_student(Student * student_details) {
	Student_list_pointer p = database.begin();
	if(get_number_correct_records()==0) {
		database.push_back(student_details);
		increment_index_of_last_element();
		set_number_correct_records(get_index_of_last_element()+1);
		return true;
	}
	while(p != database.end()) {
		if(strcmp((*p)->get_ssn().c_str(),
			student_details->get_ssn().c_str()) >0) {
			database.insert(p, student_details);
			return true;
		}else if(strcmp((*p)->get_ssn().c_str(),
			student_details->get_ssn().c_str()) == 0) {
			cout << "A student with the social security number, "
				<< (*p)->get_ssn()
				<< ", already exists in the database"
				<< endl;
			return false;
		}
		p++;
	}
	database.push_back(student_details);
	increment_index_of_last_element();
	set_number_correct_records(get_index_of_last_element()+1);
	return true;
}
bool StudentDB :: add_student ( Student * student_details ) { Student_list_pointer p = database . begin ( ) ; if ( get_number_correct_records ( ) == 0 ) { database . push_back ( student_details ) ; increment_index_of_last_element ( ) ; set_number_correct_records ( get_index_of_last_element ( ) + 1 ) ; return true ; } while ( p != database . end ( ) ) { if ( strcmp ( ( * p ) -> get_ssn ( ) . c_str ( ) , student_details -> get_ssn ( ) . c_str ( ) ) > 0 ) { database . insert ( p , student_details ) ; return true ; } else if ( strcmp ( ( * p ) -> get_ssn ( ) . c_str ( ) , student_details -> get_ssn ( ) . c_str ( ) ) == 0 ) { cout << " " << ( * p ) -> get_ssn ( ) << " " << endl ; return false ; } p ++ ; } database . push_back ( student_details ) ; increment_index_of_last_element ( ) ; set_number_correct_records ( get_index_of_last_element ( ) + 1 ) ; return true ; }
Function to add a student's particulars to the database
 @param student_details contain the student's particulars
 @param student student_particulars contain the database
 If this student's social security number is not found in the database,
 then the student is added to the database
 Else, the user is informed that another student has the same social security
 number as this student.
Function to add a student ' s particulars to the database @param student_details contain the student ' s particulars @param student student_particulars contain the database If this student ' s social security number is not found in the database then the student is added to the database Else the user is informed that another student has the same social security number as this student .
// Pointer to traverse the list //student_element *current; // Pointer just before current //student_element *trail_current; // Allocate a new student_element //student_element *newelement = new student_element(); // Place the student pointer into "value" and hook up the pointers //newelement->value = student_details; //newelement->next = NULL; // List is empty and uninitialized //cout<<"if statement"<<endl; //cout<<"while-if statement"<<endl; //cout<<"while-p++"<<endl; //cout<<"end while loop"<<endl;