WriteaprograminC++thatcreates thefollowingfunctions:
Â
Function
Description
Â
Receivesstringobjectandreturnsnumberofvowelsinit.
Â
Receivesstringobjectandreturnsnumberofconsonants
init.
Â
Receivesstringobjectandreturnsnumberofuppercase
lettersinit.
Â
Receivesstringobjectandreturnsnumberoflowercase
lettersinit.
Â
Useallofthefunctions inmainfunction.
#include<iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
class functions{
public:
void vowel(){
char line[150];
  int vowels=0;
      cout<<"\nChecking vowels";
cout << "\nEnter a line of string: ";
  cin.getline(line, 150);
  for(int i = 0; line[i]!='\0'; ++i)
  {
    if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
      line[i]=='o' || line[i]=='u' || line[i]=='A' ||
      line[i]=='E' || line[i]=='I' || line[i]=='O' ||
      line[i]=='U')
    {
      ++vowels;
    }
}
cout << "Vowels: " << vowels << endl;}
void consonant(){
char line[150];
      int consonants=0;
      cout<<"\nChecking consonant";
cout << "\nEnter a line of string: ";
      cin.getline(line, 150);
      for(int i = 0; line[i]!='\0'; ++i)
      {
if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
    {
      ++consonants;
    }
    cout << "Consonant: " << consonants << endl;
}}
void UpperLowercase(){
int i;
  int upper=0,lower=0;
  char ch[100];
  cout<<"\nChecking uppercase and lowercase letters:";
  cout<<"\nEnter the String:\n";
  gets(ch);
  for(i=0; ch[i]!=0; i++){
if(ch[i]>='A' && ch[i]<='Z'){
  upper++;
}
else if(ch[i]>='a' && ch[i]<='z'){
  lower++;
}
  }
cout<<"lowercase letters:" <<lower;
cout<<"\nuppercase letters:"<<upper;
getch();
}
};
int main(){
functions f;
f.vowel();
f.UpperLowercase();
f.consonant();
}
Comments
Leave a comment