Hello~!
Yes it has been a very, very, long time since I posted anything programming wise. I have been really busy with University trying to get all my portfolio work done and handed in on time, it was very stressful!
Well, enough about me and onto the programming! I decided to share with you challenge 7 from my portfolio with you today as it was one of the many interesting and probably most random challenges we had to do.
The task:
Write a program which asks the user to write some text before analysing it to see how many occurrences of each vowel appears in that text, you should store the number of occurrences of each vowel in an array of size 5.
Adapt this program to produce some more statistics about the text, this may include some or all of the following…
- The vowel that occurs most/least often
- The average (mean) number of occurrences for the vowels
- A list of vowels, ordered by number of occurrences
- You could even use the Cursor and Colour controllers to draw a histogram!
Here is my code!
<<——————————->>
//
// challenge 7.cpp
//
//
// Created by Sarah Oluyede on 30/03/2012.
// Copyright (c) 2012_All rights reserved.
//
#include <iostream>
#include <string>
using namespace std;
int main()
{
string text;
int vowels[5] = {0,0,0,0,0};
char vvowels[5] = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’};
int strlen;
cout << “Enter the text you want to analyse” << endl << endl;
getline(cin, text);
cout << endl << “Analysing \”" << text << “\” … ” << endl << endl;
cout << “Analysis Result” << endl << “——————————” << endl << endl;
strlen = text.length();
cout << “\tText Length : “<< strlen << endl << endl;
for(int i=0; i<5; i++){
for(int n=0; n<strlen; n++){
if (text[n] == vvowels[i]){
vowels[i] += 1;
}
}
}
for(int i=0; i<5; i++){
cout << “\tNumber of Vowel \”" << vvowels[i] << “\” : “<< vowels[i] << endl << endl;
}
double total = vowels[0] + vowels[1] + vowels[2] + vowels[3] + vowels[4];
cout << “\tTotal Number of Vowels \”a + e + i + o + u\” : “<< total << endl << endl;
int moccur = 0;
for(int i = 0; i < 5; i++){
if(vowels[i] > moccur){
moccur = i;
}else{
moccur = moccur;
}
}
cout << “\tMost Occured Vowel \”" << vvowels[moccur] << “\” : “<< vowels[moccur] << endl << endl;
int loccur = 0;
for(int i = 0; i < 5; i++){
if(vowels[i] < loccur){
loccur = i;
}else{
loccur = loccur;
}
}
cout << “\tLeast Occured Vowel \”" << vvowels[loccur] << “\” : “<< vowels[loccur] << endl << endl;
double mean;
mean = total / 5;
cout << “\tThe mean number of occurences of vowels is : ” << mean << endl << endl;
return 0;
}
<<——————————->>
You should try it out, it’s pretty fun to play with!




