Rewrite this program using an inline function to perform the calculation. #inclu
ID: 3797309 • Letter: R
Question
Rewrite this program using an inline function to perform the calculation.
#include <iostream>
#include <ctime>
using namespace std;
void MultiplyElements()
{
double num = 100;
double num2 = 10099;
double arr1[10000];
double arr2[10000];
for (int i = 0; i <10000; i++)
{
arr1[i] = num;
arr2[i] = num2;
const double result = arr1[i] * arr2[i];
num++;
num2--;
cout << "Result: " << result << endl;
}
}
int main()
{
clock_t start, end, elapsed;
start = clock();
MultiplyElements();
end = clock();
elapsed = end - start;
cout << "Time taken to perform Multiplication is: " << ((float)elapsed) / CLOCKS_PER_SEC << "s" << endl;
}
Explanation / Answer
#include <iostream>
#include <ctime>
using namespace std;
class operation{
double num = 100;
double num2 = 10099;
double arr1[10000];
double arr2[10000];
public:
void MultiplyElements();
};
inline void operation :: MultiplyElements()
{
for (int i = 0; i <10000; i++)
{
arr1[i] = num;
arr2[i] = num2;
const double result = arr1[i] * arr2[i];
num++;
num2--;
cout << "Result: " << result << endl;
}
}
int main()
{
clock_t start, end, elapsed;
start = clock();
operation s;
s.MultiplyElements();
end = clock();
elapsed = end - start;
cout << "Time taken to perform Multiplication is: " << ((float)elapsed) / CLOCKS_PER_SEC << "s" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.