Constructor (with the function signature) and the destructor with the function signature writing the code for facing issues.
Question
c++
//If program contains this class definiton class TestScores { public: TestScores(string name, int cap); ~TestScores(); private: string PersonName; double *testScores; // Points to array of test scores int numOfTestScores; // Number of test scores int capacity; // Capacity of test score array static const double DEFAULT_SCORE = 0.0; };
I need help writing the constructor (with the function signature)
and the destructor with the function signature.
Summary
Constructor (with the function signature). So, the class is defined by the constructor which is named as Test Scores outside the class is defined. After defining a class we need to check the destructor functioning is working or not.
Explanation
We need to initialize the static class in the given default constructor of the scores. Further, we have to initialize the parameterized constructor to pass the string and int in the class along with default values. Either the string has passed with the Name whereas int has passed incapacity. Now, the destructor is coming out of the class of the function. So, now the Scores has been deleted from the message and gives the system it says the output the message is deleted. Finally, the output had printed in we need to check the destructor functioning is working or not. Finally, we get the output as a constructor (with the function signature) functions which we have used.
Code
#include <iostream> using namespace std; class Testscores { public: scores (string personname, int cap); ~scores(); void display(); private: string Name; double *scores; int numofscores; int capacity; static double DEFAULT_SCORE; }; double scores::DEFAULT_SCORE=0.0; scores::scores (string personname, int cap) { Name=name; capacity=cap; } scores:: ~scores(){ delete[] scores; cout<<"\nobiect deleted"<<endl; } /*to display the contents passed to a constructor for any object */ void scores::display(){ cout<<"\n Name: "<<Name<<endl; cout<<"Capacity: "<<capacity<<endl; } /*driver code */ int main() { scores t ("Supraja", 100); t.display(); }
Output
Also, the read another blog which is to write a relational schema for the diagram.