Answer to Question #265533 in C++ for Usama

Question #265533

ProblemStatement1

WriteaprograminC++thatcreates thefollowingfunctions:

 

Function

Description

 

Receivesstringobjectandreturnsnumberofvowelsinit.

 

Receivesstringobjectandreturnsnumberofconsonants

init.

 

Receivesstringobjectandreturnsnumberofuppercase

lettersinit.

 

Receivesstringobjectandreturnsnumberoflowercase

lettersinit.

 

Useallofthefunctions inmainfunction.


1
Expert's answer
2021-11-23T06:56:23-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS