Write a program that reads a list of integers, and outputs whether the list contains all multiples of 10, no multiples of 10, or mixed values. Define a function named IsVectorMult10 that takes a vector as a parameter, representing the list, and returns a boolean that represents whether the list contains all multiples of ten. Define a function named IsVectorNoMult10 that takes a vector as a parameter, representing the list, and returns a boolean that represents whether the list contains no multiples of ten.
Then, write a main program that takes an integer, representing the size of the list, followed by the list values. The first integer is not in the list.
The program must define and call the following two functions. IsVectorMult10 returns true if all integers in the vector are multiples of 10 and false otherwise. IsVectorNoMult10 returns true if no integers in the vector are multiples of 10 and false otherwise.
bool IsVectorMult10(vector<int> myVec)
bool IsVectorNoMult10(vector<int> myVec)
#include<iostream>
#include <vector>
bool IsVectorMult10(std::vector<int> myVec)
{
bool isMultiple = true;
for (size_t i = 1; i < myVec.size(); ++i)
{
if (myVec[i] % 10 != 0)
{
isMultiple = false;
break;
}
}
return isMultiple;
}
bool IsVectorNoMult10(std::vector<int> myVec)
{
bool isNotMultiple = true;
for (size_t i = 1; i < myVec.size(); ++i)
{
if (myVec[i] % 10 == 0)
{
isNotMultiple = false;
break;
}
}
return isNotMultiple;
}
int main(int size, std::vector<int> list)
{
if (IsVectorMult10(list))
{
std::cout << "all multiples of 10\n";
}
else if (IsVectorNoMult10(list))
{
std::cout << "no multiples of 10\n";
}
else
{
std::cout << "mixed values\n";
}
return 0;
}
Comments
Leave a comment