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

please use c++ , finish the question! These questions are representative of the

ID: 3588839 • Letter: P

Question

please use c++ , finish the question!

These questions are representative of the types and format of the midterm exam questions. The instructor has given similar questions in the past. Student must show all work for full or partial credit. 1. Given the class definition below, write a member function that checks if two strings (as defined below) are equal. Give PRE and POST conditions for the operator-you write. class String public: string) s[0]-0: bool operator-(const String&) const private: char s[256] I/null terminated character array

Explanation / Answer

Please find my answer.

#include <iostream>

using namespace std;

class string {

public:

string() { s[0] = '';};

bool operator ==(const string&) const;

private:

char s[256]; // null terminator character array

};

bool string::operator ==(const string &other) const {

int i = 0, j = 0;

while(s[i] != '' && other.s[j] != '') {

// if corresponding character is not equal

if(s[i] != other.s[j])

return false;

i++;

j++;

}

// if all characters are equal

if(s[i] == '' && other.s[j] == '')

return true;

else

return false;

}