C++ exercises solutions: find record in list


C++ structure exercise: find record in list

Step 10: Defining the find(struct student st[], int itemcount) function to find the record in the list. This function asks the user to enter the id of the student record. Then this id is checked to make sure it really exists. If the record is found, the information of the target student will be displayed. If the record is not found the message "The record doesn't exist." will be displayed.

void find(struct student st[], int itemcount)
{
  string id;
  cout<<"Enter student's ID:";
  cin>>id;

  int index=search(st,id,itemcount);
  if (index != -1)
  { //display the found record
    cout<<left<<setw(5)<<st[index].stnumber<<setw(20)<<st  [index].stname<<setw(5)<<st[index].sex;
    cout<<setw(5)<<st[index].quizz1<<setw(5)<<st[index].quizz2<<setw(5)<<st[index].assigment
<<setw(5)<<st[index].midterm<<setw(5)<<st[index].final<<setw(5)
<<st[index].total;
   cout<<"\n";

}
  else cout<<"The record doesn't exits.";

 
}




Comments

Beckham comment

 Beckham

for (int i = 0; i < 5; i++)
{
cout<< "Is this correct ";

}


2017-10-03



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.