Answer to Question #117733 in C++ for ayza

Question #117733
Write a program to pass a reference of a character array in a function, store it in a pointer variable and then calculate the total characters and vowels in the array.
1
Expert's answer
2020-05-24T17:15:16-0400
#include <iostream>
#include <string>
using namespace std;

void countChars(char (&arr)[8]) {
  string vowelsArr = "aeiou";
  char *ptr = arr;

  int total = 0;
  int vowels = 0;

  for (int i = 0; i < 8; ++i) {
    ++total;
    if (vowelsArr.find(*ptr) != -1) {
      ++vowels;
    }
    ++ptr;
  }

  cout << "total: " << total << endl;
  cout << "vowels: " << vowels << endl;
}

int main() {
  char a[] = {'d', 'f', 'a', 'x', 'e', 'r', 'b', 'u'};

  countChars(a);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS