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

C++ For the given class definition below, make the following three modifications

ID: 3933961 • Letter: C

Question

C++ For the given class definition below, make the following three modifications: 1) add a new public array (named: speeds) to hold up to 100 offset CPU speeds as floating point values. 2) add the initialization of the array values to 0.0, and 3) fill in the method code for the specified method calculations. Remember that in both the methods, the calculation should be performed only on the array elements that are greater than zero. Start by copy-pasting the class definition below into your editing window. You only need to write the class definition and any code mat is required for that class. Place all your code within the class definition. class CorputerLob {public: string name;//name of lab// public: ComputerLab() {name = "";//} ??? CalcAverage() {//insert code here} ??? CalcTotalCPUSpeed() {//insert code here}}; Answer: class ComputerLab

Explanation / Answer

PROGRAM CODE:

//============================================================================
// Name : Sample.cpp
// Author : Kaju
// Version :
// Copyright : This is just an example code
// Description : C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class ComputerLab
{
public:
   string name; //name of the lab
   float speeds[100]; // 1) declaration of array

public:
   ComputerLab()
   {
       name = "";
       for(int i=0; i<100; i++) // initialization of the array
       {
           speeds[i] = 0.0;
       }
   }

   float CalcAverage()
   {
       float tot = 0.0;
       for(int i=0; i<100; i++) // Average calculation method - looping 100 times to get the total
       {
           tot = tot + speeds[i]; // adding the current speed to the tot variable
       }
       return tot/100;//dividing the tot variable by 100 to get the average
   }

   float CalcTotalCPUSpeed() // total speed calculation method
   {
       float total = 0.0;
       for(int i=0; i<100; i++) // looping through the array to get the total
       {
           total = total + speeds[i];
       }
       return total; //returning the total
   }
};

int main() {
   ComputerLab lab;
   cout<<"Total: "<<lab.CalcTotalCPUSpeed()<<endl;
   cout<<"Average: "<<lab.CalcAverage()<<endl;
   return 0;
}

OUTPUT:

Total: 0

Average: 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