Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: //stringPkg.h//A library of ASCIIZ string functions.//All functions in this

ID: 3797165 • Letter: C

Question

C++:

//stringPkg.h//A library of ASCIIZ string functions.//All functions in this library manipulate character arrays//whose values are sequences of characters (string-values)//utilizing the ASCIIZ format.//----------------//Return length of a string, length > =0.//Length is a count of the characters in the string-value, //not including the null at the end.//An empty string (" ") has length theta. int stringLength (const char s[]);//---------------//Copy string src to string dest void string Copy (char dest [], const int destBuffsize, const char src []);//-----------//Concatenate string t to end of string dest void string Concatenate (char dest [], const int destBuffsize, const char t[]);//---------------//Retrieve character from string s[position] Position must be between 0 and (stringLength-1).//Return 0 if position is out of range char stringGetchar (const char s[], const int position);//---------------//Find ch in string s starting a the "startpos" array location.//startpos must be non-negative and less than the string length.//Return the 'found' position: 0 - (stringLength-1)//Return -1 if ch not found in s. int stringFindchar (const char s[], const char ch, const int startpos = 0);//---------------//Set resultString [] to a string value that is a copy of//a specified substring of original string s.//If specified start position is not located within the string s, //then set resultString to the empty string (" ").//If specified len the length of s//then set resultstring to the longest possible substring. Void stringSubstring(char resultString[], //new string buffer const int resultBuffSize, //result array biffer size const int s[], //starting position of substring within s const int len = -1);//length of substring within s//len

Explanation / Answer

#include<iostream>
using namespace std;

int stringLength(const char s[])//method which finds the length of the string
{
   int len=0;
   for(;s[len]!='';len++);//finding length ..// '' is last char in string
   return len;//and returns length
}

void stringCopy(char dest[],const int destBuffSize,const char src[])//copies src to dest
{
   int i=0;
   for(;i<destBuffSize;i++)
   {
       dest[i]=src[i];//copying...  
   }
}

void stringConcatenate(char dest[],const int destBuffSize,const char t[])//concatenate t to end of dest
{
   int i,k=0;
   for(i=0;dest[i]!='';i++);
   for(;i<destBuffSize;i++,k++)
   {
       dest[i]=t[k];//concatenating.
   }
  
}
char stringGetchar(const char s[],const int position)//getting char from given position
{
   return s[position];
}
int stringfindchar(const char s[],const char ch,const int startpos)//finding char postion
{
   int l=stringLength(s);
  
   if(startpos<0 || startpos>l-1)
   return -1;
   else
   {
       int i=0;
       while(i<l){
           if(s[i]==ch)
           return i;
           i++;
       }
   }
   return -1;
}
void stringSubstring(char resultString[],const int resultBuffsize,const char s[],const int start,const int len)
{
  
   int l =stringLength(s);
  
   if(start >=0 && start<l)
   {
            int m = start+len;
             m = m-l;
            if(m>0)
            {
               m=l;
           }
           else
           {
               m =start+len;  
           }
          
           int i=0;
           int j=start;
           while(j<m && i<resultBuffsize)//finding max possible substring
           {
               resultString[i++]=s[j++];  
           }
   }
  
  
}

int stringCompare(const char s[],const char t[])
{
   int i,j,ls=stringLength(s),lt = stringLength(t);
   if(ls>lt)return 1;//if s>t
   else if(ls<lt)return -1;//if s<t
   else
   {
   for(i=0;s[i]!='';i++)
   {
       if(s[i]>t[i])//if s>t
           return 1;
       else if(s[i]<t[i])//if s<t
           return -1;
      
   }
   }
   return 0;//if s==t
}

int main()
{
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote