Lab Journal 4 OOP
Lab Journal 4 OOP
You will be submitting a pdf file containing all the working codes plus outputs of the
following questions with comments explaining what your program is doing line by line.
Your file extension should be Name_rollno_class_section!
Create a class named myString,which consists of one string data member and three
functions. Input the string from the user at run time then call the followingfunctions
on it.
CODE:
nclude< ostream>
nclude<str ng>
us ng namespace std;
nt Consonant;
nt Vowel;
class myStr ng
{
publ c:
str ng str;
vo d setStr ng()
{
cout << "Enter the str ng: " << endl;
getl ne(c n, str);
}
str ng getStr ng()
{
return str;
}
vo d countConsonants()
{
for ( nt = 0; < str.length(); ++)
{
f ((str[ ] != 'a' && str[ ] != 'e' && str[ ] != ' ' && str[ ] != 'o' &&
str[ ] != 'u') && (str[ ] != 'A' && str[ ] != 'E' && str[ ] != 'I' && str[ ] != 'O' && str[
]
!= 'U') && (str[ ] != ' '))
{
Consonant++;
}
}
cout << "The number of Consonants are: " << Consonant << endl;
}
vo d Vowelcount()
{
for ( nt = 0; < str.length(); ++)
{
f ((str[ ] == 'a' || str[ ] == 'e' || str[ ] == ' ' || str[ ] == 'o' ||
str[ ] == 'u') || (str[ ] == 'A' || str[ ] == 'E' || str[ ] == 'I' || str[ ] == 'O' || str[ ]
== 'U'))
{
Vowel++;
}
}
cout << "The number of vowels are: " << Vowel << endl;
}
vo d flal ndrome()
{
for ( nt = 0; < str.length() / 2; ++)
{
f (str[ ] != str[str.length() - - 1]) {
cout << "The above text s NOT a pal ndrome! " << endl;
}
else
{ cout << "The above text s a flal ndrome " << endl;
}
}
}
};
nt ma n()
{
myStr ng obj;
obj.setStr ng();
obj.getStr ng();
obj.Vowelcount();
obj.countConsonants();
obj.flal ndrome();
return 0;
}
OUTPUT:
COMMENT: USER UMAIR KHALID IS MY COUSIN.I HAVE USED HIS LAPTOP TO MAKE THE
ASSIGNENT. THANKS
+++++++++++++++++++++++++