Here are the instructions problem I need help with. 1. You are to write a progra
ID: 3620975 • Letter: H
Question
Here are the instructions problem I need help with.
1. You are to write a program that takes an array of characters as its input and creates an array of characters as its output. Every vowel found in the input array should be in uppercase in the output array. At the same time, your program is to count the number of vowels that are encountered in the input array and the number of all non-vowel characters that are encountered in the output array.
2. Your program will not accept input, instead use the list of input provided with the assignment.
3. Your output, for each of the inputs provided, will be the original text, with all of the vowels in uppercase, followed by a blank line, and then the number of vowels counted printed on one line and the number of non-vowels counted printed on the next line. Insert one blank line between each set of output. Do not print “headers” or extraneous output; just what is asked for.
4. You must use the following function in your program:
void printArray (const char inputArray[], int vowels, int nonVowels, int size);
(prints the array content to the screen).
The use of other functions is up to you.
5. The program is to run only once.
=============================================================================
A sample input might look like the following:
I was going to Texas, but I got lost and went to Connecticut instead.
Its corresponding output would look like the following:
I wAs gOIng tO TExAs, bUt I gOt lOst And wEnt tO COnnEctIcUt InstEAd.
21
48
Notice the blank line between the line of alpha-numeric output and the lines of numeric output.
List of inputs:
There's no lace like home, but I want to go to Alabama.
I lost my book called "Introduction to Information Security."
My Issues:
I know how to count the vowels and such, but I should be able to convert the vowels to uppercase in the code below at the same time I am counting them but can't. I'm also confused by the bit about the two inputs on the list when I was only asked for one, but my main concern is converting the vowels to uppercase.
My code so far:
//begin program
#include iostream
#include cctype
using namespace std;
//declare void printArray and void lowerToUpper
void printArray (const char inputArray[], int vowels, int nonVowels, int size);
//void searchArray(int inputArray[], int target, int size);
//declare main
int main()
{
//initialize char inputArray, int vowels, nonVowels and size
const char inputArray[]="There's no place like home, but I want to go to Alabama. ";
int vowels = 0, nonVowels = 0, size = 0;
printArray(inputArray, vowels, nonVowels, size);
system ("pause");
return EXIT_SUCCESS;
}
//end main
//define void printArray
void printArray (const char inputArray[], int vowels, int nonVowels, int size)
{
//change the string in inputArray to change all vowels to uppercase
//count all vowels and non-vowels
while (inputArray[size])
{
if ('a' == inputArray[size] ||'e' == inputArray[size] ||'i' == inputArray[size] ||'o' == inputArray[size]||'u' == inputArray[size]||'A' == inputArray[size] ||'E' == inputArray[size] ||'I' == inputArray[size] ||'O' == inputArray[size]||'U' == inputArray[size])
{
if (islower(inputArray[size]))
{
toupper(inputArray[size]);
}
vowels++;
}
else
{
nonVowels++;
}
size++;
}
//output the filter arrayed, and the counts of vowels and non-vowels
cout << inputArray << endl;
cout << " ";
cout << vowels << endl;
cout << nonVowels << endl;
}
//end program
Explanation / Answer
please rate - thanks
I would have done it a little differently, but I wanted to change your code as little as possible
the way you did this you don't need int vowels, int nonVowels and int size in your function, you don't use them. that was a suggestion
//begin program
#include<iostream>
//#include< cctype> not needed
using namespace std;
//declare void printArray and void lowerToUpper
void printArray (const char inputArray[], int vowels, int nonVowels, int size);
//void searchArray(int inputArray[], int target, int size);
//declare main
int main()
{
//initialize char inputArray, int vowels, nonVowels and size
const char inputArray[]="There's no place like home, but I want to go to Alabama. ";
int vowels = 0, nonVowels = 0, size = 0;
const char inputArray2[]="I lost my book called "Introduction to Information Security." ";
printArray(inputArray, vowels, nonVowels, size);
printArray(inputArray2, vowels, nonVowels, size);
system ("pause");
return EXIT_SUCCESS;
}
//end main
//define void printArray
void printArray (const char inputArray[], int vowels, int nonVowels, int size)
{char outputArray[strlen(inputArray)+1];
//change the string in inputArray to change all vowels to uppercase
//count all vowels and non-vowels
while (inputArray[size])
{outputArray[size]=inputArray[size];
if ('a' == inputArray[size] ||'e' == inputArray[size] ||'i' == inputArray[size] ||'o' == inputArray[size]||'u' == inputArray[size]||'A' == inputArray[size] ||'E' == inputArray[size] ||'I' == inputArray[size] ||'O' == inputArray[size]||'U' == inputArray[size])
{
if (islower(inputArray[size]))
{
outputArray[size]=toupper(inputArray[size]);
}
vowels++;
}
else
{
nonVowels++;
}
size++;
}
outputArray[size]='';
//output the filter arrayed, and the counts of vowels and non-vowels
cout << outputArray << endl;
cout << " ";
cout << vowels << endl;
cout << nonVowels << endl;
}
//end program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.