0% found this document useful (0 votes)
6 views5 pages

Hailemariam Addisu String Operation

This C++ program performs various string operations including reversing a string, extracting a substring, checking for palindromes, and converting case between upper and lower. The program prompts the user for input strings and allows them to choose which operation to perform through a menu. It is designed for educational purposes by a group of students.

Uploaded by

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

Hailemariam Addisu String Operation

This C++ program performs various string operations including reversing a string, extracting a substring, checking for palindromes, and converting case between upper and lower. The program prompts the user for input strings and allows them to choose which operation to perform through a menu. It is designed for educational purposes by a group of students.

Uploaded by

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

#include<iostream>

#include<algorithm>

#include<string.h>

using namespace std;

int main(){

char ch;

char str[80],st[100];

int i,l,operation,n;

string s, s1,s2,s3;//string variable

cout<<"========================================\n";

cout<<" THIS C++ PROGRAM IS ABOUTOPERATION\n ON STRING WITH OUT FUNCTION";

cout<<"========================================\n";

cout<<"\n\tTHIS ASSIGNMENT DONE BY GROUP SIX \n\tNAME\t\t\tID NO\n\tHAILEMARIAM ADDISU \


t094\n\tHAYMANOT ALEMU \t\t102\n\tZIGIJU MINSHIR \t\t185\n\tHAILEMELEKOT MELAKIE\t095\n";

cout<<"=========================================\n";

cout<<" Enter string for reverse : "<<endl;

cin>>str;

cout<<"\n enter the string that take in substring:";

cin>>s;

cout<<" Enter a string for palindrome :\n ";

cin>>s1;

cout<<" Enter a lower case string :\n ";

cin>>s3;

cout<<" Enter an upper case string:\n ";


cin>>st;

do{

cout<<"\n==================================\n";

cout<<"\n\t\tpress 1 for reverse of string \n\t\tpress 2 for substring of string \n\t\tpress 3 for palindrom
check\n\t\tpress 4 for lower case into upper\n\t\tpress 5 for upper case into lower case\n";

cout<<"====================================\n";

cout<<"\n enter your choce from the menu\n";

cin>>operation;

switch(operation){

case 1:

cout<<"\n==================================\n";

cout<<" the string before :"<<str;

int l; //Hold length of string

//Find the length of the string

for(l = 0; str[l] != '\0'; l++);

//Display the string backwards

cout<<"\n Reverse of string: ";

for( i = l - 1; i >= 0; i--)

cout << str[i];}

cout<<"\n==================================\n";

break;
case 2:

cout<<"\n==================================\n";

int x,n;//the number that starting and

// ending for substring

cout<<"enter number that indicate starting point \n";

cin>>x;

cout << "Enter an integer that limit no.string \n";

cin>>n;

cout<< "\n the substring of "<<s<<" start from index "<<x<<" to index "<<n+x<<" "<<s.substr(x,n);

cout<<"\n==================================\n";

break ;

case 3:

cout<<"\n==================================\n";;

s2 = s1;

reverse(s1.begin(),s1.end());

if(s1==s2) {

cout<<"String "<<s1<<" is Palindrome";

else {
cout<<"String "<<s1<<" is not Palindrome";

cout<<"\n==================================\n";

break ;

case 4:

cout<<"\n==================================\n";

cout<<" \n the lower case string :"<<s3;

for(i = 0; i< s3[i]; i++) {

if(s3[i]>=97 && s3[i]<=122) {

s3[i] = s3[i]-32;

}}

cout<<"\n In Upper case:";

for(i=0;i<s3[i];i++){

cout<< s3[i];

cout<<"\n==================================\n";

break ;

case 5:

cout<<"\n==================================\n";

cout<<" an upper case string: "<<st;

for( i=0;st[i]!='\0';i++)
{

if( st[i] >=65&&st[i]<=90){

st[i]=st[i]+32;}

cout<<"\n Lower case string: " << st<< endl;

cout<<"\n==================================\n";

break ;

default:

cout<<"\n==================================\n";

cout<<"\nWe have no more operation in this program.\n";

cout<<"\n==================================\n";}

cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

cout<<"\n Do you want return \n press A or a\n";

cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

cin>>ch;

}while(ch=='A' || ch=='a');

return 0;

You might also like