for this assignment you will be creating a series of functions for manipulating an array of data. The data will consist of randomly generated doubles. You should make the following functions:
Make sure to write a main() function that tests each of the functions. It should use the generate() function to fill the array. If you can't finish all of the functions make a note of which ones you did finish in the code comments.
Thanks for the question, here is the complete code including the extra credit part.
thank you !!
=======================================================================
#include<iostream>
#include <cmath>
#include<cstdlib>
using namespace std;
void generate(double data[], int size, int lower, int
upper){
for(int i=0; i<size;i++){
data[i] = ((double) rand() /
(RAND_MAX))*(upper-lower) + lower;
}
}
void print(double data[], int size){
for(int i=0; i<size;i++){
cout<<data[i]<<"
";
}
cout<<endl<<endl;
}
double average(double data[], int size){
double total = 0;
for(int i=0; i<size;i++){
total+=data[i];
}
return total/size;
}
double min(double data[], int size){
double min_val=0;
for(int i=0; i<size; i++){
if(i==0)min_val=data[0];
else
if(min_val>data[i])min_val=data[i];
}
return min_val;
}
double max(double data[], int size){
double max_val=0;
for(int i=0; i<size; i++){
if(i==0)max_val=data[0];
else
if(max_val<data[i])max_val=data[i];
}
return max_val;
}
void addX(double data[], int size, double delta){
for(int i=0; i<size; i++){
data[i]+=delta;
}
}
int num_less(double data[], int size){
double avg = average(data,size);
int count=0;
for(int i=0; i<size; i++){
count+=data[i]<avg?1:0;
}
return count;
}
int num_more(double data[], int size){
double avg = average(data,size);
int count=0;
for(int i=0; i<size; i++){
count+=data[i]>avg?1:0;
}
return count;
}
int num_less(double data[], int size, double
threshold){
int count=0;
for(int i=0; i<size; i++){
count+=data[i]<threshold?1:0;
}
return count;
}
double range(double data[], int size){
return max(data,size) - min(data,size);
}
double std_dev(double data[], int size){
double avg = average(data,size);
double squared_sum=0;
for(int i=0; i<size;i++){
squared_sum +=
(data[i]-avg)*(data[i]-avg);
}
return pow(squared_sum/size,0.5);
}
int main(){
int size=20;
double data[size];
generate(data,size,-5.0,5.0);
print(data,size);
cout<<"Average:
"<<average(data,size)<<endl<<endl;
cout<<"Min Value:
"<<min(data,size)<<endl<<endl;
cout<<"Max Value:
"<<max(data,size)<<endl<<endl;
addX(data,size,1);
cout<<"Added 1 to all elements\n\n";
print(data,size);
cout<<"Num less than average:
"<<num_less(data,size)<<endl<<endl;
cout<<"Num more than average:
"<<num_more(data,size)<<endl<<endl;
cout<<"Num more than 0:
"<<num_less(data,size,0)<<endl<<endl;
cout<<"Range:
"<<range(data,size)<<endl<<endl;
cout<<"Standard Deviation:
"<<std_dev(data,size)<<endl<<endl;
}
=======================================================================

for this assignment you will be creating a series of functions for manipulating an array of...
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...
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...
Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...
In c++
1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...
For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....
#include <stdio.h>
// Define other functions here to process the filled array: average, max, min, sort, search
// Define computeAvg here
// Define findMax here
// Define findMin here
// Define selectionSort here ( copy from zyBooks 11.6.1 )
// Define binarySearch here
int main(void) {
// Declare variables
FILE* inFile = NULL; // File pointer
int singleNum; // Data value read from file
int valuesRead; // Number of data values read in by fscanf
int counter=0; // Counter of...
CST-117 In-Class Assignment 7 A method stub, or signature, is the first line of a method. Write a class that contains the following “stubs” for methods used in measurement conversion. You do not have to implement the methods. Here’s an example: Write a void method that takes an integer for the number of millimeters and displays the number of meters. Correct response: public void showMeters(int numMillimeters){} Write a method that takes two integers and displays their sum. Write a method...
Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...
Description For this assignment, you will maintain an array of bank accounts. You will declare a struct type called bankAcct and have an array of bankAcct with maximum size of 20, the members of the struct are shown below struct bankAcct { string first , last ; double amount ; long acctNo ; short pin ; }; Each member is described below • string first stores the user’s first name • string last stores the user’s last name • double...
Note: None of these functions should use cout. It is OK to use cout while debugging to check how your function is working, but your final submission should not contain cout in any function but main. Head ==== Name the source file for this section head.cpp. Write a function named "head" which takes an array of integers as an argument, and returns the first element in the array. Write a function named main which outputs the result of testing your...