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
Which element is included in the shot breakdown storyboard? Which element is included in the shot breakdown storyboard?
VladimirAG [237]

Answer: jump out

Explanation:

Took the test and it was correct

5 0
3 years ago
Convert<br> 0.625 to binary
Anastaziya [24]

\huge{ \rm{Question:}}

Convert

0.625 to binary

\huge{ \rm{Answer:}}

Translate 0.625 into a fraction. We all know that 0.5 is ½. We know that the remainder, 0.125, is ⅛. Add them together, and you get ½ + ⅛ = ⅝.

Now, in binary, the positions to the right of the point are , which is ½, ¼, and ⅛ respectively.

⅝ is 5 × ⅛. 5 in binary is 101. So, ⅝ is

= 0.101

8 0
2 years ago
Simple mail transfer protocol (smtp) uses the well-known port number ______________ by default.
Elden [556K]
I believe it's default is port 587. 
8 0
4 years ago
Read 2 more answers
Using the C language, write a function that accepts two parameters: a string of characters and a single character. The function
Sav [38]

Answer:

#include <stdio.h>

void interchangeCase(char phrase[],char c){

  for(int i=0;phrase[i]!='\0';i++){

      if(phrase[i]==c){

          if(phrase[i]>='A' && phrase[i]<='Z')

              phrase[i]+=32;

          else

              phrase[i]-=32;      

      }

  }

}

int main(){

  char c1[]="Eevee";

  interchangeCase(c1,'e');

  printf("%s\n",c1);

  char c2[]="Eevee";

  interchangeCase(c2,'E');

  printf("%s\n",c2);    

}

Explanation:

  • Create a function called interchangeCase that takes the phrase and c as parameters.
  • Run a for loop that runs until the end of phrase and check whether the selected character is found or not using an if statement.
  • If the character is upper-case alphabet, change it to lower-case alphabet and otherwise do the vice versa.
  • Inside the main function, test the program and display the results.
8 0
3 years ago
Which of the following is a safe work practice to protect you from electrocution hazards?
Flura [38]
What are the answer choices?
7 0
4 years ago
Other questions:
  • In python,_______ are used to define the conditions necessary for a while loop to run.
    7·2 answers
  • What is the difference between a design pattern and a DLL?
    12·1 answer
  • Boardman College maintains two files—one for Sociology majors and another for Anthropology majors. Each file contains students'
    5·1 answer
  • 1. In your own words, describe the purpose of a for a loop.
    11·1 answer
  • Which of the following is an accurate definition of a computer system? A computer system consists of the operating system that t
    6·1 answer
  • A company is acquiring a smaller firm and is setting up a new IT system in order to consolidate the data and assets of the acqui
    11·1 answer
  • What is the different sheets in excel
    15·1 answer
  • A health care provider approaches Accenture to help them increase their efficiency through an advanced data science platform.Wha
    8·1 answer
  • ANs and WANs can be set up in several different shapes, also known as peripherals.
    6·1 answer
  • What is the optimal number of members for an Agile team?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!