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
What was the history of technology since the 1980s to now and how is it used in classrooms?.?. PLEASE HELP
levacccp [35]

Answer:

Please check the explanation.

Explanation:

The US education department mentioned that in 1900 there were only 10% of students enrolled in the schools, however by the end of 1992, the percentage increased by 85% and it became 95%. In 1930 1 million students were enrolled in university. And by 2012, it became 21.6 million. The teachers began to follow a new type of teaching, and the academics began to follow a special method for communique, education as well as for helping the students understand the concepts.

Though, after the 1980s the personal computer came into being in schools and colleges. Since then numerous versions of PC have originated in the marketplace as well as mobiles tracked by Smartphones, and now nearly 100% of people in the US have smartphones. Virtual reality, augmented reality, AI, Machine learning. etc. has cemented the way for the virtual classrooms. Also, each subject is now up with fruits and not just-food. The consequence is such a delightful setup of the Virtual schoolrooms in the entire US, and all over the ecosphere. The projectors, VR devices, AI applications for education, online classroom facility, Electronic version of chalkboards, and in fact everything is no sophisticated, and it is making not only teaching easy but learning as well. And the result is, students are ending up with better results, and teachers seem to be happier and more relaxed. And that is making school management satisfied as well.

3 0
3 years ago
Which statement best describes multimedia
d1i1m1o1n [39]

Answer:

I couldn't find options to this question online but I will give you an explanation so you can choose the correct answer.

Explanation:

The term multimedia refers to something that uses multiple media simultaneously when transmitting information.

Examples of this can be:

  • photographs
  • sounds
  • text
  • video

Multimedia frames the objects and systems that use multiple physical or digital media to transmit content. It also refers to the media that store and disseminate these types of content.

6 0
3 years ago
Suppose you have a string matching algorithm that can take in (linear)strings S and T and determine if S is a substring (contigu
Zielflug [23.3K]

Answer:

no seishsssssssssssssssssssss

8 0
3 years ago
Read 2 more answers
A malware-infected networked host under the remote control of a hacker is commonly referred to as:
natali 33 [55]

Answer:

Option a: Trojan

Explanation:

A Trojan or Trojan horse is one of the computer malware that exist in computing world. Trojan often appears as a legitimate software to deceive user to activate it by social engineering. Once the Trojan is activated in the user computer, a hacker can remote control the infected computer for malicious purposes such as removing files, sending files, displaying message or rebooting computer.

However, Trojan cannot be replicated in the infected computer.

7 0
3 years ago
Read 2 more answers
Develop a simple game that teaches kindergartners how to add single-digit numbers. Your function game() will take an integer n a
Lyrx [107]

Answer:

2 correct answer out of 3

5 0
3 years ago
Other questions:
  • 5. In Access, data is stored in a _______ once a form is completed. A. cell B. page C. record D. form
    13·1 answer
  • You are using Windows 10 and you have created a file with called “my text” in notepad with a .txt extension type. You need to ch
    13·1 answer
  • HTTP is made to facilitate which kind of communication?
    11·1 answer
  • Effective note-taking helps support<br><br> action.<br> distinction.<br> distraction.<br> retention.
    9·2 answers
  • Which does plug-and-play refer to?
    13·2 answers
  • How is a recession determined?
    10·1 answer
  • What is bug in computer?​
    12·1 answer
  • How many discussion posts must you complete to meet the Expectations of the replies category
    11·1 answer
  • It specifies the amount of memory needed to store data.
    7·2 answers
  • I am in class 7 should I go with java or python.​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!