Monday, October 29, 2018

Finding Length of string using user defined functions

#include<iostream>
using namespace std;
int u_strlen(char s[])
{int i;
 for(i=0; s[i]!='\0'; i++);  // starts from first character till last
    return i; // return strlen
}
int main()
{
    // declare the string
    char name[40];
    //accept the string
   // cin>>name; // ignore space in between
    cin.getline(name,40); // accept space also
            cout<<name <<endl; // display string
    int len=u_strlen(name);
cout<<"Length of String is "<<len<<endl;
//display string in reverse order
for(int k=len-1;k>=0;k--)
cout<<name[k]<<endl;
    system("pause");
    return 0;
}
   
   
   
   
   
   
    

String Manipulation (output Answer)

#include<iostream>
using namespace std;
void u_strmanip(char s[])
{int i;
 for(i=0; s[i]!='\0'; i++)  // starts from first character till last
 {
  if(isupper(s[i]))
   s[i]=s[i]+1;
  else
  if(i%2!=0)
  s[i]=s[i+1];
  else
  if(!isalnum(s[i]))
  s[i]='*';
 
}
}
int main()
{
    // declare the string
    char name[40];
    //accept the string
   // cin>>name; // ignore space in between
    cin.getline(name,40); // accept space also
          //  cout<<name <<endl; // display string
   u_strmanip(name);
//display string in reverse order
cout<<name;
    system("pause");
    return 0;
}
   
    Give output for
CoMpuTEr SciENce 2019

Answer
DMNuuUF *TcEFOc *0099