Professional Documents
Culture Documents
Example : “Hello”
Strings can be also be entered from the keyboard and displayed on the screen:
#include <iostream>
#include <string>
int main()
{
string message;
cout<<"Input any string value : ";
getline(cin, message);
system("pause");
return 0;
}
1.) Create a C++ program that will input string and display the string in reverse order.
#include <iostream>
#include <string> //length or size
int main()
{
string stringinput;
int ctr, ctreachletter;
// system("pause");
return 0;
}
2.) Create a C++ program that will input a string and count how many are alphabetic
character, numeric character, and special character in that string;
#include <iostream>
#include <cctype>
#include <string> //length or size
int main()
{
string stringinput;
int ctreachchar, ctralpha, ctrnumeric, ctrspecial;
ctralpha=0;
ctrnumeric = 0;
ctrspecial = 0;
for(ctreachchar = 0; ctreachchar < stringinput.length(); ctreachchar++)
{ stringinput[ctreachchar]= toupper(stringinput[ctreachchar]);
if(stringinput[ctreachchar]>='A' && stringinput[ctreachchar]<='Z')
ctralpha++;
else if(stringinput[ctreachchar]>='0' && stringinput[ctreachchar]<='9')
ctrnumeric++;
else
ctrspecial++;
}
cout<<endl<<"In the string entered the number of alphabetic character is "<<ctralpha<<endl;
cout<<endl<<"In the string entered the number of numeric character is "<<ctrnumeric<<endl;
cout<<endl<<"In the string entered the number of special character is "<<ctrspecial<<endl;
// system("pause");
return 0;
}
3.) Create a C++ program that will input five strings and display the five strings in reverse
order.
#include <iostream>
#include <string> //length or size
int main()
{
string stringinput [5];
int ctr, ctreachletter;
// system("pause");
return 0;
}