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
A strategy to solve a logic problem is to break it into steps. Using the drop-down menu, complete these sentences about solving
PSYCHO15rus [73]
I think the answer is 3!!
3 0
2 years ago
Read 2 more answers
Many mobile devices can perform Internet searches and other tasks via
Sedaia [141]

the answer is D Voice commands

8 0
3 years ago
EASY AND I GIVE BRAINLIEST!!! What is a good jeopardy question about operating systems?
madam [21]

 ______ is used in operating system to separate mechanism from policy
<span><span>A. Single level implementation</span><span>B. Two level implementation</span><span>C. Multi level implementation</span><span>D. None</span></span>
3 0
2 years ago
If Scheme were a pure functional language, could it include DISPLAY ? Why or why not?​
VARVARA [1.3K]

Answer:

When Scheme is a pure functional language, it cannot include the function DISPLAY. Since the pure functional languages will return the same value whenever the same expression is evaluated, and the DISPLAY would be the output and thus it cannot be part of the purely functional language. Thus in the pure functional language we can evaluate the expressions with the same arguments and it returns the same value since there is no state to change.

Explanation:

4 0
2 years ago
Multicurrency: There are several products that universal containers sells exclusively in Europe and the UK. Opportunities for th
ivanzaharov [21]

Answer:

D – Create a new validation rule that allows only EUR or GBP to be selected from all active currencies when an opportunity is created for these products.

Explanation:

Application containers are used to hold applications deployed to the internet during production. These containers are products of online hosting cloud services, used to control and maintain the application in production.

Access to the application's functionalities requires validation, the user must be authenticated and authorized to access certain services of the application.

5 0
3 years ago
Other questions:
  • Why are computer programs so much longer now than they were in the late 1980?
    8·1 answer
  • PLEASE HELP
    14·2 answers
  • What program controls the hardware and software in a computer?
    10·1 answer
  • Which of the following is a characteristic of the internet today? distributed network central hub lack of protocols absence of c
    5·1 answer
  • Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessar
    6·1 answer
  • Give sally sue specific suggestions on how she can improve her powerpoint skills.
    6·1 answer
  • If we can lock a file, we can solve the race condition problem by locking a file during the check-and-use window, because no oth
    14·1 answer
  • 1. What is JavaScript?
    15·1 answer
  • Jeremy has created a document that has images and a chart. The chart has to be updated manually, and double-clicking on the char
    15·1 answer
  • What does 69 mean?<br> Whenever I watch memes they always talk about the number 69
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!