Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! I need help on outputting the correct info from users input in C++. My binarySearchSSN function asks user for a SSN from the

Please help! I need help on outputting the correct info from users input in C++. My binarySearchSSN function asks user for a SSN from the sorted SSN pointer array but doesn't print the correct SSN for some.

My header file and cpp file:

image text in transcribed

My SortingSSN function:

image text in transcribed

My main with array of pointers and output showing that it works for some:

image text in transcribed

Please help and thank you.

1 2 3 } void binarySearchSSN(Student studArray[], int size) 1/grades.h #ifndef GRADES_H #define GRADES_H #include #include #include #include #include 138 139 140 141 142 //asks user for SSN cout > ssn; 143 6 7 144 145 146 147 148 149 10 11 using namespace std; struct Student int first = 0, last = size - 1, middle, position = 1; bool found = false; //first array element 7/last array element //midpoint of search //position of search value //flag 12 while(!found && first ssn) //if value is in lower half 24 25 162 void menu(); void readCsvToArray(Student array[], int size, ifstream& file); void sortByLastname (Student studArray[], Student* indexBy Lastname[]); void sortBySSN(Student studArray[], Student* indexBySSN[]); void binarySearchLastName(Student studArray[], int size); void binarySearchSSN(Student studArray[], int size); #endif 163 last = middle - 1; 27 28 165 else 29 166 167 first = middle + 1; //if value is in upper half 168 if(position != -1) //if position was found then output 170 171 172 173 174 175 176 Student s = studArray[position); cout (studArray[j].ssn)) minIndex = j; //here we swap ith position with the minimum index variable Student s = studArray[minIndex]; studArray[minIndex] = studArray[i]; studArray[i] = s; //we assign it to the ith position of indexByssn variable indexBySSN[i] = estudArray[i]; 96 } 15 16 17 // global number of students const int NUM_STUDENTS = 20; int main() Student studArray[NUM STUDENTS]; // array of pointers Student* indexBySSN[NUM_STUDENTS]; Student* indexByLastname[NUM STUDENTS]; 26 //opening csv file ifstream readFile; readFile.open("students.csv"); PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL 1,Alfalfa, Aloysius, 123-45-6789,40,90, 100,83,49,D- 2,Alfred, University, 123-12-1234,41,97,96,97,48,D+, 3, Gerty,Gramma, 567-89-0123,41,80,60,40,44,C 4, Android, Electric, 087-65-4321,42,23,36,45,47,B- 5,Bumpkin, Fred, 456-78-9012,43,78,88,77,45,- 6, Rubble, Betty, 234-56-7890,44,90,80,90,46,C- 7, Noshow, Cecil, 345-67-8901,45,11,-1,4,43,F 8, Buff, Bif,632-79-9939,46,20,30,40,50,B+ 9,Airpump, Andrew, 223-45-6789,49,1,90,100,83,A 10, Backus, Jim, 143-12-1234,48,1,97,96,97,A+, 11, Carnivore, Art, 565-89-0123,44,1,80,60,40,D+ 12, Dandy, Jim, 087-75-4321,47,1,23,36,45,C+ 13, Elephant, Ima, 456-71-9012,45,1,78,88,77,B- 14, Franklin, Benny,234-56-2890,50,1,90,80,90,B- 15, George, Boy, 345-67-3901,40,1,11,-1,4,B 16, Heffalump, Harvey,632-79-9439,30,1,20,30,40, 17, de Paul, Martin, 829-34-3412,34,49,12,90,34,B+ 18, Madrigal, Jay, 309-12-4312,18,2,34,34,5,F 19, Osborne, Demi, 025-24-7821,50,98, 100,89,99,A 20, Garrett, Keith, 723-35-9882,23,53,10,34,84,C+ 1. Print data in ascending order by last name 2. Print data in ascending order by SSN 3. Search by last name 4. Search by SSN 5. Exit Select a Menu:4 Enter SSN: 456-71-9012 ID Last Name First Name SSN Grade 2 Alfred University 123-12-1234 D+ Enter SSN: 723-35-9082 ID Last Name First Name SSNGrade 20 Garrett Keith 723-35-9082 C+ 1 2 3 } void binarySearchSSN(Student studArray[], int size) 1/grades.h #ifndef GRADES_H #define GRADES_H #include #include #include #include #include 138 139 140 141 142 //asks user for SSN cout > ssn; 143 6 7 144 145 146 147 148 149 10 11 using namespace std; struct Student int first = 0, last = size - 1, middle, position = 1; bool found = false; //first array element 7/last array element //midpoint of search //position of search value //flag 12 while(!found && first ssn) //if value is in lower half 24 25 162 void menu(); void readCsvToArray(Student array[], int size, ifstream& file); void sortByLastname (Student studArray[], Student* indexBy Lastname[]); void sortBySSN(Student studArray[], Student* indexBySSN[]); void binarySearchLastName(Student studArray[], int size); void binarySearchSSN(Student studArray[], int size); #endif 163 last = middle - 1; 27 28 165 else 29 166 167 first = middle + 1; //if value is in upper half 168 if(position != -1) //if position was found then output 170 171 172 173 174 175 176 Student s = studArray[position); cout (studArray[j].ssn)) minIndex = j; //here we swap ith position with the minimum index variable Student s = studArray[minIndex]; studArray[minIndex] = studArray[i]; studArray[i] = s; //we assign it to the ith position of indexByssn variable indexBySSN[i] = estudArray[i]; 96 } 15 16 17 // global number of students const int NUM_STUDENTS = 20; int main() Student studArray[NUM STUDENTS]; // array of pointers Student* indexBySSN[NUM_STUDENTS]; Student* indexByLastname[NUM STUDENTS]; 26 //opening csv file ifstream readFile; readFile.open("students.csv"); PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL 1,Alfalfa, Aloysius, 123-45-6789,40,90, 100,83,49,D- 2,Alfred, University, 123-12-1234,41,97,96,97,48,D+, 3, Gerty,Gramma, 567-89-0123,41,80,60,40,44,C 4, Android, Electric, 087-65-4321,42,23,36,45,47,B- 5,Bumpkin, Fred, 456-78-9012,43,78,88,77,45,- 6, Rubble, Betty, 234-56-7890,44,90,80,90,46,C- 7, Noshow, Cecil, 345-67-8901,45,11,-1,4,43,F 8, Buff, Bif,632-79-9939,46,20,30,40,50,B+ 9,Airpump, Andrew, 223-45-6789,49,1,90,100,83,A 10, Backus, Jim, 143-12-1234,48,1,97,96,97,A+, 11, Carnivore, Art, 565-89-0123,44,1,80,60,40,D+ 12, Dandy, Jim, 087-75-4321,47,1,23,36,45,C+ 13, Elephant, Ima, 456-71-9012,45,1,78,88,77,B- 14, Franklin, Benny,234-56-2890,50,1,90,80,90,B- 15, George, Boy, 345-67-3901,40,1,11,-1,4,B 16, Heffalump, Harvey,632-79-9439,30,1,20,30,40, 17, de Paul, Martin, 829-34-3412,34,49,12,90,34,B+ 18, Madrigal, Jay, 309-12-4312,18,2,34,34,5,F 19, Osborne, Demi, 025-24-7821,50,98, 100,89,99,A 20, Garrett, Keith, 723-35-9882,23,53,10,34,84,C+ 1. Print data in ascending order by last name 2. Print data in ascending order by SSN 3. Search by last name 4. Search by SSN 5. Exit Select a Menu:4 Enter SSN: 456-71-9012 ID Last Name First Name SSN Grade 2 Alfred University 123-12-1234 D+ Enter SSN: 723-35-9082 ID Last Name First Name SSNGrade 20 Garrett Keith 723-35-9082 C+

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago

Question

What are the advantages of planning ?

Answered: 1 week ago

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago