A teacher needs a program to grade her students. She wants to make the program f
ID: 3827676 • Letter: A
Question
A teacher needs a program to grade her students. She wants to make the program flexible so she can use it every year, so the number of students is not fixed. The program should ask the teacher for the number of student and then using DYNAMIC MEMORY ALLOCATION, create the dynamic array for the grade of the students. The program then needs to ask the teacher the integer grade for each student in the range of 1 to 100, and store it in a dynamic array. After reading completely, pass your dynamic array to a programmer defined function that returns the average grade across the class. Display the average grade of the class.Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
float getAvarage(vector<int>& marks)
{
float average = accumulate( marks.begin(), marks.end(), 0.0)/marks.size();
return average;
}
int main() {
// your code goes here
vector<int> marks;
int number_of_students,mark;
cout<<"Enter the number of Students"<<endl;
cin>>number_of_students;
while(number_of_students--)
{
cin>>mark;
marks.push_back(mark);
}
cout<<"Average Marks = "<<getAvarage(marks)<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.