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
Ipatiy [6.2K]
3 years ago
8

C++

Computers and Technology
1 answer:
nikitadnepr [17]3 years ago
8 0

Answer:

Check the explanation

Explanation:

<u>The Code</u>

#include <fstream>

#include <iostream>

#include <cmath>

#include <cstring>

#include <cstdlib>

#include <ctime>

using namespace std;

//Function Declarations

void fillArrayWithRandNos(int nos[],int size);

void displayArray(int nos[],int size);

double mean(int nos[],int size);

double variance(int nos[],int size);

double median(int nos[],int size);

int mode(int nos[],int size);

void histogram(int nos[],int size);

int main() {

  //Declaring variables

const int size=100;

srand(time(NULL));

 

// Creating array dynamically

int* nos = new int[size];

 

//Calling the functions

fillArrayWithRandNos(nos,size);

displayArray(nos,size);

cout<<"Mean :"<<mean(nos,size)<<endl;

cout<<"variance :"<<variance(nos,size)<<endl;

cout<<"Median :"<<median(nos,size)<<endl;

cout<<"Mode :"<<mode(nos,size)<<endl;

histogram(nos,size);

 

  return 0;

}

void fillArrayWithRandNos(int nos[],int size)

{

  for(int i=0;i<size;i++)

  {

      nos[i]=rand()%(45) + 55;

  }

}

void displayArray(int nos[],int size)

{

  cout<<"Displaying the array elements :"<<endl;

  for(int i=0;i<size;i++)

  {

      cout<<nos[i]<<" ";

      if((i+1)%10==0)

      cout<<endl;

  }

}

double mean(int nos[],int size)

{

  double sum=0;

  for(int i=0;i<size;i++)

  {

      sum+=nos[i];

  }

  return sum/size;

}

double variance(int nos[],int size)

{

  double avg=mean(nos,size);

 

double variance,sum=0;

for(int i=0;i<size;i++)

{

sum+=pow(nos[i]-avg,2);

}

//calculating the standard deviation of nos[] array

variance=(double)sum/(size);

return variance;

}

double median(int nos[],int size)

{

      //This Logic will Sort the Array of elements in Ascending order

  int temp;

  for (int i = 0; i < size; i++)

{

for (int j = i + 1; j < size; j++)

{

if (nos[i] > nos[j])

{

temp = nos[i];

nos[i] = nos[j];

nos[j] = temp;

}

}

}

 

int middle;

float med;

middle = (size / 2.0);

if (size % 2 == 0)

med = ((nos[middle - 1]) + (nos[middle])) / 2.0;

else

med = (nos[middle]);

return med;

}

int mode(int nos[],int size)

{

  int counter1 = 0, counter2, modevalue;

for (int i = 0; i < size; i++) {

counter2 = 0;

for (int j = i; j < size; j++) {

if (nos[i] == nos[j]) {

counter2++;

}

if (counter2 > counter1) {

counter1 = counter2;

modevalue = nos[i];

}

}

}

if (counter1 > 1)

return modevalue;

else

return 0;

}

void histogram(int nos[],int size)

{

  int hist[9]={0};

  for(int i=0;i<size;i++)

  {

      if(nos[i]>=55 && nos[i]<=59)

      {

      hist[0]++;

      }

      else if(nos[i]>=60 && nos[i]<=64)

      {

      hist[1]++;

      }

      else if(nos[i]>=65 && nos[i]<=69)

      {

      hist[2]++;

      }

      else if(nos[i]>=70 && nos[i]<=74)

      {

      hist[3]++;

      }

      else if(nos[i]>=75 && nos[i]<=79)

      {

      hist[4]++;

      }

      else if(nos[i]>=80 && nos[i]<=84)

      {

      hist[5]++;

      }

      else if(nos[i]>=85 && nos[i]<=89)

      {

      hist[6]++;

      }

      else if(nos[i]>=90 && nos[i]<=94)

      {

      hist[7]++;

      }

      else if(nos[i]>=95 && nos[i]<=99)

      {

      hist[8]++;

      }

  }

     

  cout<<"Displaying the count of numbers in each interval:"<<endl;

 

      int cnt=0;

  for(int i=55;i<=99;i+=5)

  {

  cout<<i<<"-"<<i+4<<"|"<<hist[cnt]<<endl;

 

      cnt++;

  }

 

  cout<<"Displaying the histogram :"<<endl;

  cnt=0;

  for(int i=55;i<=99;i+=5)

  {

  cout<<i<<"-"<<i+4<<"|";

  for(int j=0;j<hist[cnt];j++)

  {

      cout<<"*";

  }  

      cout<<endl;

      cnt++;

  }          

     

 

 

}

