Monday, 8 June 2015

Program that reads 10 students marks and displays average, lowest and highest marks


Code for Program that reads 10 students marks and displays average, lowest and highest marks in C++ Programming



 #include<iostream.h>
 #include<conio.h>

 float average_marks(float []);
 float highest_marks(float []);
 float lowest_marks(float []);

 main()
    {
       clrscr();

       float marks[10]={0};

       cout<<"\n Enter the marks of the ten students : "<<endl;
       cout<<"\n\t Student No.       Marks Obtained"<<endl;

       for(int count_1=0;count_1<10;count_1++)
      {
         cout<<"\t\t"<<count_1+1<<"\t\t";
         cin>>marks[count_1];
      }

       getch();
       clrscr();

       cout<<"\n ********************  Result Sheet  ****************"<<endl;

       cout<<"\n Total Marks = 100"<<endl;
       cout<<" Average Marks  = "<<average_marks(marks)<<endl;
       cout<<" Highest Marks obtained = "<<highest_marks(marks)<<endl;
       cout<<" Lowest Marks obtained = "<<lowest_marks(marks)<<endl;

       cout<<"\n   Student No.    Marks Obtained     Diff. from Average Marks      Status"<<endl;

int y=10;
       for(int count_2=0;count_2<10;count_2++)
      {
         cout<<"\t"<<count_2+1<<"\t\t"<<marks[count_2];
         gotoxy(42,y);
         cout<<marks[count_2]-average_marks(marks)<<"\t\t   "<<
                 ((marks[count_2]>=50)?"Pass":"Fail")<<endl;
         y++;
      }

       getch();
       return 0;
    }


 /*************************************************************************///------------------------  average_marks(float [])  --------------------///*************************************************************************/float average_marks(float marks[])
    {
       float sum=0;

       for(int count=0;count<10;count++)
      sum+=marks[count];

       return sum/10;
    }

 /*************************************************************************///---------------------  highest_marks(float [])  -----------------------///*************************************************************************/float highest_marks(float marks[])
    {
       float highest=marks[0];

       for(int count=0;count<10;count++)
      {
         if(marks[count]>highest)
        highest=marks[count];
      }

       return highest;
    }

 /*************************************************************************///----------------------  lowest_marks(float [])  -----------------------///*************************************************************************/float lowest_marks(float marks[])
    {
       float lowest=marks[0];

       for(int count=0;count<10;count++)
      {
         if(marks[count]<lowest)
        lowest=marks[count];
      }
       return lowest;
    }

No comments:

Post a Comment