Write a function that will take a vector of int values

Assignment Help Computer Engineering
Reference no: EM132096033

Please help with this gomework question.

Consider the problem of finding the pairs of integers in an input list that sum to 0. Assume that the integers are distinct. This problem is easily solved in quadratic time by doing a brute-force implementation with two (nested) loops that examines all possible pairs.

Write a function that will take a vector of int values as argument and it will return the pairs of values in that vector that sum to 0. Write a brute-forced implementation as described above.

The main program has been written for you, you just have to write the code for the findPairs function.

#include <vector>

#include <iostream>

#include <sstream>

#include <chrono>

using namespace std;

vector <string> findPairs(vector<int> numbers){

}

int main(){

//create test vector to pass to the function

vector <int> testNumbers;

testNumbers.push_back(1);

testNumbers.push_back(54);

testNumbers.push_back(2);

testNumbers.push_back(-3);

testNumbers.push_back(-2);

testNumbers.push_back(58);

testNumbers.push_back(-54);

testNumbers.push_back(58);

testNumbers.push_back(68);

testNumbers.push_back(78);

testNumbers.push_back(-75);

testNumbers.push_back(-1);

//call the function

vector <string> pairs = findPairs(testNumbers);

//display results

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

cout<<pairs[i]<<endl;

}

Reference no: EM132096033

Questions Cloud

Linear relation among air temperature : How do I determine if there is a linear relation among air temperature x1?, wind speed x2?, and wind chill y from the data shown below
Determine the? p-value of hypothesis test : The data below represents the population of a certain country every 10 years for the years? 1900-2000. How do I determine the? least-squares regression?
Develop a web-based pothole tracking and repair system : Why is it that many software developers don't pay enough attention to requirements engineering? Are there ever circumstances where you can skip it?
Develop a method with java program : Develop a method with java program. Write a main method to test your method.
Write a function that will take a vector of int values : Write a function that will take a vector of int values as argument and it will return the pairs of values in that vector that sum to 0.
Interval about slope of true? least-squares regression : How would I construct a? 95% confidence interval about the slope of the true? least-squares regression line shoeing the Lower and Upper Bound?
Evidence of a problem in the area : Was it evidence of a problem in the area, or was it a chance? Can you verify this? Would Binomial or Poisson distribution be suitable for modeling this case?
Identify the rows who destination network has any chance : Identify the rows who destination network has any chance of matching the IP address (compare the first three octets)
Can you explain confidence interval to me : Can you explain confidence interval to me? For example: when someone is asking what is the 95% CI for age range in a sample.

Reviews

Write a Review

Computer Engineering Questions & Answers

  What are the three types of manufacturing process data

What are the three types of manufacturing process data? Explain. What is multiplexer? Explain different types of multiplexes.

  Create a class named cellphone which will represent the code

Create a class named CellPhone which will represent the code to manage cell phone's operating system. Split your declaration and definition into a header file.

  How to measure performance in the unreal engine

Write a short report explaining how to measure performance in the Unreal Engine. After this, record and report the performance difference between 100 dynamic lights as opposed to 100 baked lights.

  Select a security framework explain the framework selected

write a three to five 3-5 page paper in which youselect a security framework describe the framework selected and design

  Write program that simulates the operation of a busy airport

Write a program that simulates the operation of a busy airport that has only two runways to handle all takeoffs and landings.

  Write a class called laptop that contains instance data

Write a class called Laptop that contains instance data for the laptop model, make, purchaser, and purchase year. Define the Laptop constructor to accept.

  What steps can small company take to mitigate potential loss

Small companies are perhaps more vulnerable to the loss of key employees and the resulting loss of organizational knowledge.

  Compute the millionth fibonacci number in under a minute

Based on you answer to 7 rewrite NewFib using loops instead of recursion. Your implementation should be able to compute the millionth Fibonacci number in under a minute. Printing it out in Spyder is not a good idea. It is not necessary to actually..

  Describe the top-down design process

Describe the top-down design process. Differentiate between a concrete step and an abstract step. Write a top-down design for the following tasks.

  Write about the information security

Essay topic assignment: NIST SP 800-100: Information Security Handbook: A Guide for Managers. Student written reports are in Microsoft Word.

  Design the logic for a program that output every even number

Design the logic for a program that outputs every even number from 2 through 30.

  Write down a windows application which randomly generates a

write a windows application that randomly generates a number from 0 through 100. prompt the user to guess the number.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd