C For the given class definition below make the following th
Solution
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

