Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Information
Technology
Department of
Artificial Intelligence and Data Science
Student Name: Aditya Sirsat
Class: F.Y. B. Tech Division: B (B2) Roll No.: 107235
Semester: 2nd Semester Academic Year: 2023-24
Subject Name & Code: IDSA
Assignment No: 2
Title of Assignment: Write a program to take students’ marks as input and
perform various operations on them.
Date of Performance: Date of Submission:
Aim: To perform various operations on array of students’ marks and find outcomes of
them.
Objective: To learn about arrays and their uses, performing actions on arrays.
Materials Required:
Computer
IDE that is supported
Visual Studio Code
Procedure:
CODE:
#include<iostream>
using namespace std;
int result(int a[], int n){
int absent = 0, passed = 0, failed = 0;
for(int i = 0; i<n ; i++){
if(a[i]==999){
absent++;
}
else if(a[i]>=45 && a[i]<=100){
passed++;
}
else{
failed++;
}
}
cout<<"The Number of Passed students: "<<passed<<"\n";
cout<<"The Number of Failed students: "<<failed<<"\n";
cout<<"The Number of Absent students: "<<absent<<"\n";
return 0;
}
float average(int a[], int n){
float count = 0;
float sum = 0;
float avg;
for(int j = 0; j<n; j++){
if(a[j]!=999){
count++;
sum+=a[j];
}
}
avg = sum / count;
cout<<"The Average marks are "<< avg <<endl;
return 0;
}
int frequency(int a[], int n) {
int maxValue = 101;
int freqA[maxValue] = {0};
bool allAbsent = true;
for(int k = 0; k < n; ++k) {
if (a[k] != 999) {
allAbsent = false;
freqA[a[k]]++;
}
}
if (allAbsent) {
cout << "No marks other than absent (999) are present." << endl;
return 0;
}
int highestFreq = 0;
for (int k = 0; k < maxValue; ++k) {
if(freqA[k] > highestFreq) {
highestFreq = freqA[k];
}
}
cout << "The highest frequency marks are: ";
for (int k = 0; k < maxValue; ++k) {
if (freqA[k] == highestFreq) {
cout << k << " ";
}
}
cout << endl;
return 0;}
int HighAndLow(int a[], int n){
int max;
int min;
for (int p=0; p<n; p++){
if(a[p]!=999){
max= a[p];
min= a[p];
break;
}
else{
continue;
}
}
for(int q=0; q<n; q++){
if(a[q]==999){
continue;
}
else if(a[q]>max){
max=a[q];
}
else if (a[q]<min){
min=a[q]; }
}
cout<<"The Highest marks: "<<max<<endl;
cout<<"The Lowest marks: "<<min<<endl;
return 0;}
int main(){
int n;
int choice;
cout<<"Enter the number of students: ";
cin>>n;
int array[n];
for (int i=0;i<n;i++){
cout<<"Enter marks of student "<<i+1<<":";
cin>>array[i]; }
cout<<"Enter the Operation you want to do on marks of student: \n 1.Count of
students passed, failed and absent. \n 2.Average Marks of the Class.\n 3.Highest
and Lowest markss in Class.\n 4.Highest Frequency Marks."<<endl;
cin>>choice;
switch(choice){
case 1:
result(array, n);
break;
case 2:
average(array, n);
break;
case 3:
HighAndLow(array, n);
break;
case 4:
frequency(array, n);
break;
default:
cout<<"Entered choice is invalid.";
break;
}
}
OUTPUT:
Conclusion: In this experiment, we learnt about arrays, their functions and how to
iterate through them and how to perform mathematical operations on the arrays.
It helped us find the number of passed, failed, absent students, the average marks,
highest and lowest marks, the highest frequency marks in the class.