#########

___________________________

The output can be seen in the attached image below.

You might be interested in
Write a program that (a) generates a vector with 20 random integer elements with integers between -29 and 30, (b) replaces all t
Ghella [55]

Answer:

import random

randomlist = []

for i in range(0,20):

n = random.randint(-29,30)

if n < 0 :

n = 100

randomlist.append(n)

print(randomlist)

Explanation:

The random module is first imported as it takes care of random. Number generation.

An empty list called randomliay is created to hold the generated random integers.

Using a for loop, we specify the range of random numbers we want.

Inside the for loop ; we attach our generated random integer which will be in the range (-29 to 30) in a variable n

For each n value generated, if the value is less than 0( it is negative, since all the values are integers), replace the value with 100.

5 0
2 years ago
There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in in
Dafna1 [17]

Answer:

import java.util.Scanner;

public class InchConversion

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter inches: ");

 double inches = input.nextDouble();

 

 inchesToFeet(inches);

 inchesToYards(inches);

}

public static void inchesToFeet(double inches){

    double feet = inches / 12;

    System.out.println(inches + " inches = " + feet + " feet");

}

public static void inchesToYards(double inches){

    double yards = inches / 36;

    System.out.println(inches + " inches = " + yards + " yards");

}

}

Explanation:

In the inchesToFeet() method that takes one parameter, inches:

Convert the inches to feet using the conversion rate, divide inches by 12

Print the feet

In the inchesToYards() method that takes one parameter, inches:

Convert the inches to yards using the conversion rate, divide inches by 36

Print the yards

In the main:

Ask the user to enter the inches

Call the inchesToFeet() and inchesToYards() methods passing the inches as parameter for each method

7 0
2 years ago
Write a C++ programthat returns the type of a triangle (scalene, equilateral,or
bixtya [17]

Answer:

#include<iostream>

using namespace std;

int main(){

   //initialize

   int a, b,c;

   //print the message

   cout<<"Enter the three sides of the triangle: "<<endl;

   //store in the variables

   cin>>a>>b>>c;

   //if-else statement for checking the conditions  

   if(a == b && b == c && a == c){

       cout<<"\nThe triangle is equilateral";

   }else if(a != b && b != c && a != c ){

       cout<<"\nThe triangle is scalene";

   }else{

       cout<<"\nThe triangle is isosceles";

   }

   return 0;

}

Explanation:

Create the main function and declare the three variables for the length of the sides of the triangle.

print the message on the screen for the user. Then the user enters the values and its store in the variables a, b, and c.

use the if-else statement for checking the conditions.

Equilateral triangle: all sides of the triangle are equal.

if condition true, print the equilateral triangle.

Scalene triangle: all sides of the triangle are not equal.

if condition true, print the Scalene triangle.

if both conditions is not true, then, the program moves to else part and print isosceles.

8 0
3 years ago
Question 1<br> a node is.<br> •a sever<br> A Cell Phone<br> A Laptop<br> a device on a network
RSB [31]

Answer:

From Networkopoint of view, a node is a redistribution point or communication point or a connection point.

It can also mean devices or data points on a large network Such as laptop, phones, printers, etc

Explanation:

3 0
3 years ago
To rename a worksheet, you change the text on the ? HELP ASAP
prohojiy [21]
If this is Excel, it would be C. Sheet tab
5 0
2 years ago
Other questions:
  • Explain Cascading Style Sheets and what they do. Describe their primary function, two effects that this function has on programm
    11·1 answer
  • Consider a movie database in which data is recorded about the movie industry. the data requirements are summarized as follows:
    15·1 answer
  • This question is for one of my classes I am in right now, and the question is:
    8·1 answer
  • One key to success in a career is to be an accomplished
    15·1 answer
  • You would like to put the data in order by product number. What should you do?
    15·1 answer
  • Write a program to simulate a Fruit Machine that displays three symbols at random from Cherry, Bell, Lemon, Orange, Star, Skull.
    11·1 answer
  • How do you use switch board in the office​
    6·1 answer
  • List and describe each of the activities of technology
    11·1 answer
  • Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the
    6·1 answer
  • Are programs that understand physics and/or hardware embedded? for example, one that uses finite-element methods to predict flui
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!