Can someone make a program that
accepts a word into a chracter array string variable. Display a
count of the number of letters in the word. Also display a count of the number of the vowels and the number of consonants in the word
and then put comment code on it and explain it to me
You are unlikely to get anyone to do your course work for you, if you have a specific question about a problem then post it, preferably with source code. If you show that you are trying to do the work people are more likely to help!
Its not actually course work it was a bonus assignment and I need to get an Idea on how to even start this off because I have never encountered anything this complex using C++ I am still just learning about strings and classes and would like to get an understanding of this work.
Put simply, gloabal variables can be used anywhere in your program, while local varaibles can only be used in the function they are declared in.
C++ make this more complicated as varaibles can be declared where you need them, rather than just at the start of a function
so you can have
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int a; //Global variable
int myfunction(int b)
{
int c=5; //local variable
return (b*c+a);
}
int main();
{
int d=10; //local variable, anywhere in main
a = 2;
for (int i=0; i<d; i++) //i is local to the for loop only
{
cout << myfunction(i) << endl;
}
return 0;
}
You cannot reference d or i in myfunction as they are local to main, similarly you cannot reference c in main.
i is an example of a varaible which is local to just a simple block of code (in this case a for loop).
b is local to myfunction, but takes the value of i (in this case) each time the function is called in the loop.
// Pseudo code only, for the "concept" of how to do this
#include <iostream>
#include <string>
char alphabet[26];
int main()
{
// Initialize the alphabet
for (int i = 0; i < 26; i++)
alphabet[i] = 'a' + i; // Set the alphabet array to contain 'a..z'
// Type "string" is used because it will increase in size automatically
std::string userInput;
// For this example only, assume that ALL text entered are lowercase, and without punctuation.
std::cout << "Input the string of text: ";
std::cin >> userInput;
unsignedint inputSize = userInput.size();
std::cout << "The size of the entire string (including spaces, punctuation, etc.) is: "
<< inputSize << std::endl;
unsignedint letterCount = 0;
for (int i = 0; i < inputSize; i++)
{
if (userInput[i] >= 'a' && userInput[i] <= 'z')
letterCount++;
}
std::cout << "The number of letters counted (lowercase, for this example) is: "
<< letterCount << std::endl;
unsignedint vowelCount = 0;
for (int i = 0; i < inputSize; i++)
{
if (userInput[i] == 'a' || userInput[i] == 'e' || userInput[i] == 'i' ||
userInput[i] == 'o' || userInput[i] == 'u')
{
vowelCount++;
}
}
// ... and so on, and so forth ...
}
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
char character1, character4;
int character2, character3, character5, character6;
cout<<"Enter a character must be A, B, or C"<<endl;
cout<<""<<endl;
cin>>character1;
if ( character1 != 'A' || 'B' || 'C')
{
cout<<"You entered an incorrect character please enter again..."<<endl;
cout<<""<<endl;
cin>>character1;
}
cout<<"Enter a number that can add up with a second number"<<endl
<<"To equal at least 22 and no more than 66"<<endl;
cout<<""<<endl;
cin>>character2;
cin>>character3;
if ( character2 + character3 < 22 )
{
cout<<"Your numbers equal less than 22 please enter another set"<<endl
<<"That combined equals more than 22 and less than 66"<<endl;
cout<<""<<endl;
cin>>character2;
cin>>character3;
}
if (character2 + character3 > 66 )
{
cout<<"Your numbers equal more than 66 please enter another set"<<endl
<<"That combined equals more than 22 and less than 66"<<endl
<<""<<endl;
cin>>character2;
cin>>character3;
}
cout<<"Enter a character that must be lower case"<<endl
<<""<<endl;
cin>>character4;
if ( character4 = 'A' || 'B' || 'C' || 'D' || 'E' || 'F' || 'G' || 'H' || 'I' || 'J' || 'K' || 'L' || 'M' || 'N' || 'O' || 'P' || 'Q' || 'R' || 'S' || 'T' || 'U' || 'V' || 'W' || 'X' || 'Y' || 'Z' )
{
cout<<"You entered a capitalized letter please enter a letter that is lower case"<<endl;
cout<<""<<endl;
cin>>character4;
}
system("PAUSE");
return 0;
}