C++
[10pts]
Write a function that takes as a parameter an integer (as a
long
value) and returns the
number of odd, even, and zero digits. Also write a program to test your function.
#include <iostream>
using namespace std;
void getResult(long value, int& odds, int& evens,
int& zeros){
if(value==0){
zeros = 0;
}
else{
while(value>0){
if(value%10==0){
zeros++;
}
else if((value%10)%2==0){
evens++;
}
else{
odds++;
}
value=value/10;
}
}
}
int main()
{
long value;
int evens = 0, odds = 0, zeros = 0;
cout<<"Enter long value: ";
cin>>value;
getResult(value, odds, evens, zeros);
cout<<"Number of evens: "<<evens<<endl;
cout<<"Number of odds: "<<odds<<endl;
cout<<"Number of zeros: "<<zeros<<endl;
return 0;
}
C++ [10pts] Write a function that takes as a parameter an integer (as a long value)...
In C++, write a function isOdd() that takes one integer parameter. The function returns true if the number if odd and false otherwise.
C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...
Write a function that takes an integer input n as a parameter and after it calculates the sum of 1+2+3+...+n, it returns the value to the main program. For example, if n=4, the output of the sum will be 10.
Write a function PoundsToKilograms that: Takes a number of pounds (an integer) as a parameter, Calculates and returns the corresponding value in kilograms. 1 kilogram is equal to 2.2 pounds. In the main section of the program: Prompt the user to input a weight in pounds, Call the function you wrote to transform the weight into kilograms, Output the weight in kilograms; the number must be shown with 2 decimals after the decimal point. Your program must define and call...
Task 4: a) Write a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. b) Include the function written in part a in a working program. Make sure your function...
Write a C++ function that takes a pointer to an array of integers as a parameter and return the number of prime integers in the array. Write main() program to test the function.
Write a recursive function named arithmeticSum that takes a positive integer parameter n and returns the sum of the integer numbers from 1 to n Please write in C++
(C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...
Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...
1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following functions: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the...