c++ In a class section there are a number of students each studied different num
ID: 3730328 • Letter: C
Question
c++
In a class section there are a number of students each studied different number of courses. Create a class called Section that has the private members aumberQiStudents **students (a double pointer of type int), and *average (a double pointer of type double). The class has the public member functions ser(int, printo, findavexaze), a default parametrized constructor, a copy constructor, and a distractor. Implement the member function, read a number of marks for each student, and find the average mark of every student. Enforce the principle of least privileged. Use the following driver: int main Section a; a.set(3); a printO; coutExplanation / Answer
Please find the code below :
#include<iostream>
using namespace std;
class Section
{
private:
int numberOfStudents, **students;
double *average;
public:
void set(int numberOfStudents)
{
this->numberOfStudents = numberOfStudents;
students = new int*[numberOfStudents];
average = new double[numberOfStudents];
}
void print()
{
int n,x,j;
for(int i=0; i<numberOfStudents; i++)
{
cout<<"Enter the number of marks for student no. "<<i+1<<": ";
cin>>n;
students[i] = new int[n];
cout<<"Enter "<<n<<" marks: ";
for(int j=0; j<n; j++)
cin>>students[i][j];
}
findAverage();
int len;
for(int i=0; i<numberOfStudents; i++)
{
cout<<"The Marks of student no. "<<i+1<<" are: ";
len = sizeof(students[i])/sizeof(students[i][0]);
for(int j=0; j<n; j++)
cout<<students[i][j]<<" ";
cout<<" The average marks is: "<<average[i]<<endl;
}
}
void findAverage()
{
for(int i=0; i<numberOfStudents; i++)
{
int len = sizeof(students[i])/sizeof(students[i][0]);
for(int j=0; j<len; j++)
average[i] += students[i][j];
average[i] /= len;
}
}
};
int main()
{
Section a;
a.set(3);
a.print();
cout<<endl;
return 0;
}
Please comment and let me know if you face issues while compiling the code.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.