Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this module you reflected on many of the basic C++ skills you learned in CIS 211 and learned about pointers and how to implement

In this module you reflected on many of the basic C++ skills you learned in CIS 211 and learned about pointers and how to implement them in your C++ programs.

For this assignment, you will use pointers to write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user to enter the number of movies each student has seen. The program should then calculate the average, median, and mode of the values entered. Be sure to including comments throughout your code where appropriate.

Complete the C++ code using Visual Studio or Xcode, compress (zip) and upload the entire project folder to the Blackboard assignment area by clicking on the Browse My Computer button or by dragging the file inside the Attach Files box.

This is what I have so far but getting an error.

#include #include #include using namespace std;

void calculations(int* arr, int* num_students);

int main() {

int *num_students; int arr;

//Get number of students surveyed cout << "How many students were surveyed?"; cin >> arr;

//Create the array num_students = new int[arr];

for (int i = 0; i < arr; i++) { cout << "Enter the amount of movies seen by student #" << (i + 1) << ": "; cin >> num_students[i]; }

//Call calculations calculations(&arr, &num_students); }

void calculations(int* arr, int* num_students) { //Initialize temp and size pointers and store size of array in size int sum = 0, * temp, * size; *size = *num_students;

//Loop to find sum of array values for (int i = 0; i < *num_students; i++) { sum += arr[i]; }

//Find average and print cout << "Average number of movies watched: " << sum / *num_students << endl;

//sort the array for (int i = 0; i < *num_students; i++) { for (int s = 0; s < *num_students - 1; s++) { if (arr[s] > arr[s + 1]) { *temp = arr[s]; arr[s] = arr[s + 1]; arr[s + 1] = *temp; } } }

//Find Median if (*num_students % 2 == 0) { int one = *num_students / 2; float median = (arr[one - 1] + arr[one]) / 2.0; cout << "The median is: " << median << endl; }

else { cout << "The median is: " << arr[(*num_students / 2)] << endl; }

//Find mode int maxValue = 0; int maxCount = 0;

for (int i = 0; i < *size; ++i) { int count = 0; for (int s = 0; s < *size; ++s) { if (arr[s] == arr[i]) { ++count; } }

if (count > maxCount) { maxCount = count; maxValue = arr[i]; } }

//print mode cout << "Mode is: " << maxValue << endl; }

Severity Code Description Project File Line Suppression State Error (active) E0167 argument of type "int **" is incompatible with parameter of type "int *" line 26

Severity Code Description Project File Line Suppression State Error C2664 'void calculations(int *,int *)': cannot convert argument 2 from 'int **' to 'int *' line 26

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

4. EMC Corporation

Answered: 1 week ago

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago