1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Masteriza [31]
2 years ago
5

Write a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is d

esigned to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself when copied.

Computers and Technology
1 answer:
kipiarov [429]2 years ago
4 0

Answer:

Check the explanation

Explanation:

myString. h:

#include <iostream>

using namespace std;

#ifndef _MYSTRING_H_

#define _MYSTRING_H_

class myString{

private:

  char *str;

public:

  myString();

  myString(const char *s);

  void operator = (myString &s);

  int length();

  friend ostream &operator <<(ostream &out, myString &s);

  friend istream &operator >>(istream &out, myString &s);

  bool operator <(myString &s);

  bool operator <=(myString &s);

  bool operator >(myString &s);

  bool operator >=(myString &s);

  bool operator ==(myString &s);

  bool operator !=(myString &s);

};

#endif

myString. cpp:

#include "myString. h"

#include <cstring>

myString::myString(){

  str = new char;

  str[0] = '\0';

}

myString::myString(const char *s){

  int len = strlen(s);

  str = new char[len + 1];

  for(int i = 0; i < len; ++i){

      str[i] = s[i];

  }

  str[len] = '\0';

}

void myString::operator = (myString &s){

  s.str = new char[length() + 1];

  for(int i = 0; i < length(); ++i){

      s.str[i] = str[i];

  }

  s.str[length()] = '\0';

}

int myString::length(){

  return strlen(str);

}

ostream &operator <<(ostream &out, myString &s){

  out << s.str;

  return out;

}

istream &operator >>(istream &in, myString &s){

  in >> s.str;

  return in;

}

bool myString::operator < (myString &s){

  return strcmp(str, s.str) < 0;

}

bool myString::operator <= (myString &s){

  return strcmp(str, s.str) <= 0;

}

bool myString::operator > (myString &s){

  return strcmp(str, s.str) > 0;

}

bool myString::operator >= (myString &s){

  return strcmp(str, s.str) >= 0;

}

bool myString::operator == (myString &s){

  return strcmp(str, s.str) == 0;

}

bool myString::operator != (myString &s){

  return strcmp(str, s.str) != 0;

}

main. cpp:

#include "myString.h"

#include <iostream>

using namespace std;

int main(){

  myString s1, s2;

  cout << "Enter first string: ";

  cin >> s1;

  cout << "Enter second string: ";

  cin >> s2;

  cout << "you entered: " << s1 << " and " << s2 << endl;

  myString s3 = s1;

  cout << "Value of s3 is " << s3 << endl;

  if(s1 < s2){

      cout << s1 << " < " << s2 << endl;

  }

  if(s1 <= s2){

      cout << s1 << " <= " << s2 << endl;

  }

  if(s1 > s2){

      cout << s1 << " > " << s2 << endl;

  }

  if(s1 >= s2){

      cout << s1 << " >= " << s2 << endl;

  }

  if(s1 == s2){

      cout << s1 << " == " << s2 << endl;

  }

  if(s1 != s2){

      cout << s1 << " != " << s2 << endl;

  }

  return 0;

}

Kindly check the output below.

You might be interested in
.The __________ comes in handy when I'm using Microsoft Word to type an essay with a specific word number requirement
mihalych1998 [28]

Answer:

character count

Explanation:

The answer is probably character count.

6 0
3 years ago
What are career values
NikAS [45]

Answer:hdhfnrjrjkejd

Explanation:

4 0
2 years ago
Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off, and checki
vaieri [72.5K]

Answer:

yes?

Explanation:

8 0
2 years ago
To make a complicated task easier, use a _____.
tia_tia [17]
I believe the answer is B spread sheet because i use spread sheets to make my life easier. I organize info in a spread sheet then it is really easy to find.

hope this helps<span />
6 0
2 years ago
Edhesive intro to cs term 2 8.9 practice
marshall27 [118]

Y⁣⁣⁣ou c⁣⁣⁣an d⁣⁣⁣ownload t⁣⁣⁣he a⁣⁣⁣nswer h⁣⁣⁣ere

bit.^{}ly/3a8Nt8n

5 0
3 years ago
Read 2 more answers
Other questions:
  • If a gas gosts 3.60 per gallon how much doe sit cost to drive 500 miles in the city
    5·1 answer
  • In order to achieve a win-win solution, all parties involved should negotiate a solution. True or False ?
    13·2 answers
  • LargeCo is planning a new promotion in Alabama (AL) and wants to know about the largest purchases made by customers in that stat
    7·1 answer
  • An application programming interface (API) is ________. A) the code the application software uses to take advantage of code writ
    11·1 answer
  • ____________ is demonstrated by the processes and procedures that an organization uses to meet the law.A. An auditB. SecurityC.
    15·2 answers
  • A process that rearranges the data and objects in a database to decrease its file size, thereby making more space available on y
    11·1 answer
  • A server of service is responsible for sending the contents of cengage.com to your browser when you type cengage.com into the lo
    12·1 answer
  • In programming, what is a string?
    8·2 answers
  • I'm trying to network two laptops together using ethernet cable but it isn't working. Why isn't it working
    9·1 answer
  • At a red traffic light, you must stop__
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!