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

Consider the following class called Section that stores the final grades of all

ID: 3883160 • Letter: C

Question

Consider the following class called Section that stores the final grades of all the students enrolled in a specific section of a class. class Section { public: Section() { // constructor nST = 0: } void addGrade(float grade) { ST [nST] = grade: nST++: } private: float ST[26]: int nST: // number of final grades stored }: a) The ST member variable can store at most 26 students. Change the code so that ST can store as many final grades as needed when a Section object is created. Change/add constructor and destructors as needed. b) Add a copy constructor for the above case. Imagine that you and your friend have been asked to write a C++ program to list all the 10 U.S. federal holidays in increasing calendaristicorder. (Rules on deciding these holidays are presented here: You decide to split the task as follows: - Your friend will write the code for a Holiday class - You will write the main function that will use the Holiday class Your friend provides you the following header file containing only the class declaration: class Holiday { public: Holiday (string holidayDate): // initialize with the giver, holiday's // date in the calendar int getDay(): // return the day of the holiday Int getMonth (): // return the month (1-12) of the holiday a) Is this header file sufficient for you to write your main function code? Or do you also need to see the Holiday class' source file with the class definition? b) Is this header file sufficient for you to compile your program? Or do you also need the Holiday class' source file with the class definition? The following part of a program computes and returns the product 1 * 2 * 3 * * N where N is the input parameter. (This value is called N! And is much used in combinatorics.) However, this function can give unexpected answers for some inputs of N! Add exception handling to this function to catch this situation. You should include both catch and try blocks. Your exception can be of any type, preferably std:: exception. int productOfNumbers (int N) { int p = 1: while (N ! = 0) { // count down until zero p *= N: N--: } return p: } int main () { int n: cout n: cout

Explanation / Answer

#1

//given solution with main to test the class

#include<iostream>

#include<stdlib.h>

using namespace std;

class Section

{

public:

//change the default constrorto take number of grades the object can support

Section(int n)

{

nST = 0;

ST = new float[n];

}

//add destructor to deallocate pointer

~Section()

{

delete[]ST;

}

//Add coppy constructor

Section(Section &obj)

{

ST = new float[obj.nST];

ST = obj.ST;

nST = obj.nST;

}

void addGrade(float grade)

{

ST[nST] = grade;

nST++;

}

void print()

{

for (int i = 0; i < nST; i++)

{

cout << ST[i] << endl;

}

}

private:

//change array to poniter to float variable

//float ST[26];

float *ST;

int nST;

};

int main()

{

Section obj(2), ob2(3);

obj.addGrade(2.4);

obj.addGrade(3.4);

obj.print();

ob2.addGrade(12.4);

ob2.addGrade(13.4);

ob2.addGrade(32.4);

ob2.print();

Section obj3(ob2);

obj3.print();

return 0;

}

-----------------------------------------------------------------------------

#2

a) header fil is sufficient to write the code in main

b) both header file and source code for class holiday also needed

-----------------------------------------------------------------------------------------

#3

//modified function

int prouctofNumber(int N)

{

int p = 1;

try

{

if (N < 0)

{

cout << "Number is negetive"<<endl;

throw -1;

}

while (N != 0)

{

p *= N;

N--;

}

}

catch (int e)

{

cout << "integer exception caught with error " << e<<endl;

return -1;

}

return p;

}

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