vowel , consonent , and other functions in a programm

// Class work.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std ;

int capital(char str[100])
{
int capi = 0 ;
int i = 0 ;
while (str[i] != NULL)
{
if (str[i] >= 'A' && str[i] <= 'Z')
capi ++ ;
i ++ ;
}
return capi ;
}


int small(char str[100])
{
int sml = 0 ;
int i = 0 ;
while (str[i] != NULL)
{
if (str[i] >= 'a' && str[i] <= 'z')
sml ++ ;
i ++ ;
}
return sml ;
}

int vowel(char str[100])
{
int vowl = 0 ;
int i = 0 ;
while (str[i] != NULL)
{
switch(str[i])
{
case 'a' : case 'A' :
case 'e' : case 'E' :
case 'i' : case 'I' :
case 'o' : case 'O' :
case 'u' : case 'U' :
vowl ++ ;
default :
break ;
}
i ++ ;
}
return vowl ;
}


int consonent(char str[100])
{
int i = 0 , consnt = 0 ;
while (str[i] != NULL)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z' )
consnt ++ ;
i ++ ;
}
i = 0 ;
while (str[i] != NULL)
{
switch (str[i])
{

case 'a' : case 'e' : case 'i' : case 'o' : case 'u' : case 'A' : case  'E' : case 'I' : case 'O' : case 'U' :
consnt  = consnt - 1 ;
default :
break ;
}
i++ ;
}
return consnt ;
}

int space(char str[100])
{
int spc = 0 ;
int i = 0 ;
while (str[i] != NULL)
{
if (str[i] == ' ')
spc ++ ;
i ++ ;
}
return spc ;
}



int word(char str[100])
{
int wrd = 0 ;
int i = 0 ;
if (str[0] == ' ')
wrd = 0 ;
else
wrd = 1 ;

while (str[i] != NULL)
{
if (str[i] == ' ' && str[i + 1] != ' ' && str[i + 1] != NULL)
wrd ++ ;
i ++ ;
}
return wrd ;
}


int main ()
{
char input[100] ;
cout << "Enter your string : " ;
cin.getline(input , 100 , '\n') ;
cout << endl << "Capital words in your enterd string : " << capital(input) << endl << endl ;
cout << "Small words in your enterd string : " << small(input) << endl << endl ;
cout << "Vowel words in your enterd string : " << vowel(input) << endl  << endl;
cout << "Consonent words in your enterd string : " << consonent(input) << endl << endl ;
cout << "Spaces in your enterd string : " << space(input) << endl << endl ;
cout << "Words in your enterd string : " << word(input) << endl  << endl;
main() ;
return 0 ;
}


Next PostNewer Post Previous PostOlder Post Home

0 comments:

Post a Comment