Home > C++ > Using of struct

Using of struct


#include <iostream.h>

using namespace std;
const int MAXNUMBER = 5;
struct StdExam
{
       char name[30];
       char subject[30];
       int mark;
};

int highestMark(StdExam s_exam []);

int main(int argc, char *argv[])
{
    StdExam myexam[MAXNUMBER];
    int hindex = 0;
    cout << "Enter name subject mark of each sutdents (20 students) " << endl;
    for( int i=0 ; i < MAXNUMBER ; i++)
    {
         cin >> myexam[i].name >>  myexam[i].subject >> myexam[i].mark ;
    }
    //
    // culculate the highest mark..
    //
    hindex = highestMark(myexam);
    cout << " >> the highest Mark is  " << endl;
    cout << " >> " << myexam[hindex].name << " " ;
    cout << myexam[hindex].subject << " " ;
    cout << myexam[hindex].mark << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}

int highestMark(StdExam s_exam [])
{
    int tmpMark;
    tmpMark = s_exam[0].mark;
    for (int i = 0; i < MAXNUMBER; i++)
    {
        if (tmpMark < s_exam[i].mark)
            tmpMark = s_exam[i].mark ;

    }
    for (int i = 0; i < MAXNUMBER; i++)
    {
        if (tmpMark == s_exam[i].mark)
            return i ;
    }
    //return tmpMark;
}
Categories: C++
  1. steerapong
    July 6, 2008 at 9:47 pm

    Good example…

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: