Please help with my assignment, our teacher told us to write a code in c++.
1.Enter 15 students and their general average.
2.List the top 10 students with a highest general average.

thank you very much for helping me.

tnx anyway. i just made a solution..

#include <iostream>
#include <iomanip>


using namespace std;

class rank
{
    char name[20];
    int sum;
    float marks;
    public:
    void getdata(void);
    void display(void);
    friend void sort(rank &,rank &);
    rank()
    {sum=0;}
};

void rank :: getdata(void)
{
    cout<<endl;
    cout<<"Enter Your Name :";
    cin>>name;
    cout<<"Enter General Average :";
    cin>>marks;
    sum=sum+marks;
}

void rank :: display(void)
{
    cout<<endl;
    cout<< setw(10)<<name<<setw(17)<<"";
    cout<<setw(5)<<marks; 
}
void sort(rank &a,rank &b)
{
    rank temp;
    if(a.sum < b.sum)
    {
        temp = a;
        a = b;
        b = temp;
    }
}
int main(int argc, char *argv[])
{
    rank o1[15];
    int rec;
    cout << "\n\t\t HONOR STUDENTS RANKING ";
    cout<<"\n\nEnter number of students to be rank [max of 15 students]:";
    cin>>rec;
    for(int q=0;q<rec;q++)
    {
        o1[q].getdata();
    }
    for(int i=0;i<rec;i++)
    {
        for(int j=i+1;j<rec;j++)
        {
            sort(o1[i],o1[j]);
        }
    }
    cout<<"\n\n\n"<<"      "<<"LIST OF TOP 10 HONOR STUDENTS\n"<<endl;
    cout<<"NAME OF STUDENT"<<setw(25)<<"GENERAL AVERAGE"<<endl;
    for(int a=0;a<10;a++)
    {
        o1[a].display();
    }
    cout << "\n\n";   
    return EXIT_SUCCESS;
}
// End of Code
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.