Question

Purpose: Learn to use arrays. Instructions: This is a project you will work on with a...

Purpose:

Learn to use arrays.

Instructions:

This is a project you will work on with a group of 3 (or 4) students.

Groups of 3 will already have a left and right partner.

Your assignment is to learn how to create code for others to use and how to use other people's code in your own project. Working with others is often a challenge especially when you haven't worked with them previously. If you know one of your partners from outside the class, you'll need to choose a different partner.

You will create a function that calculates the "Sample Standard Deviation" on an array of N ints where the value of N is 25 - strlen(your middle name). If you don't have a middle name, strlen will return 0.

You will need to create an array of random int values you will place into an array in code. DO NOT enter the values through std::cin.

You will give your function to your right partner and your data to your left partner.

Likewise, you will receive data from your right partner and a function from your left partner.

Your function should be placed in .cpp file by itself and include a .h (header) file with the function declaration.

You should now have 2 sets of data and 2 functions.

Run all 4 combinations in one program and test that the Sample Standard Deviation functions both produce the same results for the same data set. This means you will have 2 tests, one for each set of data.

You should compare your results with your partners. They should produce the same results. If not, work out why.

Proper submission is extremely important, so be sure to look over the guidelines.

For help with formulas, here is a site that might help you:

https://www.mathsisfun.com/data/standard-deviation-formulas.html

0 0
Add a comment Improve this question Transcribed image text
Answer #1
declarations.h
double getStandardDeviation(int array[], int size);
void getRandomNumbersArray(int array[], int size);
void printArray(int array[], int size);
SampleStd.cpp

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<string.h>

#include<cmath>

#include"declarations.h"

using namespace std;

// main function

int main()

{

srand(time(NULL)); // seeding the random number generator

char middleName[50];

cout << "Enter your middle name: "; // inputting the middle name

fgets(middleName, 50, stdin);

int size = 25 - strlen(middleName); // deciding the size of array

int array[size];

getRandomNumbersArray(array, size); // calling the function to populate the array

cout << "\nArray generated is." << endl;

printArray(array, size);

cout << endl;

double std = getStandardDeviation(array, size); // calculating the std

cout << endl;

cout << "Sample Standard Deviation is: " << std << endl;

}

// function to calculate and return the standard deviation

double getStandardDeviation(int array[], int size)

{

double mean = 0;

int sum = 0;

double squared_diff = 0;

for(int i = 0; i < size; i++)

sum += array[i];

mean = sum / size;

for(int i = 0; i < size; i++)

{

squared_diff += pow((array[i] - mean), 2);

}

squared_diff /= size - 1;

return sqrt(squared_diff);

}

// function to populate the arrray with random numbers

void getRandomNumbersArray(int array[], int size)

{

for(int i = 0; i < size; i++)

{

// generating a random number in range -10 to 100

array[i] = -10 + (rand() * (int)(100 - -10) / RAND_MAX);

}

}

// printing the array

void printArray(int array[], int size)

{

for(int i = 0; i < size; i++)

cout << array[i] << " ";

}

NOTE: Create a header file named declarations.h and another file SampleStd.cpp and copy - paste its respective codes into it and save. Now, run the main file SampleStd.cpp

OUTPUT

E:\Program Files Cplusplus workspace SampleStd.exe nter your middle name: william rray generated is 4 74 48 44 8 94 13 17 29

Add a comment
Know the answer?
Add Answer to:
Purpose: Learn to use arrays. Instructions: This is a project you will work on with a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • I need help with the following code... Instructions: This lab builds on the skills from Lab...

    I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...

  • Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std;...

    Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std; int read_function(int array[], int, int); int main() { int array[300], numba; read_function(array[300]); cout << "Enter a whole number between 2-20: " << endl; cin >> numba; read_function(numba); return 0; } int read_funtion (int arr[300], int num, int Values) { int sum=0; ifstream array_file; array_file.open("Lab8.dat"); for(int i=0; i < 300; i++) {   array_file >> arr[i];   cout << arr[i];   sum += i; } cout << sum;...

  • how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays....

    how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays. Write the three functions described below. Demonstrate that your code works by calling each function and printing out the results. All of your code should be in one file. Upload your java code and a file containing the output of running your program to show that it works. Write a function called create2DIntArray that creates a two-dimensional array of integers between 0 and 10....

  • Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for...

    Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for this purpose. For your initial implementation, use ordered insertion to keep the words in order and ordered sequential search when looking for words. Note that the array utility functions from the lecture notes are available to you as art of the provided code. Although we are counting words in this program, the general pattern of counting occurrences of things is a common analysis step...

  • COSC 1437 C++ Project Assignment 2 Poll Summary Utilize a dynamic array of structure to summarize...

    COSC 1437 C++ Project Assignment 2 Poll Summary Utilize a dynamic array of structure to summarize votes for a local election Specification: Write a program that keeps track the votes that each candidate received in a local election. The program should output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. To solve this problem, you will use one dynamic...

  • C programming. please include comments In this lab, you will learn to read data from and...

    C programming. please include comments In this lab, you will learn to read data from and write data to a file - another use for pointers. SAMPLE PROGRAM There are two sample programs this week - WriteFile.c and ReadFile.c. The first, WriteFile.c, allows the user to enter customer names (first, middle, and last), and writes each name to an output text file, customerNames.txt. formatted as: firstName middlelnitial lastName" After you've run it once, what happens to the names you added...

  • The purpose of the project is to perform a timing experiment. You are required to complete...

    The purpose of the project is to perform a timing experiment. You are required to complete the following activities: Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then usees the bubble sort to order the array. The program should print out the array prior to the call to the sorting algorithm and afterwards. You can write the program in either Java, C++, C#, or whatever language you...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Project 2 Sorting, CPU Time, and Big O Analysis Note: you will be using Microsoft Visual...

    Project 2 Sorting, CPU Time, and Big O Analysis Note: you will be using Microsoft Visual Studios 2019 as the compiler. This is an individual assignment. You will have lab time to work on this assignment as well as homework time. Each person will analyze two sorts. The first sort will be either bubble sort or insertion sort. The second sort will be either quick sort or merge sort. Create two projects, one for each sort in the given choices....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT