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

This was the question of Program#8 that I have finished doing and I need your he

ID: 3575518 • Letter: T

Question

This was the question of Program#8 that I have finished doing and I need your help to modify this for doing Program 8#a and Program 8#b:

And I came up with the following code and this worked perfectly:

#include <iostream>
#include <string>

using namespace std;

//Class definition
class StudentInfo
{
//Member variable declaration
private:
string firstName, lastName;
int exams[3];

//Public member functions
public:

//Set functions for names
void setFirstName(string name)
{
firstName = name;
}

void setLastName(string name)
{
lastName = name;
}

//Get functions for names
string getFirstName()
{
return firstName;
}

string getLastName()
{
return lastName;
}

//Set function for exams
void setExams(int arr[], int length)
{
int i;

//Assigning exams
for(i=0; i<3; i++)
exams[i] = arr[i];
}

//Get function for three exams
int getExam1()
{
return exams[0];
}

int getExam2()
{
return exams[1];
}

int getExam3()
{
return exams[2];
}

//Function that calculates average of three exams
double getAverage()
{
return (exams[0] + exams[1] + exams[2]) / 3.0;
}
};

//Main function
int main()
{
//Creating object
StudentInfo student;

string temp;

int scores[3];

//Reading name
cout << " Enter first name: ";
getline(cin, temp);

//Soring into object
student.setFirstName(temp);

//Reading name
cout << " Enter last name: ";
getline(cin, temp);

//Soring into object
student.setLastName(temp);

//Reading scores
cout << " Enter three scores separated by space: ";
cin >> scores[0] >> scores[1] >> scores[2];

//Soring into object
student.setExams(scores, 3);

//Greeting user
cout << " Hello " << student.getFirstName() << " " << student.getLastName() << " ";

//Printing scores
cout << " Your three exam scores: " << " " << student.getExam1() << " " << student.getExam2() << " " << student.getExam3() << " ";

//Printing average score
cout << " Your average score: " << student.getAverage();

cout << " ";
return 0;
}

Now I need help with doing the following parts:

Question (Program8a):

Now modify Program #8 for the StudentInfo:

a. to contain the additional data members:

Quizes an array of 8 elements of type int

Programs: an array of 10 elements of type int.

Write the appropriate set and get functions as you did in Program #8 for each of the new data members.

Additional write a function member called getAverage() which is passed the array and length and returns the average score.

b. declare studentPtr to be a pointer to theStudent Info class. Show that all the functions work using studentPtr.

Run your program to be sure it works correctly.

Question (Program 8b):

Continue to modify Program #8 so that the data members and functions of the StudentInfo class are made up of:

firstName of type string and lastName of type string;

The set and get functions for these data members will be the same as those for both Program 8 and the previous part.

Exams[3] of type int; The set function is passed an array and the variable, L, of type int for the size of the array. However, the get function returns a pointer to the array.

Quizes[8] of type int; The set function is passed an array and the variable, L, of type int for the size of the array. However, the get function returns a pointer to the array.

Programs[10] of int; The set function is passed an array and the variable, L, of the type int for the size of the array. However, the get function returns a pointer to the array.

Create two constructors for the StudentInfo class. One constructor will be the default (no parameters) and one constructor will include parameters for each data member so that the data members can be initialized when an object is declared.

Additionally, create the class member function getAverage() which is passed an array and variable L, of type int for the size of the array. getAverage() returns the average value of the array sent to it. Note: there is only 1 getAverage() (not one for each data member). getAverage() will have three class function members: getAverageExams(), getAverageQuizzes() and getAveragePrograms(). These functions compute their respective averages and return the average.   These functions are not passed any parameters.

In main(), declare a pointer to an object of StudentInfo class. Use dynamic allocation to create the object. Read in information to the data members of the object and compute the average of each kind of grade such as Exams, Quizzes and Programs. Delete the object and reset the pointer after you complete this work.

Also, declare 2 objects of the StudentInfo class.  Initialize one object's data members. Use the default constructor for the other object. Then read in values for the object's data members. Compute the average of each kind of grade such as Exam, Quizzes and Programs.

Determine what information your program will be printing out to show that all of the operations work.

Program #8a and #8b are to be completed in one program. The program will contain three separate files for the class declaration, class function implementation, and main().

