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

1. chmod: WARNING: can\'t access prog.cpp chmod: WARNING: can\'t access ans.cpp

ID: 3733436 • Letter: 1

Question

1.

chmod: WARNING: can't access prog.cpp

chmod: WARNING: can't access ans.cpp

// Consider the class diagram below.

//

// +---------------------------------------+

// | class STUFF |

// | +---------------------+ |

// | | int x; | |

// | +---------------------+ |

// |--------------------+ +----------------|

// |void set_p(int val);| |void Show_x(); |

// |--------------------+ +----------------|

// |----------+ +----------------|

// | STUFF ();| | int p; |

// +---------------------------------------+

//

// Complete the declaration of this class using in-line member function definitions.

// The default constructor must initialize member variable p to 75, and x to 0.

// Show_x displays the value of member variable x.

// -------------------------------------------------------------------------

#include <iostream>

using namespace std;

class STUFF

{

};

// DO NOT MOVE OR DELETE.

#include "mainptclass71000.cpp"

2.

chmod: WARNING: can't access prog.cpp

chmod: WARNING: can't access ans.cpp

#include <iostream>

using namespace std;

//-----------------------------------------------------------------------------

// Define a class named STUDENT that has the following

// private

// members: string myName;

// integer array myScores of 5 test scores.

// public

// members: constructor STUDENT(string name) to initialize myName

// with string parameter, and set all test scores to -1.

// void function ReadScores -- to read 5 test scores from keyboard.

// int function AvgScore -- to compute and return average score.

// void Show -- to display name and scores.

//

// Use INLINE-DEFINITIONS for the member functions.

//----------------------------------------------------------------------------

class STUDENT

{

}

#include "mainptclass7800.cpp"

Explanation / Answer

1.ans

#include <iostream>

using namespace std;

/*Class definition*/

class STUFF

{

//Member variable

private:

int x;

int p;

//Inline member function definition

public:

void set_p(int val){

this->p = val;

}

void show_x(){

cout << "x = "<<this->x<<endl;

}

void show_p(){

cout << "p = "<<this->p<<endl;

}

STUFF(){

this->p =75;

this->x =0;

}

};

2.ans

#include<iostream>

using namespace std;

//Class definition

class STUDENT

{

//Member variable declaration

private :

string myName;

int myScores[5];

//Inline member function definitions

public:

STUDENT(string name){

this->myName = name;

for(int i=0;i<5;i++){

this->myScores[i] = -1;

}

}

void ReadScores(){

cout<<"Enter the scores of 5 tests :"<<endl;

for(int i=0;i<5;i++){

cin >>this->myScores[i];

}

}

int AvgScore(){

int sum = 0;

for(int i=0;i<5;i++){

sum = sum+this->myScores[i];

}

return sum/5;

}

void Show(){

cout<<"Name : "<<this->myName<<endl;

cout<<"Test scores are : "<<endl;

for(int i=0;i<5;i++){

cout<<this->myScores[i]<<endl;

}

}

};