In: Computer Science
Write up to 10 lines to explain the logic used behind this code pls!!!!!
#include <iostream>
#include <iomanip>
#include<cmath>
#include<AclUI.h>
using namespace std;
int main()
{
int array[][2] = { {29,60} , {33,80} , {45,90} , {57,52} , {12,44} , {21,78} , {32,64} , {17,59} }; //given values
int Totalstudents = 0,TotalPass = 0, Average = 0;
for (int i = 0; i < 8; i++) //students enrooled
{
Totalstudents += array[i][0];
}
for (int i = 0; i < 8; i++) //Total Pass
{
TotalPass += array[i][1];
}
TotalPass /= 8;
for (int i = 0; i < 8; i++) //Loop to calculate total students passed
{
Average += int(((array[i][0] * array[i][1]) / 100));
}
//Display the results
cout << "Name of Paper" << setw(25) << " Students Enrolled" << setw(15) << "Passed %" << setw(35) << " Number of Passing Students" << endl;
cout << "Architecture" << setw(25) << array[0][0] << setw(15) << array[0][1] << setw(35) << int(0.60 * array[0][0]) << endl;
cout << "Computing " << setw(25) << array[1][0] << setw(15) << array[1][1] << setw(35) << int(0.80 * array[1][0]) << endl;
cout << "Electrical " << setw(25) << array[2][0] << setw(15) << array[2][1] << setw(35) << int(0.90 * array[2][0]) << endl;
cout << "Mechanical " << setw(25) << array[3][0] << setw(15) << array[3][1] << setw(35) << int(0.52 * array[3][0]) << endl;
cout << "Chemical " << setw(25) << array[4][0] << setw(15) << array[4][1] << setw(35) << int(0.44 * array[4][0]) << endl;
cout << "Biomedical " << setw(25) << array[5][0] << setw(15) << array[5][1] << setw(35) << int(0.78 * array[5][0]) << endl;
cout << "Mechatronics" << setw(25) << array[6][0] << setw(15) << array[6][1] << setw(35) << int(0.64 * array[6][0]) << endl;
cout << "Electronics " << setw(25) << array[7][0] << setw(15) << array[7][1] << setw(35) << int(0.59 * array[7][0]) << endl;
cout << "Total " << setw(25) << Totalstudents << setw(15) << TotalPass << setw(35) << Average << endl;
return 0;
}
Answer :
This program is mainly used to calculated the statistics of student exams in 8 different papers
Below is the steps used to calculate statistics
:
1.Including required libraries and declaring required
variables.
2.Initilized 2-D array containing total students and total pass
percentage for each paper.
3.There are 8 fields(Architecture,computing etc...) so 8
papers.
4.Using Loop to calculate total students enrooled for 8
papers.
5.Using another for loop to sum all the pass percentages in 8
papers.
6.Then dividing the sum with 8 to get Total Pass percentage.
7.In Output they are using setw() function to format the output and
printing it in correct order(In tabular form).
8.printing the Name of Paper,Students Enrolled,passed %,Number of
passing Students for all 8 Papers(Well formated).
9.Number of passing Students = numOfStudents*(pass
percentage/100)
10.At final they are printing the already calculated
totalStudents,TotalPass and average for total 8
fields.
********Comment me for any Quereis and Rate me up*********