Restriction: Do not use any topics we have not yet covered in class such as pointers. Assignment: Create a StudentInfo class which contains the following data members: first Name and lastName type string an array of 3 int Exams The public function members of the class will consist of Set and get functions for firstName and lastName Set function for Exams which is passed an array and length 3 get functions one each for Exam1, Exam2, and Exam3 (returns int) Additionally, construct public function member called getAverage() which computes the average of the 3 exam scores The program prompts the user for their first name, last name and 3 exam scores setting all of the data attributes in the class. The program then greets the user, prints the three exam scores and prints the average using the StudentInfo class functions (and other required code). Programs: 1. Create the above class, class functions and main n one file. Run the program to verify its correctness. 2. Separate the program into the header, class implementation and program file. Run the program to verify its correctness.

Explanation / Answer

#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
//Class definition
class StudentInfo
{
//Member variable declaration
private:
string firstName, lastName;
int exams[3];
int quizs[8];
int programs[10];
//Public member functions
public:
//Default Constructor
StudentInfo()
{
int c;
firstName = "";
lastName = "";
for(c = 0; c < 3; c++)
exams[c] = 0;
for(c = 0; c < 8; c++)
quizs[c] = 0;
for(c = 0; c < 10; c++)
programs[c] = 0;
}
//Parameterized constructor
StudentInfo(string fn, string ln, int e[], int q[], int p[])
{
int c;
firstName = "";
lastName = "";
for(c = 0; c < 3; c++)
exams[c] = e[c];
for(c = 0; c < 8; c++)
quizs[c] = q[c];
for(c = 0; c < 10; c++)
programs[c] = p[c];
}
//Set functions for names
void setFirstName(string name)
{
firstName = name;
}
void setLastName(string name)
{
lastName = name;
}
//Get functions for names
string getFirstName()
{
return firstName;
}
string getLastName()
{
return lastName;
}
//Set function for exams
void setExams(int arr[], int length)
{
int i;
//Assigning exams
for(i = 0; i < length; i++)
exams[i] = arr[i];
}
//Get function for three exams
int * getExam()
{
return exams;
}

//Set function for quiz
void setQuizs(int arr[], int length)
{
int i;
//Assigning exams
for(i = 0; i < length; i++)
quizs[i] = arr[i];
}
//Get function for eight exams
int* getQuizs()
{
return quizs;
}

//Set function for Program
void setPrograms(int arr[], int length)
{
int i;
//Assigning exams
for(i = 0; i < length; i++)
programs[i] = arr[i];
}
//Get function for eight exams
int* getPrograms()
{
return programs;
}
//Returns the average of exam score
double getAverageExams()
{
return getAverage(exams, 3);
}
//Returns the average of quiz score
double getAverageQuizzes()
{
return getAverage(quizs, 8);
}
//Returns the average of program score
double getAveragePrograms()
{
return getAverage(programs, 10);
}
//Function that calculates average of three exams
double getAverage(int a[], int l)
{
int c;
float tot = 0, avg;
for(c = 0; c < l; c++)
tot += a[c];
return (tot / l);
}
};
//Main function
int main()
{
//Creating pointer type object
StudentInfo *student = new StudentInfo();
string temp, temp1;
int x, c;
int *scores = new int[3];
int *quiz = new int[8];
int *program = new int[10];
//Pointer
//Reading name
cout << " Enter first name: ";
getline(cin, temp);
fflush(stdin);
//Soring into object
student->setFirstName(temp);
//Reading name
cout << " Enter last name: ";
getline(cin, temp);
//Soring into object
student->setLastName(temp);
//Reading scores
cout << " Enter three scores separated by space: ";
for(c = 0; c < 3; c++)
cin >> scores[c];
//Soring into object
student->setExams(scores, 3);

//Reading Quiz mark
cout << " Enter eight scores separated by space: ";
for(c = 0; c < 8; c++)
cin >> quiz[c];
//Soring into object
student->setQuizs(quiz, 8);

//Reading program mark
cout << " Enter ten scores separated by space: ";
for(c = 0; c < 10; c++)
cin >> program[c];
//Soring into object
student->setPrograms(program, 10);

//Greeting user
cout << " Hello " << student->getFirstName() << " " << student->getLastName() << " ";
//Printing Exam scores
cout << " Your three exam scores: " << " ";
scores = student->getExam();
for(int c = 0; c < 3; c++)
cout<< scores[c]<<" ";

//Printing quiz scores
cout << " Your eight quiz scores: " << " ";
quiz = student->getQuizs();
for(int c = 0; c < 8; c++)
cout<< quiz[c]<<" ";

//Printing Program scores
cout << " Your ten program scores: " << " ";
program = student->getPrograms();
for(int c = 0; c < 10; c++)
cout<< program[c]<<" ";

//Printing average exam score
cout << " Your average Exam score: " << student->getAverage(scores, 3);
cout << " ";

//Printing average quiz score
cout << " Your average Quiz score: " << student->getAverage(quiz, 8);
cout << " ";

//Printing average program score
cout << " Your average Program score: " << student->getAverage(program, 10);
cout << " ";

delete student;
//Default Constructor

//Creating an object using default constructor
StudentInfo ss;

//Reading name
fflush(stdin);
cout << " Enter first name: ";
getline(cin, temp);

//Soring into object
ss.setFirstName(temp);

//Reading name
cout << " Enter last name: ";
getline(cin, temp);

//Soring into object
ss.setLastName(temp);

fflush(stdin);
//Reading scores
cout << " Enter three scores separated by space: ";
for(c = 0; c < 3; c++)
cin >> scores[c];
//Soring into object
ss.setExams(scores, 3);

//Reading Quiz mark
cout << " Enter eight scores separated by space: ";
for(c = 0; c < 8; c++)
cin >> quiz[c];
//Soring into object
ss.setQuizs(quiz, 8);

//Reading program mark
cout << " Enter ten scores separated by space: ";
for(c = 0; c < 10; c++)
cin >> program[c];

//Soring into object
ss.setPrograms(program, 10);

//Greeting user
cout << " Hello " << ss.getFirstName() << " " << ss.getLastName() << " ";
//Printing Exam scores

cout << " Your three exam scores: " << " ";
scores = ss.getExam();
for(int c = 0; c < 3; c++)
cout<< scores[c]<<" ";

//Printing quiz scores
cout << " Your eight quiz scores: " << " ";
quiz = ss.getQuizs();
for(int c = 0; c < 8; c++)
cout<< quiz[c]<<" ";

//Printing Program scores
cout << " Your ten program scores: " << " ";
program = ss.getPrograms();
for(int c = 0; c < 10; c++)
cout<< program[c]<<" ";

//Printing average exam score
cout << " Your average Exam score: " << ss.getAverage(scores, 3);
cout << " ";

//Printing average quiz score
cout << " Your average Quiz score: " << ss.getAverage(quiz, 8);
cout << " ";

//Printing average program score
cout << " Your average Program score: " << ss.getAverage(program, 10);
cout << " ";

//Parameterized Constructor
//Reading name
fflush(stdin);
cout << " Enter first name: ";
getline(cin, temp);

//Reading name
cout << " Enter last name: ";
getline(cin, temp1);
fflush(stdin);
//Reading scores
cout << " Enter three scores separated by space: ";
for(c = 0; c < 3; c++)
cin >> scores[c];

//Reading Quiz mark
cout << " Enter eight scores separated by space: ";
for(c = 0; c < 8; c++)
cin >> quiz[c];

//Reading program mark
cout << " Enter ten scores separated by space: ";
for(c = 0; c < 10; c++)
cin >> program[c];

//Creating an object using parameterized constructor
StudentInfo ssp(temp, temp1, scores, quiz, program);

//Greeting user using parameterized constructor
cout << " Hello " << ssp.getFirstName() << " " << ssp.getLastName() << " ";

//Printing Exam scores
cout << " Your three exam scores: " << " ";
scores = ssp.getExam();
for(int c = 0; c < 3; c++)
cout<< scores[c]<<" ";

//Printing quiz scores
cout << " Your eight quiz scores: " << " ";
quiz = ssp.getQuizs();
for(int c = 0; c < 8; c++)
cout<< quiz[c]<<" ";

//Printing Program scores
cout << " Your ten program scores: " << " ";
program = ssp.getPrograms();
for(int c = 0; c < 10; c++)
cout<< program[c]<<" ";

//Printing average exam score
cout << " Your average Exam score: " << ssp.getAverage(scores, 3);
cout << " ";

//Printing average quiz score
cout << " Your average Quiz score: " << ssp.getAverage(quiz, 8);
cout << " ";

//Printing average program score
cout << " Your average Program score: " << ssp.getAverage(program, 10);
cout << " ";
return 0;
}

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