76 976
Assignments Done
Successfully Done
In June 2019

Answer to Question #50603 in C++ for Umer

Question #50603
Modify the person class in the PERSORT program in this chapter so that it includes not
only a name, but also a salary item of type float representing the person’s salary.You’ll need to change the setName() and printName() member functions to setData() and printData(), and include in them the ability to set and display the salary as well as the name. You’ll also need a getSalary() function. Using pointer notation, write a salsort() function that sorts the pointers in the persPtr array by salary rather than by name. Try doing all the sorting in salsort(),rather than calling another function as
PERSORT does. If you do this, don’t forget that -> takes precedence over *,so you’ll need
to say
if( (*(pp+j))->getSalary() > (*(pp+k))->getSalary() )
{ /* swap the pointers */ }
Expert's answer
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <string>
using namespace std;
class Person{
void SetData(string newName, float newSalary)
name = newName;
salary = newSalary;
void PrintData()
cout<<"Name : "<<name<<endl;
cout<<"Salary : "<<salary<<endl;
float GetSalary(){
return salary;
string name;
float salary;
void salsort(Person *person, int size);
int main(){
Person *sal = new Person[5];
string _name;
float _salary;
for(int i = 0; i < 3; i++)
cout<<"Enter name : ";
cout<<"Enter salary : ";
(sal +i)->SetData(_name, _salary);
salsort(sal, 3);
for (int i = 0; i < 3; i++){
(sal +i)->PrintData();
return 0;
void salsort(Person *person, int size)
Person tmp;

for(int i = 0; i < size - 1; ++i)
for(int j = 0; j < size - 1; ++j)
if ((person+j + 1)->GetSalary() < (person+j)->GetSalary() )
tmp = *(person+j + 1);
*(person+j + 1) = *(person+j);
*(person+j) = tmp;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions