// Function file
DomesticPtr searchRS(DomesticStudent *head, int RS)
{
//head and temp point to first node
// intialize tmp to be head
DomesticStudent* tmp = head;
if(tmp == NULL)//check to see if its an empty list
{
cout << "No research score found with that value" << endl;
}
else
{
while(tmp != NULL)//reads the list until tail which is NULL
{
while(tmp->getLink() != NULL && tmp->getresearchScoreD() != RS )//creates a while loop checking each node to see if it is the targeted value
{
tmp= head->next;
// tmp=tmp->getLink();//traverses the loop to point to next node
}
if(tmp->getresearchScoreD() == RS)// checks to see if the next node research score match target
{
// unlink node from list because already found
cout<< " " << tmp->getfirstNameD()<< " " << tmp->getlastNameD() << " " << tmp-> getprovince() << " " << tmp->getcgpaD() << " "<< tmp-> getresearchScoreD() <<" "<< tmp-> getidD()<< endl;
return tmp;
// searchRS(tmp->next, RS);//recursive call for rest of the list
}
tmp=head->next;
}
}//else
}
//Main
int RS;
int cgpa;
int ID;
string input;
cout << "Would you like to search for research score(RS),cgpa(cgpa),or student id(ID)" << endl;
cin >> input;
if(input =="RS")
{
int RS= 0;
cout << "Give vaule of research score" <<endl;
cin >> RS;
if(RS < 0 || RS > 100)//error statement on user input
{
cout << "Invalid research score, please restart program again"<< endl;
}
searchRS( head, RS);
}
//header
class DomesticStudent: public Student
{
public:
DomesticStudent();
// ~DomesticStudent();
DomesticStudent( DomesticStudent *next, string firstNameD, string lastNameD, string province, float cgpaD, int researchScoreD, int idD); //default constructor
DomesticStudent *getLink();
void setLink(DomesticStudent *next);
//~DomesticStudent();
string getfirstNameD(); // intialize member function
string getlastNameD();
string getprovince();
float getcgpaD();
int getresearchScoreD();
int getidD();
void setfirstNameD(string FND);
void setlastNameD(string LND);
void setprovince(string pro);
void setcgpaD(float c_g_p_a_D);
void setresearchScoreD(int RS_D);
void setidD(int i_d_D);
DomesticStudent *next;
//DomesticStudent* list_head();
friend int compareCGPA(DomesticStudent* cgpaC, DomesticStudent* cgpaE); //friend function declaration for comparison
friend int compareResearchScore(DomesticStudent* RSA, DomesticStudent* RSB);
friend int compareFirstName(DomesticStudent FN, DomesticStudent FN1);
friend int compareLastName(DomesticStudent LN, DomesticStudent LN1);
friend int compareProvince(DomesticStudent* P, DomesticStudent* P1);
friend ostream& operator<<(ostream &out,const DomesticStudent& d); // friend function declaration for overloading operator
friend void bubblesort(DomesticStudent* head);
private:
string firstNameD;
string lastNameD;
string province;
float cgpaD;
int researchScoreD;
int idD;
float cgpa1;
float cgpa2;
DomesticStudent *link; // intialize member varibles
};
typedef DomesticStudent* DomesticPtr;
DomesticStudent* sortedmerge(DomesticStudent* a, DomesticStudent* b); //called in int main
void frontnback(DomesticStudent* line, DomesticStudent** frontref, DomesticStudent** backref);
void mergesort(DomesticStudent** headref);
void head_insert(DomesticPtr& head, string firstNameD, string lastNameD, string province, float cgpaD, int researchScoreD, int idD);
DomesticPtr searchRS(DomesticStudent*, int RS);
DomesticPtr searchcgpa(DomesticStudent*, int cgpa);
DomesticPtr searchID(DomesticStudent*, int ID);
trying to run a program that will read a file and print a linked list. One of my functions requires me search through the list and print out data. But it requires me to print out multiple nodes that have the same value. Sorry I am really new to c++ any feedback would be gratefully aprreciated.
Aucun commentaire:
Enregistrer un commentaire