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
Describe one type of technology that is useful in producing images from space.
marta [7]
One technology is the telescope
8 0
3 years ago
Which statement are true regarding mainframe computers
Dominik [7]

what are the answer choices?

5 0
4 years ago
In what kind of attack can attackers make use of hundreds of thousands of computers under their control in an attack against a s
Allisa [31]

Answer:

distributed denial of service

Explanation:

5 0
3 years ago
Read 2 more answers
PLEASE I NEED HELP FAST
tankabanditka [31]

Answer:

your answer will be src=

7 0
3 years ago
Create a report showing the Order ID, the name of the company that placed the order, and the first and last name of the associat
8090 [49]

Answer:

/******************************

Both of the queries below will work in SQL Server

Oracle

******************************/

SELECT o.OrderID, c.CompanyName, e.FirstName, e.LastName

FROM Orders o

JOIN Employees e ON (e.EmployeeID = o.EmployeeID)

JOIN Customers c ON (c.CustomerID = o.CustomerID)

WHERE o.ShippedDate > o.RequiredDate AND o.OrderDate > '1-Jan-1998'

ORDER BY c.CompanyName;

/******************************

MySQL

******************************/

SELECT o.OrderID, c.CompanyName, e.FirstName, e.LastName

FROM Orders o

JOIN Employees e ON (e.EmployeeID = o.EmployeeID)

JOIN Customers c ON (c.CustomerID = o.CustomerID)

WHERE o.ShippedDate > o.RequiredDate AND o.OrderDate > '1998-01-01'

ORDER BY c.CompanyName;

8 0
3 years ago
Other questions:
  • Where can you access all the formatting options for worksheet cells?
    5·1 answer
  • Explain the advantages of taking the aspire test
    15·1 answer
  • The bluecross blueshield federal employee program (fep) is a(n) __________ health benefits program established by an act of cong
    8·1 answer
  • The Leader Motive Profile (LMP) includes a: a. high need for power. b. low need for achievement. c. moderate need for power. d.
    6·1 answer
  • Convert binary number 11101111.10111 to decimal
    5·1 answer
  • Post as a reply your example of "data, which is processed into information" case - examples should not necessarily be related to
    13·1 answer
  • Which is better Play Station Xbox or PC
    14·2 answers
  • What is the deference between touch screen phone and keypad phone
    6·1 answer
  • A system analyst generally needs to have a number of skills. For example, technical and analytical skills are required for this
    7·1 answer
  • I NEED THIS ASAP
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!