Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

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;

}

2. A read() function

The read() function will allow the client programmer to specify the delimiting character (the character at which reading will stop). It should work just like the getline() function works for c-strings; that is, it should place everything up to but not including the delimiting character into the calling object, and it should also consume (and discard) the delimiting character. This will be a void function that will take two arguments, a stream and the delimiting character. It should not skip leading spaces. The limit of 127 characters imposed on the >> function above also applies to this function.

Hint: Don't try to read character by character in a loop. Use the in.getline() function to read the input into a non-dynamic array, then use strcpy() to copy it into your data member.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY