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
Take any software or Application that you have recently purchased, this can be a video game or any other application helping you
IgorC [24]

A good product should have copyright protection which prevents others from using the product without permission.

Some products specify the penalties which are given to a person who makes unauthorized copies of their product and this is done to clearly educate to avoid ignorance claims.

A good product should have clear lettering which are legible and can be easily read, and should also have reasonable copyright protection.

<h3>What is Copyright?</h3>

This refers to the licensing which is done for a product and is also legally backed which prevents a person from illegally using or redistributing the work of a creator without their explicit consent.

Read more about copyright infringement here:
brainly.com/question/1078532

8 0
2 years ago
In python please!! Write the definition of a function named countPos that needs integer values from standard input until there a
jek_recluse [69]

Answer:

Explanation:

The following code is written in Python it doesn't use any loops, instead it uses a recursive function in order to continue asking the user for the inputs and count the number of positive values. If anything other than a number is passed it automatically ends the program.

def countPos(number=input("Enter number: "), counter=0):

   try:

       number = int(number)

       if number > 0:

           counter += 1

           newNumber = input("Enter number: ")

           return countPos(newNumber, counter)

       else:

           newNumber = input("Enter number: ")

           return countPos(newNumber, counter)

   except:

       print(counter)

       print("Program Finished")

countPos()

8 0
3 years ago
Why is the cpu the most important component in a computer?
german
CPU (Central Processing Unit) is also known as the brain of the computer because this is the place which actually runs the programs. The programs are the set of instructions needed to perform a task.
4 0
2 years ago
given an array of integers a, your task is to count the number of pairs i and j (where 0 ≤ i &lt; j &lt; a.length), such that a[
Nimfa-mama [501]

Using the knowledge of computational language in C++ it is possible to write a code that given an array of integers a, your task is to count the number of pairs i and j.

<h3>Writting the code:</h3>

<em>// C++ program for the above approach</em>

<em> </em>

<em>#include <bits/stdc++.h></em>

<em>using namespace std;</em>

<em> </em>

<em>// Function to find the count required pairs</em>

<em>void getPairs(int arr[], int N, int K)</em>

<em>{</em>

<em>    // Stores count of pairs</em>

<em>    int count = 0;</em>

<em> </em>

<em>    // Traverse the array</em>

<em>    for (int i = 0; i < N; i++) {</em>

<em> </em>

<em>        for (int j = i + 1; j < N; j++) {</em>

<em> </em>

<em>            // Check if the condition</em>

<em>            // is satisfied or not</em>

<em>            if (arr[i] > K * arr[j])</em>

<em>                count++;</em>

<em>        }</em>

<em>    }</em>

<em>    cout << count;</em>

<em>}</em>

<em> </em>

<em>// Driver Code</em>

<em>int main()</em>

<em>{</em>

<em>    int arr[] = { 5, 6, 2, 5 };</em>

<em>    int N = sizeof(arr) / sizeof(arr[0]);</em>

<em>    int K = 2;</em>

<em> </em>

<em>    // Function Call</em>

<em>    getPairs(arr, N, K);</em>

<em> </em>

<em>    return 0;</em>

<em>}</em>

See more about C++ code at brainly.com/question/17544466

#SPJ4

4 0
1 year ago
Why was the television the first audio visual device that changed the way people see entertainment?
Daniel [21]
It was  not.   Movies   then  talking movies  were   before television.

7 0
3 years ago
Other questions:
  • Make three statements about technology
    9·1 answer
  • The file extensions .webm, .m4v, and .ogv are used for:
    15·1 answer
  • Q10: Putting it all together (0.75 points) Here, we'll update the values in dictionary, storing the output in a dictionary calle
    5·1 answer
  • Leonardo is having difficulty accessing the course website. he should contact the for assistance. (points:1)
    13·1 answer
  • Create an application named TurningDemo that creates instances of four classes: Page, Corner, Pancake, and Leaf. Create an inter
    7·1 answer
  • Drag the right word to it’s definition
    13·1 answer
  • To have a reason or purpose to do something
    8·2 answers
  • How is the architecture converted into software code? Elaborate the steps its passes through with help of examples / Diagram.
    15·1 answer
  • Convert the following decimal numbers into their binary equivalent: a. 13
    9·1 answer
  • 1. Define the term M.A.N.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!