The idea of this C++ program is to create an array of pointers to objects of the
ID: 675280 • Letter: T
Question
The idea of this C++ program is to create an array of pointers to objects of the person class. The program can sort a group of person objects based on the alphabetical order of their names.
Requirements:
Create class called person with the following property and methods:
name
salary
void setPerson() //input name and salary
string getName()
float getSalary()
Create a function called bsort to sort pointers to objects.
void bsort(person **, int n, bool s)
n is an the number of person objects stored in the array
s is true, then sort by name;otherwise, sort by salary.
order(person**, person**) //orders two pointers
In the function bsort, call the function order to the pointers contents
In the main function
Create an array of pointers to persons.
Input person objects and put them into the array.
Display the unsorted array of persons
Call the function bsort to sort pointers (by name and by salary)
Display the sorted list
Explanation / Answer
Person *personArray[3]; //pointers to person objects personArray[0] = new Employee("Bill", 1200); personArray[1] = new Customer("Steve"); personArray[2] = new Employee("Bill", 1200); Person *tempArray[3]; string temp1; for(int i=3-1;i>0;i--) { int min = 0; for(int j=1;jprintname(); personArray[min] = personArray[i]; personArray[i] = temp1; } class Person { public: Person(string); virtual void printname() = 0; bool operatorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.