Tuesday, 7 August 2018

Data Structures and Algorithms- Assignment :A2



Title:

Write C/C++ program to store marks scored for first test of subject 'Data Structures and Algorithms' for N students. Compute
I. The average score of class
ii. Highest score and lowest score of class
iii. Marks scored by most of the students
iv. List of students who were absent for the test



Program:

#include <iostream>
using namespace std;


class Marks
{
            int m[100],n;
public :

            void get()
            {
                        cout<<"\nEnter no. of students : ";
                        cin>>n;
                        cout<<"\nEnter the Dsa marks(-1 for absent students) : ";
                        for(int i=0 ; i<n ; i++)
                        {
                                    cout<<"\nMarks of Roll No. "<<i+1<<" : ";
                                    cin>>m[i];
                        }
            }
            void repeated_marks()
            {
                        int a[100];
                        for(int i=0 ; i<100; i++)
                        {
                                    a[i]=0;
                        }
                        for(int i=0 ; i<n ; i++)
                        {
                                    for(int j=0 ; j<100 ; j++)
                                    {
                                                if( m[i]==j)
                                                            a[j]++;
                                    }
                        }

                        int max=a[0],temp=0;

                        for(int i=0 ; i<100; i++)
                        {
                                    if(max<a[i])
                                    {
                                                max=a[i];
                                                temp=i;
                                    }
                        }
                        cout<<"\nmax="<<max;
                        cout<<"\nMarks scored by most of the students : "<<temp;
            }

void averrage()
{
            int sum,avg;
            sum=0,avg=0;
            int x=n;
            for(int i=0 ; i<n ; i++)
            {
                        if(m[i] != -1)
                        {
                                    sum+=m[i];
                        }
                        else
                                    if(m[i]==-1)
                                                x--;
            }
            avg=sum/x;
            cout<<"\nAverage Marks : "<<avg;
}
void highest_lowest()
{
            int max,min;
            max=min=m[0];
            for(int i=0 ; i<n ; i++)
            {
                        if(m[i]!=-1)
                        {
                                    if(m[i]<min)
                                                min=m[i];
                                    if(m[i]>max)
                                                max=m[i];
                        }
            }
            cout<<"\nMaximum Marks : "<<max<<"\nMinimum Marks : "<<min;
}
void absent()
{
            cout<<"\nStudents absent for test are : ";
            for(int i=0 ;i<n ; i++)
            {
                        if(m[i]==-1)
                                    cout<<"\nRoll No. : "<<i+1;
            }
}

};
int main()
{
            Marks obj;
            int ch;

            do{
                        cout<<"\n\n1.Get Details \n2.Average \n3.Highest and lowest marks \n4.Marks scored by most students \n5.Absent Students \n6.EXIT";
                        cout<<"\nEnter your choice";
                        cin>>ch;
                        switch(ch)
                        {
                        case 1:obj.get();break;
                        case 2:obj.averrage();break;
                        case 3:obj.highest_lowest();break;
                        case 4:obj.repeated_marks();break;
                        case 5:obj.absent();break;
                        }
            }while(ch!=6);
            return 0;
}


Output:

1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice1

Enter no. of students : 10

Enter the Dsa marks(-1 for absent students) :
Marks of Roll No. 1 : 5

Marks of Roll No. 2 : 5

Marks of Roll No. 3 : 6

Marks of Roll No. 4 : 7

Marks of Roll No. 5 : 8

Marks of Roll No. 6 : 5

Marks of Roll No. 7 : -1

Marks of Roll No. 8 : -1

Marks of Roll No. 9 : 6

Marks of Roll No. 10 : 5


1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice2

Average Marks : 5

1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice3

Maximum Marks : 8
Minimum Marks : 5

1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice4

max=4
Marks scored by most of the students : 5

1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice5

Students absent for test are :
Roll No. : 7
Roll No. : 8

1.Get Details
2.Average
3.Highest and lowest marks
4.Marks scored by most students
5.Absent Students
6.EXIT
Enter your choice6

No comments:

Post a Comment

Stack and Queue as ADT in C++

Stack as ADT The functions associated with stack are: empty()  – Returns whether the stack is empty size()  – Returns the size o...