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
int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; Write a C++ program to ask the user to enter a number, if the number can b
Inessa [10]

Answer:

The c++ program to implement search through an array is shown.

#include <iostream>

using namespace std;  

int main()  

{

   int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 };

   int input;

   int found = 0;

   cout << " This program confirms whether your element is present in the array. " << endl;

   cout << " Enter any number  " << endl;

   cin >> input;

   for( int k = 0; k < 10; k++ )

   {

       if( input == sequence[k] )

           found = found + 1;

   }

   if( found == 0 )

       cout << " Not Found " << endl;

   else

       cout << " Found " << endl;

   return 0;

}

OUTPUT

This program confirms whether your element is present in the array.  

Enter any number  

7

Found

Explanation:

The program uses the given integer array.

User is prompted to input any number. No validation is implemented for user input since it is not mentioned. The user input is taken in an integer variable, input.

int input;

cout << " Enter any number " << endl;

   cin >> input;

Another integer variable found is declared and initialized to 0.

int found = 0;

Inside for loop, each element is compared with the user input.

If the user input is present in the given array, variable found is incremented by 1.

for( int k = 0; k < 10; k++ )

   {

       if( input == sequence[k] )

           found = found + 1;

   }

If value of variable found is 0, program displays “ Not Found ”.

If the value of variable found is greater than 0, program displays “ Found ”.

if( found == 0 )

       cout << " Not Found " << endl;

   else

       cout << " Found " << endl;

This program can be tested for both positive and negative numbers.

7 0
3 years ago
Why are rules required for a number system to be useful?
evablogger [386]

Answer

This is because without them no one would know how much each symbol represents, and no one would be able to decipher the message.

Explanation

Number system is a way to represent numbers. It  is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

In computing or in a computer number systems are the techniques which represents numbers in the computer system architecture where   every value that you are saving or getting into/from computer memory has a defined number system.Computer architecture supports  . Binary number system,Octal number system and Decimal number system.

5 0
3 years ago
Read 2 more answers
What do you believe are the advantages of a clean install over an upgrade? What additional choices do you think are important to
Allushta [10]

Answer:

Upgrade refers to upgrading to a new version from old version

Clean Install: Removing old version completely and install from scratch

Explanation:

Let you want to upgrade windows server 2008 to windows server 2016.There are 2 options

1. you can directly migrate windows server 2008 to 2016 by keeping everything as it is , so all the data and applications on the system remains as it is and only OS will upgrade.

2. uninstall everything and clean install windows server 2016.Here all previous applications and data are erased

In the above case if all applications on the system are compatible with windows server 2016 from 2008 we can go for upgrade directly otherwise it is better to go with clean install as we need different version of application which is compatible with windows server 2016

3 0
3 years ago
Define generation of computer ​
steposvetlana [31]

Answer:

The generation of computer is define as the devlopment in computer hardware/software,their processing speed and their language.

I HOPE IT HELP YOU

5 0
2 years ago
Why are websites operated by recognized print publishers, such as newspapers and journals, generally accurate and reliable?
leonid [27]
I think the correct answer would be that the <span>contents has usually been reviewed and edited by experts. These websites are required to do as such since it is how they make money from it. And if information are erroneous, it would make a big problem. Hope this helps.</span>
8 0
3 years ago
Read 2 more answers
Other questions:
  • HELP!!!! I need this ASAP
    9·1 answer
  • A species of snake lives in a rainforest. Which would be an adaptation for this
    10·2 answers
  • Why are fixed resistors’ values indicated by color bands rather than printing the numeric value on their exterior?
    13·1 answer
  • Can you find the ip address from a physical address
    13·1 answer
  • ???????????????????????​
    10·1 answer
  • Write an essay about yourself based on the dimensions of ones personality​
    9·1 answer
  • Assembly language program wich indetify largest number from the five elements 51,44,67,30,99​
    13·1 answer
  • В.
    11·1 answer
  • List different examples of models​
    5·1 answer
  • Computer networks that use packet switching are less efficient than telephone networks that use circuit switching.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!