In: Computer Science
Write a C++ function that lets the user enter alphabet letters into a static char array until either the user enters a non-alphabet letter or, it has reached the MAXSIZE. You can use the isalpha([Char]) function to check if the input is an alphabet letter or not.
void fillArray (char ar[], size_t& size){
// this is the function prototype
}
C++ CODE:
#include <iostream> using namespace std; #define MAXSIZE 10 void fillArray (char ar[], size_t& size){ char ch; cout << "Enter letters: "; ch = cin.get();//Read a character from input stream while(size < MAXSIZE && isalpha(ch)){//Check if character is alphabet or not ar[size] = ch; size++; ch = cin.get(); } } int main(){ char ar[MAXSIZE]; size_t size = 0; fillArray(ar, size); cout << "Array content: " << ar << endl; return 0; }
SAMPLE OUTPUT: