Question
C++ The program makes use of arrays and pointers in a class definition. In this assignment, you will create a class called MovieStatistics . The
The program makes use of arrays and pointers in a class definition. In this assignment, you will create a class called MovieStatistics. The class contains:
an integer that keeps track of the number of students surveyed
an array that keeps track of the number of movies watched by each student surveyed.
The class private variables are:
an int pointer called movies_pointer
an int variable called numOfStudents
Class functions are described below:
Class Constructor. This function takes in an int and an int array. Suppose that it is invoked as follows:
int my_mov_array[5] = {23, 5, 6, 1, 5}; MovieStatistics my_movies(5, my_mov_array); The Constructor should:
set 5 (the first argument to function invocation) into numOfStudents class private variable
Create a 5 element int array and place address of newly created array into movies_pointer class private variable
Copy contents of the incoming parameter array (2nd parameter) into the newly created dynamic array whose address is maintained in movies_pointer
Do not copy incoming pointer into the class private pointer!
Class destructor : Release the array whose address is maintained in movies_pointer.
print. Print out the contents of the dynamic array whose address is maintained in the movies_pointer variable. Print out the average of the array contents.
sort_desc. Sort the contents of the dynamic array whose address is maintained in the movies_pointer variable in descending order
This assignment should be implemented in 3 files, which are:
MovieStatistics.h
MovieStatistics.cpp
assignment9_tester.cpp
Use the following code to test the MovieStatistics class
#include #include #include using namespace std; #include "MovieStatistics.h" int main() { int movies_numbers_Spring[7] = { 3, 6, 1, 3, 4, 9, 5 }; int movies_numbers_Fall[4] = { 7, 3, 9, 1 }; MovieStatistics stu_movies1(7, movies_numbers_Spring), stu_movies2(4, movies_numbers_Fall); cout << "**********Survey Data from Spring 2014************** "; cout << " -- Before Sort -- "; stu_movies1.print(); stu_movies1.sort_desc(); cout << " -- After Descending Sort -- "; stu_movies1.print(); cout << "**********Survey Data from Fall 2014************** "; cout << " -- Before Sort -- "; stu_movies2.print(); stu_movies2.sort_desc(); cout << " -- After Descending Sort -- "; stu_movies2.print(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started