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
A company that hires only American Indians is practicing
Mashutka [201]
What’s the question ?
7 0
2 years ago
Read 2 more answers
host b is sending an email intented for the user on host a to the mail server what protocol is being used to send the message
KatRina [158]

Answer:

SMTP

Explanation:

This is the SMTP or the Simple Mail Transfer Protocol. It is the push protocol and is used to send the mail message. Whereas POP3 and IMAP are meant for retrieving the message. These are the three main types of protocols associated with mail services. And the correct answer here is certainly the SMTP.

3 0
3 years ago
What is the LER for a rectangular wing with a span of 0.225m and a chord of 0.045m
ch4aika [34]

Calculate LER for a rectangular wing with a span of 0.225m and a chord of 0.045m. The weight of the glider is 0.0500 Newtons. (Note: the wing span is the width of the wing and is measured from wing tip to wing tip, or perpendicular to the fuselage. The wing chord is the length of the wing measured parallel or along the length of the fuselage.)

Answer:

Area of rectangular wing = span × chord = 0.225×0.045= 0.010125m2

LER = Area/weight = 0.010125/0.0500 = 0.2025

4 0
2 years ago
You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly
sweet-ann [11.9K]

Answer:

Code is too large , i attached a source file below and also a text file from where i get Questions

Explanation:

6 0
3 years ago
Ava calls tech support because she is unable to send information that a customer has requested. The tech support person tells he
Blizzard [7]

Answer:

Outlook as it is a common email aplication which may experience some issues

Explanation:

7 0
3 years ago
Other questions:
  • Which keyboard feature is a form feed character?
    14·1 answer
  • True or false: when considering data backups, it is most important to verify that the integrity of the backup file or data is va
    9·1 answer
  • If you delete an imessage does the other person see it
    12·1 answer
  • Types of operating systems
    5·2 answers
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    9·1 answer
  • What should be entered to make the loop print
    6·1 answer
  • When adjusting the aperture, an F-stop of F32 lets in more light then a setting of F8
    10·1 answer
  • The purpose of Appetizers on the menu​
    6·2 answers
  • Write A Code In Python
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!