Write a C++ function using pointer notation that receives an integer array and a
ID: 3881527 • Letter: W
Question
Write a C++ function using pointer notation that receives an integer array and another number and returns the count of how many numbers in the array are positive and smaller than the received number.
Write a C++ function that receives a character array and uses pointer notation to count how many times each of the vowels a, e, i, o, and u were found among the characters in the array and returns these counts as another array of size 5. Also write a main() function that obtains up to 200 characters from the user, uses the above written function to count the occurrence of each, and prints these counts. User will enter a -1 to indicate end of entering data. Your program must use dynamic memory allocation.
Please explain your solutions
Explanation / Answer
#include <iostream>
using namespace std;
void printLesser(int *a, int x)
{
int i, count = 0;
// looping through each element in a
for (i=0;i<sizeof(a) ; i++){
// checking if the value is positive and less than given number
// increasin count by 1
if(*a<x && *a > -1){
count++;
}
*a++;
}
// printing count
cout << count;
}
// sample run
int main() {
int a[]= {-1, 0, 1, 3, 5, 6, 7, 8};
printLesser(a, 4);
}
#include <iostream>
using namespace std;
void printLesser(int *a, int x)
{
int i, count = 0;
// looping through each element in a
for (i=0;i<sizeof(a) ; i++){
// checking if the value is positive and less than given number
// increasin count by 1
if(*a<x && *a > -1){
count++;
}
*a++;
}
// printing count
cout << count;
}
// sample run
int main() {
int a[]= {-1, 0, 1, 3, 5, 6, 7, 8};
printLesser(a, 4);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.