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

Computing III Lab –6 There is a collection of student records to be maintained f

ID: 3920056 • Letter: C

Question

Computing III Lab –6

There is a collection of student records to be maintained for an examination - including the variables studentID, studentFirstName and studentGrade (integer). The program should prompt for, input the data and keep records in dynamic array. Initialize the default studentFirstName as XXXX and the default grade as 0. Implement your own constructor, copy constructor, copy assignment operator and destructor. Consider the passing grade as 8 (out of 10). Create a second array of passed students and a third array which just copies this array. Print the output of the test run given below. Additionally, display when were the following called (a) constructor (b) copy constructor (c) copy assignment operator (d) destructor – and explain it to your instructor (you could uncomment the code for this display and show in the next run with fewer data input).

Test run.

How many records? 3
Enter student record (studentID <space> studentFirstName <space> studentGrade):
01660000 Ramji 6
01670000 Sitaji 9
00199999 Hanumanji 8

Pass records
01660000 Sitaji 9
00199999 Hanumanji 8

Copied 2 pass records
01660000 Sitaji 9
00199999 Hanumanji 8

Any more records?(y/n) y
How many records? 1
Enter student record (studentID <space> studentFirstName <space> studentGrade):
01990000 Shivji 9

Pass records
01660000 Sitaji 9
00199999 Hanumanji 8
01990000 Shivji 9

Copied 3 pass records
01660000 Sitaji 9
00199999 Hanumanji 8
01990000 Shivji 9

Any more records (y/n)? n

Grading.
Functional implementation with comments and style – 3
Constructor -2
Copy constructor -2
Copy assignment operator – 2
Destructor - 1

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class Student {

    private:
        string studentID;
        string studentFirstName;
        int studentGrade;
    public:
        Student(){
           studentID = "";
           studentFirstName = "XXXX";
           studentGrade = 0;
        }
        Student(string i, string f, int g){
            studentID = i;
            studentFirstName = f;
            studentGrade = g;
        }
        Student(const Student &s){
           studentID = s.studentID;
            studentFirstName = s.studentFirstName;
            studentGrade = s.studentGrade;
        }
        ~Student() {
        }
        void operator = (Student &s){
            studentID = s.studentID;
            studentFirstName = s.studentFirstName;
            studentGrade = s.studentGrade;
        }
        int getStudentGrade(){
           return studentGrade;
        }
        string getStudentID(){
             return studentID;
        }
        string getStudentFirstName(){
           return studentFirstName;
        }
        void setStudentID(string a){
            studentID = a;

        }
        void setStudentFirstName(string a){
            studentFirstName = a;

        }
        void setStudentGrade(int a){
            studentGrade = a;

        }
        void disp(){
            cout << studentID << " " << studentFirstName << " " << studentGrade << endl;
        }

       
};

void Display(Student data[], int num){
    for (int i = 0; i<num; i++){
        data[i].disp();
    }
}

int main(){

    string id, name;
    int grade;
    Student totalpass[50];
  
    int passcount = 0;
    while (true){
         cout << "How many records? ";
         int n;
         cin >> n;
         cout << "Default Constructor Invoked ";
         Student *data = new Student[n];
         Student *pass = new Student[n];
         for (int i = 0; i<n; i++){
           
            cin >> id >> name >> grade;
            data[i].setStudentID(id);
            data[i].setStudentFirstName(name);
            data[i].setStudentGrade(grade);
         }
         int count = 0;
         cout << " Copy Assignment operator invoked ";
         for (int i = 0; i<n; i++){
             if (data[i].getStudentGrade() >= 8){
                pass[count] = data[i];   //Assignment operator
                count++;
             }
         }
         cout << "Pass Records ";
         cout << "Copy Constructor invoked for displaying ";
         Display(pass,count);    //Copy Construtor

         cout << " Copy Assignment operator invoked ";
        
         for (int i = 0; i<count; i++){
             totalpass[passcount] = pass[i]; //Assignment operator
             passcount++;
         }
       
         cout << "Copied " << count << " pass records ";
         cout << "Copy Constructor invoked for displaying ";
         Display(totalpass,passcount);
         cout << " Destructor invoked ";
         delete [] data;   // destructor called
         delete [] pass;
         cout << "Any more records?(y/n): ";
         string line;
         cin >> line;
         if (line[0] == 'n')
            break;
    }
}

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