Vous êtes sur la page 1sur 3

Create a class for the following requirement

-------------------------------------------------------------
String s;
--------------------------------------------------------------------------------
--
s = "testing message";
Above code should assign string testing message to object s
--------------------------------------------------------------------------------
--
s = s.toUpperCase( )
Should convert the object data to uppercase and return
converted object
--------------------------------------------------------------------------------
--
String x;
x = s.toUpperCase( )
s value should be immutable( should not modify ) and
converted string should be given to x
--------------------------------------------------------------------------------
--
int x = s.length( )
Should return string length.
--------------------------------------------------------------------------------
--
int p = s.indexOf("ing");
(4) because ing exists at 4th position.
If not found -1 should be returned.
--------------------------------------------------------------------------------
--
s = "http://www.yahoo.com"
if( s.startsWith("http") )
cout << "It is using http protocol";
StartsWith should check for characters given from the beginning of the
string.
In the same way "endsWith" should also work.
--------------------------------------------------------------------------------
--
s = s.insert( 4 , "india");
insert a new string at 4th position.
--------------------------------------------------------------------------------
--
s = "beetal everest";
String r = s.substring( 3 , 4 );
It should extract characters from 3rd position for 4 characters

String x = s.substring( 3 )
It should extract all characters from 3rd position until end.
--------------------------------------------------------------------------------
--
s = "hello india"
char c = s.charAt(0)
|
'h'
char t = s.charAt(1)
|
'e'
--------------------------------------------------------------------------------
--
String s;
cin >> s;
--------------------------------------------------------------------------------
--
cout << s;
--------------------------------------------------------------------------------
--

Using Above class i wanted following main( ) program should work

1. void main( )
{
String site;
cin >> site;
if( site.endsWith(".com"))
cout << "Commerical site";
else
cout << "Some other site";
}

2.
void main( )
{
String s;
cin >> s;
int c=0;
for(int i=0; i<s.length(); i++)
{
char e = s.charAt(i);
switch(e)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':c++;
}
}
cout << "Count of vowels = " << c;
}

3.
void main( )
{
String mobile;
cin >> mobile;
if( mobile.startsWith("9845") && mobile.length() == 10 )
cout << "Valid airtel number";
else if( mobile.startsWith("9342") && mobile.length() == 10 )
cout << "Valid reliance number";
else
cout << "Some other provider"
}

Vous aimerez peut-être aussi