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

Implement the following methods in the C++ program - String(const char* s): cons

ID: 3588382 • Letter: I

Question

Implement the following methods in the C++ program

- String(const char* s): constructor

- String(): destructor

- String & operator=(const String &st): assign operator

Program Description

i. Find `lab4.h' and `driver.cpp'

ii. Write down your code only between
//your code from here~ //your code to here.

iii. Do not modify other parts.

iv. Evaluate your program using `driver.cpp'

This Should be the output:

Constructor test (CSULB): pass
Constructor test (CECS424): pass
Destructor test: pass
Assign op. test: pass

Explanation / Answer

Source Code:

#include<iostream>
#include<string.h>
using namespace std;

class String
{
char *str;
public:
  

char *get() { return str; }


String(const char *s)
{
int l = strlen(s);
str = new char[l+1];
strcpy(str, s);
}
~String()
{
cout<<" Destructor Invoked";
}

};
int main()
{
String s1("Constructor Invoked");
cout << s1.get();

}

Output:

Constructor Invoked

Destructor Invoked