C++ exercises solutions: view records


C++ structure exercise: view records

Step 5: Defining the viewall(student st[], int itemcount) method to display the list of all records in the set. To display all records, we need a while loop to traverse through the array of student objects.

//function to view all records
void viewall(struct student st[], int itemcount){
   int i=0;
  cout<<left<<setw(5)<<"ID"<<setw(20)<<"NAME"<<setw(5)<<"SEX"
  <<setw(5)<<"Q1"
  <<setw(5)<<"Q2"<<setw(5)<<"As"<<setw(5)<<"Mi"<<setw(5)<<"Fi"
  <<setw(5)<<"TOTAL"<<"\n";
   cout<<"==========================================\n";
  while(i<=itemcount){
     if(st[i].stnumber!=""){
        cout<<left<<setw(5)<<st[i].stnumber<<setw(20)<<st[i].stname<<setw(5)
       <<st[i].sex;
       cout<<setw(5)<<st[i].quizz1<<setw(5)<<st[i].quizz2<<setw(5)<<st[i].assigment
      <<setw(5)<<st[i].midterm<<setw(5)<<st[i]. final<<setw(5)
      <<st[i].total;

      cout<<"\n";}
      i=i+1;

}


}




Comments

sdsad comment

 sdsad

dassa


2016-07-01



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.