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
Paladinen [302]
3 years ago
10

Write a C function that takes an STL vector of int values and determines if all the numbers are different from each other (that

is, they are distinct).

Computers and Technology
1 answer:
eduard3 years ago
7 0

Answer:

Here is the function:

#include <iostream>  //to use input output functions

#include <vector>  // to use vector (sequence containers)

#include <algorithm>   //use for sequence operations

#include<iterator>  //to move through the elements of sequence or vector

using namespace std;  //to identify objects cin cout

 void DistinctNumbers(std::vector<int> values) { /*function that takes  an STL vector of int values and determines if all the numbers are different from each other */

     sort(values.begin(), values.end());  //sorts the vector elements from start to end

     bool isDistinct = std::adjacent_find(values.begin(), values.end()) == values.end();  //checks for occurrence of two consecutive elements in vector

if(isDistinct==true)  // if all numbers are different from each other

{cout<<"Numbers are distinct";}

else  //if numbers are duplicate or same

{cout<<"Numbers are not distinct";}   }  

int main(){      //start of main function

std::vector<int> v = {1,2,3,4,5};  // vector of int values

DistinctNumbers(v); }  //function call to passing the vector v to check if its elements are distinct

Explanation:

The program that takes an STL vector of int values and the function DistinctNumbers determines if all the numbers are different from each other. It first sorts the contents of the vector in ascending order using sort() method. Then it used the method adjacent_find() to searches the range means from the start to the end of the vector elements, for first occurrence of two consecutive elements that match, and returns an iterator to the first of these two elements, or last if no such pair is found. The result is assigned to a bool type variable isDistinct. It then checks if all the numbers are different and no two adjacent numbers are same. If all the numbers are distinct then this bool variable evaluates to true otherwise false. If the value of isDistinct is true then the message :Numbers are distinct is displayed on screen otherwise message: Numbers are not distinct is displayed in output screen.

You might be interested in
Como interactua el hardware de la computadora con el ser humano
soldi70 [24.7K]

Answer:

Los humanos interactúan con las computadoras a través de una interfaz de usuario

7 0
2 years ago
Anyone play Ps4 and wanna run up some warzone or Gta? Im M 16 so dont be a creep... :) ill mark brainliest if you drop gamertag
Nikitich [7]

Answer:

Xbox/ PC game here

Explanation:

4 0
3 years ago
Read 2 more answers
What computer is designed for particular application​
Karo-lina-s [1.5K]

Answer: Applications for desktop or laptop computers are sometimes called desktop applications, while those for mobile devices are called mobile apps. When you open an application, it runs inside the operating system until you close it

Explanation:

5 0
2 years ago
What is the correct keyboard shortcut to cut a cell value
vladimir2022 [97]

Answer:

Cntrl+X

Explanation:

Do it on your computer

4 0
2 years ago
Which of the following is part of Connections Academy's AUP regarding the use of the school'supplied technology
sergey [27]
A)technology supplied by connections should only be used for school purposes
6 0
3 years ago
Read 2 more answers
Other questions:
  • What kind of testing is basically checking whether a game or feature works as expected by the developers?
    10·1 answer
  • Write a function called calculate() that accepts three integer Numbers as arguments, compute these values : Sum and Product and
    7·1 answer
  • What control features will you use in the input screens to aid in data entry? give a specific example of how you will use at lea
    6·1 answer
  • Tweaking existing technology in a new way is usually called _____. leveraged creativity state-of-the-art breakthrough applicatio
    5·1 answer
  • An Organization Chart to support the Appliance Warehouse case study The SWOT Analysis diagram you performed and created to suppo
    13·1 answer
  • Write the contrapositive of each of the following statements. Healthy plant growth follows from sufficient water. Increased avai
    7·1 answer
  • A style sheet consists of CSS ______________________ that specify the layout and format properties to apply to an element. *
    13·1 answer
  • The physical layer of the OSI model is not foundational to any of the other layers. True or False
    8·1 answer
  • How do you get lugia in pokemon alpha saphire
    6·1 answer
  • Your friend decides to create a spreadsheet containing vocabulary terms and their definitions to help prepare for the unit test
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!