Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please check my c++ codes please I have do write twenty students records sorted

ID: 3543893 • Letter: P

Question

Please check my c++ codes please


I have do write twenty students records sorted by ID .

and display 20 student records and using recursive binary search to search one studet-Id in the vector, also searched Id at the end of the vector, and search ID which is not in the vector.

so FOr each searchm I have to print out the Id to be searched and the searched result with the found entire record.


but mine is keepgeeting error and confuse to using a vector

please check my codes and fix it please so.~~

thank u~


#ifndef pro4_H

#define pro4_H


#include<iostream>

#include <string>

#include<iomanip>

#include<vector>


using namespace std;



class Student

{

private:

string nam;

int iden;

double grade;

string address;

int test1;

int test2;

int test3;

int test4;

int test5;

int test6;

int test7;

int test8;

int test9;

int test10;



public:

void setRecord( string name, int ID, double GPA, string addr, int t1,int t2,int t3,int t4,int t5,int t6,int t7,int t8,int t9,int t10);

int binarySearch(int array[], int first, int last, int value);

void print();

};




void Student::setRecord( string name, int ID, double GPA, string addr, int t1,int t2,int t3,int t4,int t5,int t6,int t7,int t8,int t9,int t10)

{


nam=name;

iden=ID;

grade=GPA;

address=addr;

test1=t1;

test2=t2;

test3=t3;

test4=t4;

test5=t5;

test6=t6;

test7=t7;

test8=t8;

test9=t9;

test10=t10;

}


int Student::binarySearch(int array[],int first,int last, int value)

{

const int size =20;

int middle;

value= iden;

if(first >last)

return -1;

middle=(first+last)/2;

if(array[middle]==value)

return middle;

if(array[middle]<value)

return binarySearch(array, middle+1,last,value);

else

return binarySearch(array,first,middle-1,value);

}


void Student::print()

{


cout<<nam<<" "<<iden<<" "<< grade<<" "<<address<<" "<<test1<<" "<<test2<<" "<<test3<<" "<<test4<<" "<<test5<<" "<<test6<<" "<<test7<<" "

<<test8<<" "<<test9<<" " <<test10<<" "<<endl;


}

#endif



#include "pro4.h"

#include <iostream>

#include <string>

#include<vector>


using namespace std;


int main()

{

vector<Student> v(20);

v[0].setRecord("Ryan",1234,3.2, "Austin",50,90,80,57,87,98,87,39,70,89);

v[1].setRecord("Joo", 2345,3.4, "Dallas",56,87,67,98,67,90,56,45,67,84);

v[2].setRecord("Choo",3452,3.4, "Austin",76,90,89,90,93,90,98,90,99,76);

v[3].setRecord("Jay", 4123, 2.2, "San Marcos",45,67,56,44,34,23,76,54,34,43);

v[4].setRecord("Ryan",2345,4.0,"Houston", 34,25,56,78,72,81,67,89,67,56);

v[5].setRecord("koo", 3456,2.8,"Austin", 36,23,44,67,54,76,34,56,43,23);

v[6].setRecord("Lee", 9808,3.1,"Dallas",45,65,76,34,87,54,67,76,89,56);

v[7].setRecord("Kim", 7634,2.3,"Houston",45,78,97,67,89,90,89,99,87,65);

v[8].setRecord("Lisa",4560,3.5,"Dallas",67,89,90,87,89,78,67,56,90,87);

v[9].setRecord("Eric",9087,3.2,"Austin",34,56,78,87,98,67,78,67,78,87);

v[10].setRecord("Jean",8763,2.4,"Dallas",34,90,98,96,90,87,85,65,74,70);

v[11].setRecord("Bryan",7834,3.2,"Houston",87,87,89,87,67,89,67,76,76,56);

v[12].setRecord("Emi",9823,3.1,"Kyle",97,67,88,87,67,89,78,98,56,88);

v[13].setRecord("Tony",3423,3.0,"Corpus", 87,54,66,45,34,89,87,56,89,90);

v[14].setRecord("Tom",4567,2.4,"Plano", 54,67,54,78,98,90,778,87,49,87);

v[15].setRecord("Tylor",4321,1.8,"Dallas",34,43,34,56,12,23,0,0,12,43);

v[16].setRecord("Leah",2367,2.1,"Austin",43,56,78,99,87,65,43,44,78,65);

v[17].setRecord("Diana",5664,2.7,"Houston",32,56,87,97,67,87,98,67,67,78);

v[18].setRecord("Derrick",7964,2.1,"Plano",54,67,87,56,45,78,98,65,86,89);

v[19].setRecord("Corry",2317,3.3,"San Antonio",34,78,90,87,89,67,85,87,89,65);

v[20].setRecord("Ray",1235,3.8,"Austin",87,89,98,78,89,90,98,87,90,78);

cout<< print(v)<<endl;

int Id;

int result;

cout<<"Enter the Student ID number to search for: "<<endl;

cin>>Id;

result= binarySearch(v,0,SIZE-1,Id);

if(result==-1)

cout<<" Error";

else

{

cout<<"That Id is found at element "<< result;

cout<<" in the vector "<<endl;

cout<<print(v);


}

system("PAUSE");


return 0;

}


Explanation / Answer

THIS IS THE MOST POSSIBLE ERROR : PLEASE MAKE THIS CHANGE AND NOW COMPILE


int Student::binarySearch(int array[],int first,int last, int value)

{

const int size =20;

int middle;

///value= iden;

if(first >last)

return -1;

middle=(first+last)/2;

if(array[middle]==value)

return middle;

if(array[middle]<value)

return binarySearch(array, middle+1,last,value);

else

return binarySearch(array,first,middle-1,value);

}