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

COMPUTER SCIENCE, I have 3 simple functions, code is in C size_t kstrlen(kstring

ID: 3666468 • Letter: C

Question

COMPUTER SCIENCE, I have 3 simple functions, code is in C

size_t kstrlen(kstring str)

Returns the length of the kstring str (that is, str.length).

char kstrget(kstring str, size_t pos)

Returns the character at index pos in str's data.

If pos is out of bounds (greater than or equal to the length of str), this function should abort the program: either by throwing an uncaught exception (C++), or by calling abort() (C or C++).

void kstrput(kstring str, size_t pos, char ch)

Replaces the character at index pos in str's data with the character ch.

If pos is out of bounds (greater than or equal to the length of str), this function should abort the program: either by throwing an uncaught exception (C++), or by calling abort() (C or C++).

(if you have any questions feel free to ask)

Explanation / Answer

1. int kstrlen(String str)

{

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

return i;

}

2.char kstrget(kstring str, size_t pos)

{ int p;

p=str.length();

if(pos>=p){ abort();}

else

{for (unsigned pos=0; pos<str.length(); ++pos)

{ std::cout << str.at(pos);

}

}

3.void kstrput(kstring str, size_t pos, char ch)

{for (int pos= 0; pos < str.length(); ++pos)

{ (str[pos] == ch)

}

return str; }

}

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