USING C++:
Write a function that will return the number of elements that appear in pairs in a vector (i.e., the number of elements that appear exactly twice).
E.g. if the vector v={1,3,7,10,1,1,3,5,10,5}, the function will return 3 (since 3, 5 and 10 appear in pairs)
The function prototype is given below:
template <class T> int pairCount(const vector<T>&);
#include <iostream>
#include <vector>
using namespace std;
template<class T>
int pairCount(const vector<T> &);
int main() {
vector<int> v = {1, 3, 7, 10, 1, 1, 3, 5, 10, 5};
cout << pairCount(v) << endl;
return 0;
}
template<class T>
int pairCount(const vector<T> &v) {
int count = 0;
for (int i = 0; i < v.size(); ++i) {
int c = 0;
for (int j = 0; j < v.size(); ++j) {
if (v[i] == v[j])
++c;
}
if (c == 2) {
++count;
}
}
return count / 2;
}

USING C++: Write a function that will return the number of elements that appear in pairs...
USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...
c++ microsoft visual studio Write a function that given a string it will return the number of vowels in the string. Function prototype is given by: int getNumVowels(string s1);
Write a int function that accepts as parameter the name of a candidate and return the number of votes received by the candidate. So, if the user enters Duck, the output will be 6000. Of course, if the given name does not exist, display an appropriate message. Need help with the above here is what i have so far: #include <iostream> #include <iomanip> #include <string> #include <vector> #include <map> using namespace std; // Get the details from the user for...
USING C++: Write a function that will print out all the factors of a given positive integer N. The factors of N are all the numbers that N is divisible by (i.e., x is a factor of N if N/x has remainder 0). The function prototype is provided below. E.g. factors(12) will print out 1, 2, 3, 4, 6, 12. void factors(int);
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <=...
this program is in C.
Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...
Write a main function that declares the names, marks, number of elements as well as the value to be searched for and the index of the returned function calls. Read and display the contents of names and marks. Ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student. Sort the arrays...
(c++) Write a predicate function that checks whether two vectors have the same elements in the same order. Write a predicate function that checks whether two vectors have the same elements in the same order bool equals(vector<int> a, vector<int> b) provided code : #include <iostream> #include <vector> using namespace std; bool equals(vector<int> a, vector<int> b) { // TODO } int main() { // TODO // Print Expected, "Vectors a and b are " (print "equal." if they are. Otherwise, print...
How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){ if (indexStatusList[i] == 1){ cout <<HTable[i]<< " " << endl; } } } **********Rest of the code...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...