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
Stella [2.4K]
3 years ago
14

C++

Computers and Technology
1 answer:
vichka [17]3 years ago
4 0

Answer:

#include <iostream>

#include <map>  

using namespace std;

int main()

{

   map<int, int> numbers;

   cout << "Enter numbers, 0 to finish" << endl;

   int number;

   while (true) {

       cin >> number;

       if (number == 0) break;

       numbers[number]++;

   }

   for (pair<int, int> element : numbers) {

       std::cout << element.first << ": occurs " << element.second << " times" << std::endl;

   }

}

Explanation:

One trick used here is not to keep track of the numbers themselves (since that is not a requirement), but start counting their occurrances right away. An STL map< > is a more suitable construct than a vector< >.

You might be interested in
Write a program to implement problem statement below; provide the menu for input N and number of experiment M to calculate avera
zalisa [80]

Answer:

Explanation:

#include<iostream>

#include<ctime>

#include<bits/stdc++.h>

using namespace std;

double calculate(double arr[], int l)

{

double avg=0.0;

int x;

for(x=0;x<l;x++)

{

avg+=arr[x];

}

avg/=l;

return avg;

}

int biggest(int arr[], int n)

{

int x,idx,big=-1;

for(x=0;x<n;x++)

{

if(arr[x]>big)

{

big=arr[x];

idx=x;

}

}

return idx;

}

int main()

{

vector<pair<int,double> >result;

cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

int choice;

cin>>choice;

while(choice!=2)

{

int n,m;

cout<<"Enter N"<<endl;

cin>>n;

cout<<"Enter M"<<endl;

cin>>m;

int c=m;

double running_time[c];

while(c>0)

{

int arr[n];

int x;

for(x=0;x<n;x++)

{

arr[x] = rand();

}

clock_t start = clock();

int pos = biggest(arr,n);

clock_t t_end = clock();

c--;

running_time[c] = 1000.0*(t_end-start)/CLOCKS_PER_SEC;

}

double avg_running_time = calculate(running_time,m);

result.push_back(make_pair(n,avg_running_time));

cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

cin>>choice;

}

for(int x=0;x<result.size();x++)

{

cout<<result[x].first<<" "<<result[x].second<<endl;

}

}

8 0
2 years ago
Consider an airport security system. Determine the system model considering that there are two classes of customers – regular an
kykrilka [37]

The answer & explanation for this question is given in the attachment below.

4 0
2 years ago
The number of arguments does not need to match the number in the parameter list when you use ____. 19. When can a method be call
photoshop1234 [79]
<h2>Only when the default parameter are defined in the function</h2>

Explanation:

Answer is same for both the question.

  • A default argument or default parameter is assigned an automatic value when the function is invoked.
  • So the default value will be assigned during the function definition itself.
  • You can find the assignment operator which is being used in the function definition.
  • You can overwrite the default values by passing your own value in the calling portion
  • The constraint here is that, the default parameter should always be the last parameter of function definition to avoid ambiguity.

3 0
3 years ago
Which invention made mobile phones and tablet devices possible? 1 Decoder 2 Integrated circuitry 3 Microchip 4 Motherboard (I th
Korolek [52]

Answer:

The correct option is;

Integrated circuit

Explanation:

Following the invention of the transistor, the electrical wiring within an electronic device became known as the major factor contributing to the size of these devices and so in 1958 Jack Kilby and Noyce Fairchild independently developed the Integrated Circuit (IC) model which allowed the integration of the entire circuit onto a piece of solid material, making them smaller, faster, cheaper, more reliable to mass produce, made it possible for the development of smaller computers such as laptops and versions of similar technology, such as mobile phones and tablets due to the ease of standardization of ICs, leading to easier links from design to actual product of small communication devices that rely on ICs.

3 0
3 years ago
29. Write a program that asks to input any ten numbers and displays sum of them​
pogonyaev

Answer:

Here is the code for a classic C++ program that does it:

--------------------------------------------------------------------------------

#include <iostream>

using namespace std;

int main()

{

   int sum = 0;

   int n;

   cout << "Input 10 numbers: " << endl;

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

   {

       cin >> n;

       sum += n;

   }

   cout << "Sum of the numbers: " << sum << endl;

}

--------------------------------------------------------------------------------

Explanation:

I'm assuming you know what "include", "using namespace std" and "int main()" do, so I will skip over those.

First, we declare a variable "sum" and initialize it with 0 so we can add numbers to it later.

Then, we declare a variable "n" that will be set as the input of the user.

The "for-loop" will iterate ( go ) from 0 to 9, and will set the value of "n" as the input that is given -> "cin >> n;". After that, we add the value of "n" to the sum variable.

After "i" reaches 9, it will exit the loop and proceed to printing the sum of the numbers.

Hope it helped!

5 0
3 years ago
Other questions:
  • The method header of the equals() method within the string class is ____.
    13·1 answer
  • 1.Which type of camera tool pushes the picture back and makes it wider, exaggerating the distance between the background and for
    13·2 answers
  • T F The exit function can only be called from main .
    10·1 answer
  • Bob works at a cafe where he earns $11 an hr. which of the following graphs describes the amount of money that bob earns after x
    9·2 answers
  • A group of developers for a startup company store their source code and binary files on a shared open-source repository platform
    14·1 answer
  • The L-exclusion problem is a variant of the starvation-free mutual exclusion problem. We make two changes: as many as L threads
    15·1 answer
  • Difference between customized and packaged software​
    10·1 answer
  • Prior to the 1996 NEC, ____ receptacles and cords were permitted. However, now it is mandatory that a separate equipment groundi
    11·1 answer
  • 15. You read a news article that's politically biased and not well organized. It's
    6·1 answer
  • ZipCar uses cutting edge wireless technology combined with sophisticated data management and security techniques to assure that
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!