1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elina [12.6K]
3 years ago
9

For this assignment, you will use pointers to write a program that can be used to gather statistical data about the number of mo

vies 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 include comments throughout your code where appropriate.
Complete the C++ code
Computers and Technology
1 answer:
salantis [7]3 years ago
4 0

Answer:

Following are the program to the given question:

#include <iostream>//header file

#include <bits/stdc++.h>//header file

using namespace std;

int main()//main method

{

   int x,i,sum=0;//defining integer variable

   double average, median;//defining double variable

   cout<<"How many students were surveyed? ";//print message

   cin>>x;//input value

   int *a = new int[x]; //dynamically created array

   for(i = 0;i<x;i++)//defining for loop to input value in array

   {

       cout<<"Enter the number of movies seen by student number "<<i+1<<": ";//print message  

       cin>>a[i];//input value

   }

   for (int i = 0; i < x; i++)//defining loop for add value

       sum += a[i];   //use sum to add array value

   average = (double)sum/x;//defining average variable to calculate average

   cout<<"Average is "<<average<<endl;//print average value with message

   sort(a, a+x); //use sort method to sort array to find the median

   if (x % 2 != 0)//use if to check the even value

      median = (double)a[x/2];//calculating the median value

   else//esle block

       median = (double)(a[(x-1)/2] + a[x/2])/2.0;//calculating median value

   cout<<"Median is "<<median<<endl;//print median value with message

   int m_count=1 ,mode= a[0], c_count = 0;//defining integer variable

   for( i=1;i<x;i++)//defining for loop arrenge value

   {

       if(a[i]==a[i-1])//use if to check array value

       {

           c_count++;//increment c_count variable value

       }

       else//else block

       {

           if(c_count>m_count)//use if to check c_count greater than m_count

           {

               m_count = c_count;//holding value in m_count

               mode = a[i-1];//holding mode value

           }

           c_count = 1;//holding value integer value in c_count

       }

   }

   cout<<"Mode is "<<mode;//print mode value with message

   return 0;

}

Output:

Please find the attachment file.

Explanation:

  • Including header file.
  • Defining the main method.
  • Declaring integer and double type variables.
  • Declaring integer array.
  • Use the loop to the input value.
  • After input, the value uses double variable "average, the median" that uses the for loop and conditional statement to check the value and hold in its variable.
  • In the next step, another integer variable "m_count, mode, and c_count" is defined that uses the loop and conditional statement to check the median and mode value and hold its value into their variable.

You might be interested in
What does "CPU" stand for?
MrMuchimi
Central processing unit
7 0
3 years ago
Read 2 more answers
How are the current and resistance related when the voltage of a circuit is constant?
andreev551 [17]
Since resistance and current are inversely proportional, when the resistance doubles, the current is cut in half.
5 0
2 years ago
Read 2 more answers
What is the minimum amount of hard drive space required for a 64-bit Windows 10 installation?
BaLLatris [955]

The minimum requirements for a 64-bit Windows 10 installation are 2 GB of RAM and a minimum of 16 GB of space on the hard drive.

<em>Hope this helps :)</em>

7 0
1 year ago
Select the two true statements about functions with parameters:
kondor19780726 [428]

Answer:

Option (B) and (C) is the correct option to the following question.

Explanation:

Because the function is the module of the program and we call that function again and again anywhere whenever we need that function in the program.

Function is used to carry out any operation which is used in the program many times and it creates the program short and simple.

<u>For example</u>: if we need to add or multiply two numbers many times in the program then, we create one or two functions for addition and subtraction or one program for both, when we need them we call them.

4 0
2 years ago
Give four characteristics of hard disk​
Lubov Fominskaja [6]

Answer:

1. Mass Storage Devices

2. Available Storage Space

3. Data Access Performance

4. Device Form Factor and Connection

3 0
3 years ago
Other questions:
  • What is a motherboard?
    6·2 answers
  • Every application program has a _______________ segment
    6·1 answer
  • When you first start your computer, which software will have to start first?
    5·2 answers
  • Which version of Windows was considered an operating environment rather than an operating system? Windows 1.0 Windows 3.0 Window
    9·1 answer
  • Which of the following people was a member of FFA?
    7·1 answer
  • You are photographing your friend in a local park which of the following might be supporting details you want to include in the
    6·1 answer
  • In Access, it is possible to have _______________ fields, that is, fields that can contain more than one value.
    9·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    9·1 answer
  • What is the first phase of the project process?
    14·2 answers
  • How can structure of a table change in sql. What general types of changes are possible
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!