### Structures related problem

Make a structure named as Employee, containing two member variables name of type
char[] and salary of type float. Make an array dynamically querying the size from the
user to store the Employee. Input each Employee data from user and store it in this array.
Sort the Array with respect to the salary of the Employee. Finally display the output in
ascending order as follows:

Ali‟s Salary is: xxxxxx
Abc‟s Salay is: xxxxxx
Def‟s Salary is :xxxxxx

I HAVE EVERYTHING REQUIRED IN ABOVE QUESTION PROBLEM I AM FACING IS THAT AFTER ARRANGING DATA IN ASCENDING ORDER I GET RECORD ON 0TH LOCATION OF ARRAY ONLY OTHER IS SKIPPED AND GARBAGE VALUE IS DISPLAYED
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` ``````#include using namespace std; struct Employee{ char name[30]; float salary; }; int main(){ int size; cout <<"\nEnter the size\n"; cin>>size; Employee *ptr = new Employee [size]; for (int i=0; i>ptr->name; cout<<"\nEnter the salary\n"; cin>>ptr->salary; } for(int j=0;j ptr[k+1].salary){ int temp; temp = ptr[k].salary; ptr[k].salary = ptr[k+1].salary; ptr[k+1].salary = temp; } } } for (int x=0;x
SOLVED BY MY FRIEND wiserehan@gmail.com
////////////////////////////////////////////////////
#include<iostream>
using namespace std;

struct Employee{

char name[30];
float salary;

};
int main(){
int size;

cout <<"\nEnter the size\n";
cin>>size;
Employee *ptr = new Employee [size];

for (int i=0; i<size ; i++){
cout<<"\nEnter the name:\n";
cin>>ptr[i].name;//

cout<<"\nEnter the salary\n";
cin>>ptr[i].salary;//
}

for(int j=0;j<size-1;j++){
for(int k=0;k<size-j-1;k++){//
if (ptr[k].salary > ptr[k+1].salary){
Employee temp;//
temp = ptr[k];
ptr[k] = ptr[k+1];
ptr[k+1] = temp;
}

}

}

for (int x=0;x<size;x++){
cout<<ptr[x].name<<"'s salary is : "<<ptr[x].salary<<endl;
}

return 0;
}

///////////////////////////////////////////////////
Topic archived. No new replies allowed.