ram Description In this assignment, you will redo Assignment 1 using functions a
ID: 3739967 • Letter: R
Question
ram Description In this assignment, you will redo Assignment 1 using functions and also extend its functionality Like Assignment 1, you will develop a Console Application that grades a multiple choice test with 10 questions taken by 8 students. The applications finds each student's letter grade based on that test, and then displays: (i) a table listing names, scores and grade for all students, (ii) average, standard deviation, and median of the test scores, (ii) a histogram showing the number of students who got A, B, C, D, or F, etc. Suppose the student's names, their answers to the questions, the answer key and the score for each question are as given below Student's Answers to the Questions Jack John Jill Mary Peter Bob Nancy Pat A B ACC D E E A D D B ABCA E E A D E D D A C B E E A D C BAEDC E E A D A B DCC D E E A D B BECC D E E A D B B ACC D E E A D E BECC D E E A D Key D B D CC D A E A D Score 2 2533 4 4 4 6 7 1. The Main0 method should create one two dimensional array to store the student's answer and three different one dimensional arrays to store the student names, the answer key and the scores for each question, and initialize them to the values given above. You may create other arrays if you like, but only if necessary level. Every array you declare should be declared inside DO NOT declare any array at class- a function (Main or other) Note that we may change the student responses, the answer key and/or the scores for the questions when we test your application. So, write your code in such a way that it will work for any valuesExplanation / Answer
Due to shortage of time could not post the screenshots of the output but here is the full working code
//Code
#include<iostream>
#include<math.h>
#include<cstring>
#include <bits/stdc++.h>
using namespace std;
char calculate_grade(int score,int total_score){
float percentage = (score*1.0/total_score)*100;
if(percentage>=90 && percentage<100){
return 'A';
}else if(percentage>=80 && percentage<90){
return 'B';
}else if(percentage>=70 && percentage<80){
return 'C';
}else if(percentage>=60 && percentage<70){
return 'D';
}else if(percentage<60){
return 'F';
}
}
void compute_grades(int students_answer[8][10],char answer_key[10],int score[10],int student_scores[10],char student_grades[10]){
int total_score=0;
for(int i=0;i<10;i++){
total_score+=score[i];
}
for(int i=0;i<8;i++){
for(int j=0;j<10;j++){
student_scores[i]+=(students_answer[i][j]==answer_key[j]?score[j]:0);
}
student_grades[i] = calculate_grade(student_scores[i],total_score);
}
}
void compute_statistics(int student_scores[8],float mean,float standard_deviation,float median){
int arr[8];//stores the copy of the students score
int total;
for(int i=0;i<8;i++){
arr[i]=student_scores[i];
total+=student_scores[i];
}
mean = (total*1.0)/8;
float factor;
for(int i=0;i<8;i++){
factor+=pow((student_scores[i]-mean),2);
}
factor=factor/8;
standard_deviation = sqrt(factor);
sort(arr,arr+8);
median = (student_scores[3]+student_scores[4])/2;
}
void draw_histogram(char student_grades[10]){
char grades[5];
char a='A';
for(int i=0;i<5;i++){
grades[i] = (char)(a++);
}
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
char temp;
if(student_grades[j]==grades[i]){
temp='*';
}else{
temp='';
}
cout<<grades[i]<< " |"<<temp;
}
cout<<endl;
}
}
void display_results(string names[8],int student_scores[8],char student_grades[8],float mean,float standard_deviation,float median){
cout<<"Student Score Grade"<<endl;
for(int i=0;i<8;i++){
cout<<names[i]<<" "<<student_scores<<" "<<student_grades[i]<<" "<<endl;
}
cout<<endl<<endl;
cout<<"Mean: "<<mean<<endl;
cout<<"Standard deviation: "<<standard_deviation<<endl;
cout<<"Median: "<<median<<endl;
cout<<endl<<endl;
draw_histogram(student_grades);
}
int main(){
string names[8];
char answer_key[10];
int score[10];
int students_answer[8][10];
cout<<"Enter the names of the student"<<endl;
for(int i=0;i<8;i++){
cin>>names[i];
}
cout<<"Enter the score alloted for each question"<<endl;
for(int i=0;i<10;i++){
cin>>score[i];
}
cout<<"Enter the Answer Key"<<endl;
for(int i=0;i<10;i++){
cin>>answer_key;
}
cout<<"Enter the students answers "<<endl;
for(int i=0;i<8;i++){
for(int j=0;j<10;j++){
cin>>students_answer[i][j];
}
}
int student_scores[8];
char student_grades[8];
compute_grades(students_answer,answer_key,score,student_scores,student_grades);
float mean=0;
float standard_deviation=0;
float median=0;
compute_statistics(student_scores,mean,standard_deviation,median);
display_results(names,student_scores,student_grades,mean,standard_deviation,median);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.