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

We are given some code and we have to convert it to object oriented programming.

ID: 3547957 • Letter: W

Question

We are given some code and we have to convert it to object oriented programming.

Here's the problem statement: Write a class that holds the necessear variables and functions. Use main to instantiate the class and call these functions. Your could should have the same functionality(how average after the lowest score gets dropped) as the given code given but should use classes. All your functions should now belong to the class you define.

Constraints: All the variable in the class are private. The functions defined in the class are public.

Pay attention to :

1. Do you define your array test score in the main or in your class?

2. If you define it in your class would you need to pass it in each function as an arguement of can your class functions access the variables defined in the class?


This is the code given to us:


#include <iostream>

#include <cmath>

#include <ctime>

#include <iomanip>


using namespace std;


// Function Prototypes

void getTestScores( double[], int);

double getTotal( double[], int);

double getLowest( double[], int);


int main () {


const int SIZE = 4; // Array size

double testScores[SIZE], // Array of test scores

total, // Total of the scores

lowestScore, // Lowest test score

average; // Average test score


// Set up the numeric output formatting.

// See Appendix for notes on how this manipulator works.

cout << setprecision(4);


// Get the test scores from the user

getTestScores(testScores, SIZE);


// Get the total of the test scores

total = getTotal(testScores, SIZE);


// Get the lowest test score

lowestScore = getLowest(testScores, SIZE);


// Subtract the lowest score from the total.

total -= lowestScore;


// Calculate the average. Divide by 3 because

// the lowest score was dropped

average = total / (SIZE - 1 );


// Display the average

cout << "The average with the lowest score"

<< " dropped is " << average << endl;



return 0;

}


//********************************************************

// The getTestScores function accepts an array and its size

// as arguments. It prompts the user to enter test scores,

// which are stored in the array

// ********************************************************


void getTestScores( double scores[], int size )

{

// Loop counter

int index;


// Get each test score.

for (index = 0; index <= size-1; index++) {

cout << "Enter test score number" << index+1 << ":";

// enter your code here. Hint: use cin and read each element in the array.

cin >> scores[index];

}

}


//**********************************************************

// The getTotal function accepts a double array

// and its size as arguments. The sum of the array's

// elements is returned as a double.

//**********************************************************


double getTotal(double array[], int size)

{

double total = 0; // Accumulator


// Add each element to total

for (int count = 0; count < size; count++) {

total = total + array[count];

}

// return the total

return total;


}


//*********************************************************

// The getLowest function accepts a double array and its

// size as arguments. The lowest value in the array is

// returned as a double.

//*********************************************************


double getLowest(double array[], int size)

{

double lowest;


// Get the first array's element

lowest = array[0];


// Step through the rest of the array. When a value

// less than the lowest is found, assign it to lowest

for (int count = 1; count < size; count++) {

if (array[count]<lowest) {

lowest = array[count];

}

}


// Return the lowest value

return lowest;

}

Explanation / Answer

// test.cpp : Defines the entry point for the console application.
//

#include <iostream>

#include <cmath>

#include <ctime>

#include <iomanip>


using namespace std;

public void getTestScores( double[], int);

public double getTotal( double[], int);

public double getLowest( double[], int);



class example
{

public void getTestScores( double scores[], int size )

{

// Loop counter

    int index;

// Get each test score.

    for (index = 0; index <= size-1; index++) {

    cout << "Enter test score number" << index+1 << ":";

// enter your code here. Hint: use cin and read each element in the array.

    cin >> scores[index];

}

}

//*********************************************************

// The getLowest function accepts a double array and its

// size as arguments. The lowest value in the array is

// returned as a double.

//*********************************************************


public double getLowest(double array[], int size)

{

double lowest;


// Get the first array's element

lowest = array[0];


// Step through the rest of the array. When a value

// less than the lowest is found, assign it to lowest

for (int count = 1; count < size; count++) {

if (array[count]<lowest) {

lowest = array[count];

}

}


// Return the lowest value

return lowest;

}

//**********************************************************

// The getTotal function accepts a double array

// and its size as arguments. The sum of the array's

// elements is returned as a double.

//**********************************************************


public double getTotal(double array[], int size)

{

double total = 0; // Accumulator


// Add each element to total

for (int count = 0; count < size; count++) {

total = total + array[count];

}

// return the total

return total;


}

}








public static int main () {


const int SIZE = 4; // Array size

double testScores[SIZE], // Array of test scores

total, // Total of the scores

lowestScore, // Lowest test score

average; // Average test score


// Set up the numeric output formatting.

// See Appendix for notes on how this manipulator works.

cout << setprecision(4);


// Get the test scores from the user

getTestScores(testScores, SIZE);


// Get the total of the test scores

total = getTotal(testScores, SIZE);


// Get the lowest test score

lowestScore = getLowest(testScores, SIZE);


// Subtract the lowest score from the total.

total -= lowestScore;


// Calculate the average. Divide by 3 because

// the lowest score was dropped

average = total / (SIZE - 1 );


// Display the average

cout << "The average with the lowest score"

<< " dropped is " << average << endl;



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