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
--------------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
//Author : Vivek S. Sharma
//Copyright : Your copyright notice
class Data_Structure{
int m[100],n;
public :
Data_Structure(){
n=0;
}
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;
cout<<"\nmax="<<max;
for(int i=0 ; i<100; i++){
if(max<a[i]){
max=a[i];
temp=i;
}
}
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(){
Data_Structure d;
int ch;
do{
cout<<"\n1.Get Deatails \n2.Average \n3.Highest and lowest marks \n4.Marks scored by most students \n5.Absent Students \n6.EXIT";
cin>>ch;
switch(ch){
case 1:d.get();break;
case 2:d.averrage();break;
case 3:d.highest_lowest();break;
case 4:d.repeated_marks();break;
case 5:d.absent();break;
}
}while(ch!=6);
return 0;
}
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
--------------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
//Author : Vivek S. Sharma
//Copyright : Your copyright notice
class Data_Structure{
int m[100],n;
public :
Data_Structure(){
n=0;
}
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;
cout<<"\nmax="<<max;
for(int i=0 ; i<100; i++){
if(max<a[i]){
max=a[i];
temp=i;
}
}
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(){
Data_Structure d;
int ch;
do{
cout<<"\n1.Get Deatails \n2.Average \n3.Highest and lowest marks \n4.Marks scored by most students \n5.Absent Students \n6.EXIT";
cin>>ch;
switch(ch){
case 1:d.get();break;
case 2:d.averrage();break;
case 3:d.highest_lowest();break;
case 4:d.repeated_marks();break;
case 5:d.absent();break;
}
}while(ch!=6);
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
**If some mistakes, plz let me know!-----Vivek S. Sharma
No comments:
Post a Comment