0% found this document useful (0 votes)
35 views4 pages

Lab Journal 4 OOP

This document provides instructions for an object oriented programming lab assignment. Students are asked to submit a PDF with the code and output for an exercise involving a String class. The String class should have data members for the string and functions for getting string input, counting consonants, counting vowels, and checking if the string is a palindrome. The code provided defines the String class with these functions. It also includes a main function that creates a String object, gets input, and calls the functions to output the results.

Uploaded by

haseeb Urehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Lab Journal 4 OOP

This document provides instructions for an object oriented programming lab assignment. Students are asked to submit a PDF with the code and output for an exercise involving a String class. The String class should have data members for the string and functions for getting string input, counting consonants, counting vowels, and checking if the string is a palindrome. The code provided defines the String class with these functions. It also includes a main function that creates a String object, gets input, and calls the functions to output the results.

Uploaded by

haseeb Urehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming

Lab Journal – Lab 1


(Deadline: - Saturday (1-10-2022) 11:59 AM (midnight))
Where to submit:-LMS link for submission!
For queries: - [email protected]

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.

void CountConsonants( ) //displays the total number of consonants in the


string
void VowelCount( ) //displays the total vowels in the string
void Palindrome( ) //displays if the string is a palindrome or
not Use pointer of object to call the member function of the
class.

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

+++++++++++++++++++++++++

You might also like