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
aliina [53]
3 years ago
8

Write a program that creates a list (STL list) of 100 random int values. Use the iterators to display all the values of the list

in order and in reverse order. Use the sort function to sort the list of values and output the list. g
Computers and Technology
1 answer:
sertanlavr [38]3 years ago
4 0

Answer:

The program is as follows:

#include <bits/stdc++.h>

#include <iostream>

using namespace std;

int main(){

  list <int> myList;

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

      myList.push_back(rand()%100);       }

   list <int> :: iterator it;

   cout<<"Forward: ";

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

   

   cout<<"\nReversed: ";

   std::copy(myList.rbegin(),myList.rend(),std::ostream_iterator<int>(std::cout, " "));

        myList.sort();  

   cout<<"\nSorted: ";

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

   return 0;

}

Explanation:

This declares the list

  list <int> myList;

The following iteration generates 100 random integers into the list

<em>   for(int i=0;i<100;i++){  </em>

<em>       myList.push_back(rand()%100);       } </em>

This initializes an iterator

   list <int> :: iterator it;

This prints the header "Forward"

   cout<<"Forward: ";

This iterates through the list and prints it in order

<em>    for(it = myList.begin(); it != myList.end(); ++it){ </em>

<em>        cout <<*it<<" ";    } </em>

    This prints the header "Reversed"

   cout<<"\nReversed: ";

This uses ostream_iterator to print the reversed list

   std::copy(myList.rbegin(),myList.rend(),std::ostream_iterator<int>(std::cout, " "));

This sorts the list in ascending order

        myList.sort();

This prints the header "Reversed"  

   cout<<"\nSorted: ";

This iterates through the sorted list and prints it in order

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

You might be interested in
Word frequencies - functions
Nuetrik [128]

Answer:

#include <iostream>

#include <vector>

#include <iomanip>

#include <string.h>

#include <string>

#include <algorithm>

using namespace std;

bool strEqual(const string& str1, const string& str2)

{

 //check each characters by case insensitive  

 return std::equal(str1.begin(), str1.end(),

                     str2.begin(), str2.end(),

                     [](char str1, char str2) {

                         return tolower(str1) == tolower(str2);

                     });

}

unsigned GetWordFrequency(vector<string>& vec,const string& str)

{

 //return the number of occurrences of the search word in the

 unsigned res=0;//the numbers of occurences

 for(auto itr:vec)

   {

     if(strEqual(itr,str))

       res++;

   }

 return res;

}

int main()

{

 int size=0;

 cin>>size;

 vector<string>vec;

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

   {

     string str;

     cin>>str;

     vec.push_back(str);

   }

   cout<<"Output:"<<endl;

 for(auto itr: vec)

   {

     cout<<itr<<" - "<<GetWordFrequency(vec,itr)<<endl;

   }

 return 0;

}

Explanation:

5 0
2 years ago
An analogue sensor has a bandwidth which extends from very low frequencies up to a maximum of 14.5 kHz. Using the Sampling Theor
shepuryov [24]

Answer:

3.2*10^5

Explanation:

By Nyquist's theorem we must have 2*14.5kHz=29kHz so 29,000 samples per second. 2048=2^11 so we have 11 bits per sample. Finally we have 29000*11 bits per second (bps) =319000=3.2 * 10^5

3 0
3 years ago
Read 2 more answers
When an object is acted on by unbalanced forces, the object will always
alexandr402 [8]

Answer:

If an object has a net force acting on it, it will accelerate. The object will speed up, slow down or change direction. An unbalanced force (net force) acting on an object changes its speed and/or direction of motion. An unbalanced force is an unopposed force that causes a change in motion.

Explanation:

6 0
3 years ago
What is a Boolean operator?
ASHA 777 [7]

Answer:

The correct answer is search parameters set to identify specific information during Internet searches.

Explanation:

A Boolean operator is used to connect words or symbols that allows setting search parameters to include or exclude items in a text search.  

The booleans operators are:

  • AND.
  • OR.
  • NOT.
8 0
4 years ago
Write a program to read 2 numbers and display the largest of the two. You should use scanfto read the two numbers and use if sta
Harman [31]

Answer: in C

#include <stdio.h>

int main(){

  int num1, num2;

  printf("Enter first number :: ");

  scanf("%d", &num1);

  printf("Enter second number :: ");

  scanf("%d", &num2);

 

  if(num1 > num2){

     printf("%d is larger than %d\n", num1, num2);

  } else if (num2 > num1) {

     printf("%d is larger than %d\n", num2, num1);

  } else{

     printf("Both of them are equal\n");

  }

  return 0;

}

8 0
4 years ago
Other questions:
  • A device that modulates digital data onto an analog signal and then demodulates the analog signal back to digital data is a ____
    8·1 answer
  • What is the difference between a denial-of-service attack and a distributed denial-of-service attacks? which is potentially more
    10·1 answer
  • 6. Write a program that can multiply an n x m matrix and m x n matrix together: The input specifications are these: Read n and m
    11·1 answer
  • Which option is used to apply formatting to multiple objects on a single slide while still maintaining the ability to manage the
    14·2 answers
  • What things have small motors
    13·1 answer
  • First identify the formula to compute the sales in units at various levels of operating income using the contribution margin app
    12·1 answer
  • What strategies do you use to better understand difficult reading material? Check all that apply.
    5·1 answer
  • Write a modular program that accepts up to 20 integer test scores in the range of 0 to 100 from the user and stores them in an a
    9·1 answer
  • In python, sorry if it’s blurry
    13·2 answers
  • Write a for loop that displays the following numbers exactly like this (you must use a loop):
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!