C++
Write a function named "FriendsWithPets" that takes a const reference to a std::map of my friends names (std::string) to the number of pets they own (int) and returns the number of friends (int) that have at least one pet.
You should be using the STL algorithms to achieve this, credit is only given if your solution doesn't have any looping constructs (no "while" or "for" keywords anywhere in the solution).
The function is as follows:
// definition of the function.
void FriendsWithPets(map<string,int>data){
// Declare the class type variable.
Test< string, int > val(0);
// Calculate the count.
size_t count = count_if( data.begin(), data.end(), val );
//display the result on console.
cout<<data.size() - count <<endl;
}
The complete program is as follows:
Program screenshots:


Sample Output:

Code to Copy:
// Include the necessary header files.
#include <bits/stdc++.h>
using namespace std;
// Declare template.
template< class E1, class E2 >
// Declare class.
class Test
{
// Declare public members.
public:
Test( const E2& val ) : Tval( val ) {};
bool operator()( const typename std::pair< const E1, E2 >& temp )
{
return (temp.second == Tval);
}
// Declare private members.
private:
const E2 Tval;
};
// definition of the function.
void FriendsWithPets(map<string,int>data){
// Declare the class type variable.
Test< string, int > val(0);
// Calculate the count.
size_t count = count_if( data.begin(), data.end(), val );
//display the result on console.
cout<<data.size() - count <<endl;
}
// Start the main function.
int main(){
// Declare a map
map<string,int>data;
// Add values to the map
data["1"]=0;
data["2"]=1;
data["3"]=1;
data["4"]=3;
data["5"]=5;
data["6"]=0;
data["7"]=2;
data["8"]=0;
// Call the function.
FriendsWithPets(data);
}
C++ Write a function named "FriendsWithPets" that takes a const reference to a std::map of my...
#C++ Write a function, named sortByCourseNumber, that takes a reference to a vector of string (like {"CSE 232", "ECE 100", "CSE 450", "CSE 232"}) and returns nothing. The function should reorder the vector so that the courses are sorted by number in ascending order. You can assume that the department code is separated from the number by a space and that all course numbers are 3 characters long. You should be using the STL algorithms to achieve this, full credit...
a. Write a function arrayToMap that takes an array of strings and returns a std::map<int, string> such that the values in the map are the string values in the array of strings, and the keys in the map are the corresponding array indices of the string values. You may assume all necessary libraries have been included in your program and your solution must be syntactically correct in order to receive full credit. map<int, string> arrayToMap(string arr[], int arrSize) { b....
help ASAP
3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...
Create a C project named login_l06t1. Write and test a function strnclean that takes two strings as parameters, target and source. Using the ctype library, copy only the alphabetic characters from source to target, and make the characters lower case. Ex: source: David Brown! target: davidbrown Prototype: void strnclean(char *target, const char *source); How do i do this using the C type library below! int isalnum(int c) Returns non-zero (true) if c is an alphanumeric character, zero otherwise. int isalpha(int...
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...
USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...
Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example, Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31. The constructor for the class should take as parameter an integer representing the day of the year, and the class should have...
C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...
Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest to make main.cpp compile. Put the declaration and definition of find youngest in StudentClub.h and StudentClub.cpp separately. You may not modify provided files and only submit StudentClub.h and StudentClub.cpp. Non-member function find youngest is declared as follows. It returns the names of students who have the youngest age. Note there may exist more than one students who are youngest. std::vector find_youngest(const std::vector member); StudentClub...
Help with programming in C++
Phase 1 is complete, please help with phase 2. Thank you.
Phase 1
You must design 3 algorithms, and provide
both a flow chart and pseudo code for the
algorithms.
Algorithm descriptions:
Given an integer parameter named current_number
and two constant global variables:
const int MIN_NUMBER = 1;
const int MAX_NUMBER = 8;
Create an algorithm named forward, that will
advance ONE value through a sequence of numbers 1,
2, 3 ... MAX_NUMBER. In...