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]
3 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]3 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
You try to enter your name into a cell that accepts a numeric value. What error would you receive? A. #NAME B. #VALUE C. #REF D.
UNO [17]

Answer:

<h2>Option B: #VALUE</h2>

is the correct answer.

Explanation:

<h3>Reasons of #VALUE error:</h3>
  • When cells are not given the expected type of value.
  • If cells are left blank unnoticeable or for giving a null value.
  • For entering dates and other numerical data in text form.
<h3>Correcting and fixing #VALUE error:</h3>

This type of error can only be fixed by finding the cell in which there is wrong data entered and correct it.

Fixing the #VALUE error is tricky as some functions automatically ignore the data that is invalid.

<h3>EXAMPLE:</h3>
  • Suppose a cell contains the value as cost of the object and in order to make it 0, NA is inserted into the cell.
  • While making total of all the costs, that particular cell might cause #VALUE error.
  • Following image attach will help you clear the concept.

I hope it will help you!

4 0
3 years ago
Read 2 more answers
Which of these is not a feature of a CPU?<br><br>Multicore<br>64-Bit Processing<br>L1 Cache<br>DDR
Triss [41]

Answer:

DDR

Explanation:

DDR is a feature of memory. It means a double data rate and is a more sophisticated version of the SDRAM, which is a memory. And the rest like the Multicore, 64-bit processing, and the L1 cache are the features of the CPU. And hence, the correct option here is none other than DDR. Remember that the L1 cache is the memory bank, which is being built over the CPU chip. And we have 32 bit and 64-bit processing for the CPU. As well as CPU can be dual-core, quad-core and likewise.

4 0
3 years ago
Read 2 more answers
How do lung and heart work together
Vinil7 [7]
Heart is attached to the lungs by the pulmonary artery and vein the artery carries deoxygenated blood to the pulmonary circuit (lungs) the lungs have a gas exchange and the deoxygenated blood goes back to the heart via the pulmonary vein.<span />
8 0
3 years ago
Which of the following ways is NOT one of the ways that the census is
Liono4ka [1.6K]

Answer: By internet

Explanation:

5 0
3 years ago
Regression testing should be a normal part of integration testing because as a new module is added to the system new
nikklg [1K]
It's E) both A and B A) Control logic is invoked B) Data flow paths are established
7 0
3 years ago
Other questions:
  • To apply the rule of thirds you first? PLZ HURRY AND ANSWER THIS
    5·2 answers
  • The ____________ is the number of rectangles an image has in a square inch.
    11·2 answers
  • What is a way to Procter your social security number and other sensitive information from identity theft
    9·1 answer
  • The tax calculator program of the case study outputs a floating-point number that might show more than two digits of precision.
    7·1 answer
  • A port is the point at which a peripheral device attaches to or communicates with a computer or mobile device. True False
    15·1 answer
  • In an information systems framework, ________ is the bridge between the computer side on the left and the human side on the righ
    14·1 answer
  • Describe the difference between the circumscribed and inscribed options when using the AutoCAD Polygon command
    14·1 answer
  • On line two, you take a string, word, as input. Then, using that string...
    9·1 answer
  • What is the name of the first practical asymmetric cryptosystem that was created?
    15·1 answer
  • You can use a(n) ______________to store large amounts of customer data for a website.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!