Complete the code below by adding a search function that searches for a student
ID: 3659265 • Letter: C
Question
Complete the code below by adding a search function that searches for a student based on the id and displays the student first name, last name, ID and grade information i.e
sample output
Enter the ID you are searching: 5555
Dan Martin 5555 86
#include <iostream>
#include <string>
using namespace std;
struct Student{
string firstname, lastname;
int ID;
int score;
};
int main()
{
int counter = 1;
cout<<"Enter the size of the array: ";
int sz; cin>>sz;
Student *sPtr = new Student[sz];
cout<<"Let's populate the array ";
for(int i=0; i<sz; i++)
{
cout<<"Enter the firt name followed by last name: ";
cin>>sPtr[i].firstname;
cin>>sPtr[i].lastname;
cout<<"Enter ID for "<<sPtr[i].firstname<<": ";
cin>>sPtr[i].ID;
cout<<"Enter score for "<<sPtr[i].firstname<<": ";
cin>>sPtr[i].score;
cout<<endl;
}
cout<<"Let's print the class list ";
cout<< " Sl FirstName LastName ID Grade";
for(int i=0; i< sz; i++) {
cout<< " "<<counter++<<" "<< sPtr[i].firstname<< " "<< sPtr[i].lastname<< " "<<sPtr[i].ID<< " "<< sPtr[i].score<<endl;
}
}
Explanation / Answer
#include #include using namespace std; struct Student{ string firstname, lastname; int ID; int score; }; void search_on_id(Student *sPtr,int sz,int id) { int i; for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.