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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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->name;

cout<<"\nEnter the salary\n";
cin>>ptr->salary;
}

for(int j=0;j<size-1;j++){
	for(int k=0;k<size-i-1;k++){
		if (ptr[k].salary > 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<size;x++){
	cout<<ptr[x].name<<"'s salary is : "<<ptr[x].salary<<endl;
}

	return 0;
}
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.