#include<bits/stdc++.h>
using namespace std;
template<class T>
class ArrayCalc {
public:
void FindMin(T inArrayData[],int
inArraySize, T &outMinVal );
void FindMax(T inArrayData[],int
inArraySize, T &outMaxVal );
void CalcSum(T inArrayData[],int
inArraySize, T &outSumVal );
void CalcAvg(T inArrayData[],int
inArraySize, T &outAvgVal );
};
template <class T>
void ArrayCalc<T>::FindMin(T inArrayData[],int inArraySize, T
&outMinVal )
{
for(int i=0;i<inArraySize;i++)
{
if(inArrayData[i]<outMinVal)
{
outMinVal=inArrayData[i];
}
}
}
template <class T>
void ArrayCalc<T>::FindMax(T inArrayData[],int inArraySize, T
&outMaxVal )
{
for(int i=0;i<inArraySize;i++)
{
if(inArrayData[i]>outMaxVal)
{
outMaxVal=inArrayData[i];
}
}
}
template <class T>
void ArrayCalc<T>::CalcSum(T inArrayData[],int inArraySize, T
&outSumVal )
{
for(int i=0;i<inArraySize;i++)
{
outSumVal+=inArrayData[i];
}
}
template <class T>
void ArrayCalc<T>::CalcAvg(T inArrayData[],int inArraySize, T
&outAvgVal )
{
for(int i=0;i<inArraySize;i++)
{
outAvgVal+=inArrayData[i];
}
outAvgVal=outAvgVal/inArraySize;
}
int main()
{
int n; //size of array should always in
int
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
cin>>ar[i];
int outMinVal=INT_MAX;
int outMaxVal=INT_MIN;
int outAvgVal=1;
int outSumVal=0;
ArrayCalc<int>a;
a.FindMin(ar,n,outMinVal);
a.FindMax(ar,n,outMaxVal);
a.CalcSum(ar,n,outSumVal);
a.CalcAvg(ar,n,outAvgVal);
cout<<"The Minimum value is
"<<outMinVal<<endl;
cout<<"The Maximum value is
"<<outMaxVal<<endl;
cout<<"The Average value is
"<<outAvgVal<<endl;
cout<<"Total Sum is
"<<outSumVal<<endl;
return 0;
}
//Output for int type
//output for float type
Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on...
c++ Q.2. a) Create a C++ class template called MathCalc, to perform arithmetic operations between two numbers. These arithmetic operations are addition, subtraction, multiplication and division. The MathCalc class template accepts two type parameters, which can be defined as: template <class T, class U>. This allows MathCalc to carry out arithmetic operations between two different data types. MathCalc has the following public methods, described here in pseudocode: i. Ret Sum(augend, addend); Ret is the return value of the method. ii....
In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...
Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output:
Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template of the solution, if you need Write a program that asks users to input 10 integers into an array, write a function that takes the array as its argument, use bubble sort to sort the array and output the sorted array in increasing order. #include <iostream> using namespace std; C:IWINDOWSSystems2cmd.exe lease input 10 integers: void bubblesort(int a[10]) int help; int b[10]; for (int i...
#ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO:: default constructor perform new to reserve memory of size INITIAL_CAPACITY. set num_items = 0; */ heap() { // write your code here }; /** Create a heap from a given array */ heap(dtype *other, size_t len) { // write your code here }; /** copy constructor copy another heap to this heap. */ heap(const heap<dtype> &other) { //write your code here }; /** Accessor...
Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...
members of a class non-friends, non-members of a class All of the above be 13. Why do you want to usually make data members private in a class? so that no one can use the class ensure data integrity b. provide data abstraction c provide information hiding. d. e. Band D B.C and D 14. The copy constructor for a class is called when an object of the class is passed by value to a function. when an object of...
Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Description The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. s is shown below: Write a program that...