Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

These questions should be written in C++ and should compile. A) Write the class

ID: 3572003 • Letter: T

Question

These questions should be written in C++ and should compile.

A) Write the class definition for the ADT Student. The class will contain three private member variables, a cstring statically sized 32 called name, an integer pointer for tests, and an integer for testCount. The class definition will also contain prototypes for a default constructor, a copy constructor, an overloaded assignment operator, a destructor, a void function called inputStudent, and a void function called displayStudent.

B) Write the definitions for the Student class. The default constructor will assign NULL to the first character of name, dynamically allocate one integer for tests then assign it 0, and assign 1 to testCount. The copy constructor will copy the passed Student object, and the overloaded assignment operator will assign the passed Student object into this Student object. The destructor will deallocate any and all memory the dynamic member variable has allocated. The function inputStudent will prompt the user for a name, assign the entered value into name, prompt for the amount of test scores to enter, assign the entered value into testCount, allocate, and assign a value for each tests. Remember to handle the dynamic member variable accordingly. The function displayStudent will output the student's name, each tests score, and the average of the test scores.

Explanation / Answer

#include <bits/stdc++.h>
#include <string>
using namespace std;
class Student
{
   int* tests;
   int testCount;
   string name;

public:
   Student()
   {
       name="";
       testCount=1;
       tests=new int[testCount];
      

   }
   Student(const Student &obj)
   {
    testCount=obj.testCount;
name=obj.name;
tests = new int[obj.testCount];
*tests = *obj.tests;

for (int i = 0; i < testCount; ++i)
{
        tests[i]=obj.tests[i];
}

   }


   void operator = (const Student &obj )
   {
     
testCount=obj.testCount;
name=obj.name;
tests = new int[obj.testCount];
*tests = *obj.tests;

for (int i = 0; i < testCount; ++i)
{
        tests[i]=obj.tests[i];
}
}
~Student()
{
   delete tests;
}

void inputStudent()
{
   cout<<"Enter name of student ";
   cin>>name;
   cout<<"Enter Test count ";
   cin>>testCount;
   cout<<"Enter each tests marks ";

   for (int i = 0; i < testCount; ++i)
   {
       cin>>tests[i];
   }
}

void displayStudent()
{
   cout<<"Student name is "<<name<<endl;
   cout<<name<<"'s marks are as follows ";
   int sum=0,avg=0;
   for (int i = 0; i < testCount; ++i)
   {
       cout<<"Test No: "<<i+1<<" "<<tests[i]<<endl;
       sum+=tests[i];
   }
   avg=sum/testCount;
   cout<<"Avearge of marks is "<<avg<<endl;

}
};
int main(int argc, char const *argv[])
{
   Student s;
   s.inputStudent();
   s.displayStudent();
   cout<<"Testing Copy Constructor ";
   Student scopy=s;
   scopy.displayStudent();
   cout<<"Testing Assignment operator ";
   Student sassign;
   sassign=s;
   scopy.displayStudent();
   return 0;
}

==========================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ student.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter name of student
akshay
Enter Test count
3
Enter each tests marks
10
20
30
Student name is akshay
akshay's marks are as follows
Test No: 1 10
Test No: 2 20
Test No: 3 30
Avearge of marks is 20
Testing Copy Constructor
Student name is akshay
akshay's marks are as follows
Test No: 1 10
Test No: 2 20
Test No: 3 30
Avearge of marks is 20
Testing Assignment operator
Student name is akshay
akshay's marks are as follows
Test No: 1 10
Test No: 2 20
Test No: 3 30
Avearge of marks is 20
akshay@akshay-Inspiron-3537:~/Chegg$

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote