Help with C++_student project

Hi, I need help with my school work on C++. I have an already working code but my instructor told me to sort the structure elements which I have no idea how to do. Hoping someone can help me, here is my code below

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <sstream>
#include <stdlib.h>
using namespace std; 

#define SIZE 100
struct employee  
        char  name[30];	
        char  enumber[30];
        char  salary[30];
        char  address[50];
        char  job[50];
        float balance;
   	void Sort(void);
        void InputDetail(void);
        void OutputDetail(void);

void employee::InputDetail(void){
    cout << "Enter Employee Name: ";
    cin >> name;
    cout << "Enter Employee Number: ";
    cin >> enumber;
    cout << "Enter Employee Address: ";
    cin >> address;
    cout << "Enter Job Designation: ";
    cin >> job;
    cout << "Enter Basic Salary: ";
    cin >> salary;
void employee::OutputDetail(void){
    cout << "Employee details:\n";

    cout << "Name: "<< name <<endl;

	cout << "Employee Number: " << enumber << endl;
	cout << "Employee Address: " << address << endl;
	cout << "Job Designation: " << job << endl;

	cout << "Basic Salary: " << salary << endl;
int main()   //start of program
    employee std[SIZE];  
    int x,loop;
    cout << "Enter total number of employees: "; 
    cin >> x;
    for(loop=0; loop<x; loop++){					
        cout << "Enter details of employees " << loop+1 << ":\n";
    cout << endl;
	printf("\nUnsorted List: \n"); 
    for(loop=0; loop<x; loop++){					
        cout << "Details of employees " << loop+1 << ":\n";		
    cout << endl;
	printf("\nSorted List: \n");
     for(loop=0; loop<x; loop++){					
        cout << "Details of employees " << loop+1 << ":\n";
    return 0;

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


The first thing you should ask your instructor is to sort according to which variable in the struct? According to alphabetical order of name, amount of salary etc…

Once you know that try and use a sorting algorithm that is available to use and output the results.

Hope this helps.

He told me that sorting it alphabetically by name is enough.

Hey Ryan,

Check out this sample code where I sort an array of structs according to age:

You can change this to sort based on the name also.

Check out this video for more help:

I think you’ll be able to figure it out from here.

Good luck.