Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dear Chegg Experts, I am learning C++ and would deeply appreciate assistance in

ID: 3663789 • Letter: D

Question

Dear Chegg Experts,

I am learning C++ and would deeply appreciate assistance in building code in C++ for the following project specifications.

There is a similar question on Chegg for JAVA language. I don't know JAVA well enough to use that posted solution as a guide. I have included a link to the page I refer.

https://www.chegg.com/homework-help/questions-and-answers/create-program-using-java-language-understand-classes-problem-every-message-contains-conte-q10203199

Please help me create a C++ program that complies with the following requirements. I will post the code I have done so far so that you can see where I am.

Spec start:

Message, email, and shweet

Understand the classes and problem

Every message contains some content and a creator, or author. We could enhance these by adding other traits(Date and/or time of creation), but let's keep things simple and say these are the only two aspects of a basic message.

Some messages however have further components that defined them.

For example an email consists of a normal message, plus at least two other items: a from email address and ate too email address. And email it is a message but a special kind of message. So we can smell inheritance in the neighborhood. A message seems like it will make a good base class, and an email, is having an is a relationship with message, is a good candidate for a derived class or extension of the base class message.

Meanwhile, a tweet consists of a normal message, plus at least one other item: a from user ID.

A tweet is a message, too. It has a different kind of specialization then and email house, so it is a different extension of the base class. (we are not considering a direct tweet, which would also require a to user ID.)

Not only will both emails and tweets contain extra data then the base class, message, but in at least one instance we will see the same member (the content) have a different kind of restriction in the derived class then in the base class (can you guess what I'm suggesting before you read on?).

Thus, even though we store the tweet content in the base class member without the need for a new content area for the tweet, we will still have a different validation of the length of that message content.

Warning: Because it makes sense to do so, we are going to name the message content message and the message class Message. So what I called content in the above paragraph will be known as (lower – case) message in what comes next. The class, itself, will be (Upper – case) Message. You'll see. Just keep reading.

File structure: I prefer one file for the entire program, so you can put all classes together with main() in one file.

The base class: Message

Your base class is named Message.

Public or protected (your choice) static class constants

A full set of limits and defaults, like MAX_MSG_LENGTH and DEFAULT_AUTHOR, for both min, max lengths and default data of every member. Set the maximum message length to a large number (at least 1 million) and the maximum author length to a reasonable value like 40 or 65, not 5 or 200.

Private Member Data

string message;

string author;

Public methods

Default and 2 parameter constructors.

Mutator and accessor for each member.

toString method that provides a nicely formatted return string for potential screen I/O.

Private methods

Private static validation helpers to filter client parameters. These will support your public methods.

Recommended test of class Message

Instantiate two or more message object song using the default constructor and some using the parameter talking constructor. Mutate one or more of the members and after that use the toString() to assist a screen output so we can see what all of your objects contain. Next, test one or more accessors. Finally, test two or more new Tatars, providing both legal and illegal arguments and testing the return values (thus demonstrating that to the mutators do the right thing). Here is a sample run from my test (but you will have to imagine/deduce the source I used and create your own source for your testing, which will produce a different output).

Example test run of message class

/* ---------------------------------------------------------

Base Class Testing ***********************************

Author: Kinnard

Message ----------------------

Some messages just aren't worth sending.

Author: loceff

Message ----------------------

hello world

testing Message accessors:

Kinnard

hello world

testing Message mutators:

too long (as expected)

Author: Kinnard

Message ----------------------

Some messages just aren't worth sending.

acceptable length (should be)

Author: Kinnard

Message ----------------------

LONG STRING abcde abcde abcde abcde abcde abcde abcde abcde abcde abcde abc

de abcde abcde abcde abcde abcde

--------------------------------------------------------- */

The derived class: email

Your first derives class is named email. Email uses two members already present in the base class; the emails message is the message of the base class, and the author of the base class is the emails authors actual name (not the from email address which I will introduce next). Do not try to store and emails messages body or author as a new member of the derived class or you will get -20 points––not desirable by you or me. Duplicating base class a daughter in derived class means you do not understand what inheritance is, thus the significance of this kind of mistake.

Public static class constants

To the existing base class statics, add at least two with names and meanings similar or identical to max_email_address_length and default_email_address. Look up to the maximum length of an email address and make yours no larger than that (but you can make it smaller for easier testing).

Additional private member data

string fromAddress;

string toAddress;

Public methods

Default and 4-parameter constructors. Use constructor chaining.

Mutator and accessor for the new members.

Override those methods of the base class for which it makes sense to do so. Think about this and come to your own conclusions.

Private methods

Private static validation helper to filter a bad email address. You should do the minimum, but you don't have to be more complete than that. This is just to show that you can perform basic filtering. The minimum is a method isValidAddr() (or similarly named) which tests for both links and the existence of at least one ‘@’ and one ‘.’ character. Further is up to you, but don't overdo it or be too restrictive.

Recommended test of class email

Similar to the Message class.

Example test run of email class (done in the same run as overall program run)

EMail Derived Class Testing ***********************************

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

From: chloe123@gmail.com

To: lili999@gmail.com

Author: chloe

Message ----------------------

bark bark

testing EMail accessors:

lili999@gmail.com

lili999@gmail.com

testing Email mutators:

too long (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

missing @ char (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

missing DOT char (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

--------------------------------------------------------- */

The derived class: Shweet

Your second derived class is named shweet.

(it is like a twitter tweet, but since I can't be certain that the details of a tweet or exactly what I stated here, we will disengage this from twitter, and make the constraints that I impose accurate for a shweet by degree.)

Shweet uses of the two members already present in the base class; the suites of message is the message of the base class and, the Author of the base class is the sweet authors actual name (not the Shwitter ID which I will introduce next). Do not try to store a shweet message body or author as new members or you will get -20 points, as mentioned above.

Public static class constants

To the existing base class statics, add three with names and meaning similar or identical to MAX_SHWITTER_ID_LENGTH (15), MAX_SHWEET_LENGTH (140), and DEFAULT_USER_ID. Look up and use the actual maximum length of the first two constants.

While the MAX_SHWEET_LENGTH is going to be smaller than the base classes MAX_MSG_LENGTH, do not assume this fact in your implementation. A valid message length for a shweet has to be smaller than both of these values. If it's not a valid base class message, it isn't a valid shweet message, and this should be true if we later change the MAX_SHWEET_LENGTH length to be 50 million.

Additional private member data

String fromID;

Public methods

Default and 3– parameter constructors. When it is possible and meaningful, use constructor chaining. Think about which constructor to chain to.

Mutator and accessor for the new member.

Override those methods of the base class for which it makes sense to do so. Think about this and come to your own conclusions. You have to somehow enforce the length limits of both the base class and the derived class for the same message member.

Private Methods

Private static validation helpers(plural) to filter out the bad shweets and shwitter ID. Create isValidShweet() For the message. Also create an isValidShwitterID() for the Shwitter ID. But also, make a third, even lower – level, helper that would make isValidShwitterID() clear and short.

This helper – helper should be named something like stringHasOnlyAlphaOrNumOrUnderscore() and that name tells you the kind of thing it should do: it's should make sure the Twitter ID contains only some combination of letters, numbers, or an underscore (‘_’). The name of this method is fine–don't try to apply Boolean logic to it as there is no way to do so. Definition is what you care about. Also, I don't care whether you decide that the Twitter ID be case-sensitive. If you don't know the built – in the plus plus string work hard methods that can help you here, look them up online they are very easy to find.

Recommended test of class Shweet

Similar to the message class.

Example test run of tweet class (done in same run as overall program run)

/*Shweet Derived Class Testing ***********************************

Shweet: Kim Kardashian @kimkardashian

Oh Deer https://www.keek.com/!PYjCdab

Shweet: Katy Perry @katyperry

It's a verb and an adjective.

testing Shweet accessors:

kimkardashian

testing Shweet mutators:

bad shwitter ID (as expected)

Shweet: Kim Kardashian @kimkardashian

Oh Deer https://www.keek.com/!PYjCdab

acceptable shwitter ID (as expected)

Shweet: Kim Kardashian @a_good_user99

Oh Deer https://www.keek.com/!PYjCdab

--------------------------------------------------------- */

Code start:

//

// main.cpp

// Assignment_4

//

// Created by Macintosh User on 1/23/16.

// Copyright © 2016 Macintosh User. All rights reserved.

//

#include <iostream>

using namespace std;

class Message

{

private:

string message;

string author;

//static validationHelper();

  

public:

static int const MAX_MSG_LENGTH = 10000000;

static int const DEFAULT_AUTHOR = 60;

  

string getMessage();

string getAuthor();

string setMessage();

string setAuthor();

string toString();

};

class Email

{

private:

string fromAddress;

string toAddress;

//static validationHelper(); // filter bad email address// how to write a validation helper function?

  

public:

static int const MAX_EMAIL_ADDRESS_LENGTH = 255; // 255 characters; 64char@max255char

static const int DEFAULT_EMAIL_ADDRESS = 0; // Will fill.

  

string getFromAddress();

string getToAddress();

string setFromAddress();

string setToAddress();

string toString();

//Override those methods of the base class for which it makes sense to do so.

//Think about this and come to your own conclusions.

};

class Shweet

{

private:

string fromID; //Shwitter ID != author name

string stringHasOnlyAlphaOrNumOrUnderscore();

  

   //validation helper isValidShweet(Message);

//validation helper isValidShwitterID()

public:

static int const MAX_SHWITTER_ID_LENGTH = 15;

static int const MAX_SHWITTER_LENGTH = 140;

static int const DEFAULT_USER_ID = 50; //No mandated value...

string getFromID();

string setFromID();

};

int main()

{

//cout << "Base Class Testing *********************************** ";

//cout << "Author: " << author << endl;

//cout << "Message: " + "----------------------" << endl;

//cout << message << endl;

  

//cout << "Email Derived Class Testing *********************************** ";

//cout << "From: " << fromAddress << endl;

//cout << "To: " << toAddress << endl;

//cout << "Author: " << author << endl;

//cout << "Message: " + "----------------------" << endl;

//cout << message << endl;

  

//cout << "Testing email accessors:" << endl;

//cout << toAddress << endl;

  

//cout << "Testing email mutators:" << endl;

//cout << fromAddress << endl;

  

//cout << "Shweet Derived Class Testing *********************************** ";

//cout << "From: " << fromAddress << endl;

//cout << "To: " << toAddress << endl;

//cout << "Author: " << author << endl;

//cout << "Message: " + "----------------------" << endl;

//cout << message << endl;

  

return 0;

}

/*==============================================================================*/

//Message function definitions

string Message::getMessage()

{

return message;

}

string Message::getAuthor();

{

return author;

}

string Message::setMessage();

{

;

}

string Message::setAuthor()

{

;

}

string Message::toString()

{

;

}

/*==============================================================================*/

//Email function definitions

string Email::getFromAddress()

{

return fromAddress;

}

string Email::getToAddress()

{

return toAddress;

}

string Email::setFromAddress()

{

;

}

string Email::setToAddress()

{

;

}

string Email::toString()

{

;

}

/*==============================================================================*/

//Shweet function definitions

string Shweet::getFromID()

{

return fromID;

}

string Shweet::setFromID()

{

;

}

/*==============================================================================*/

//End of function definitions

/*

Spec Demo

Base Class Testing ***********************************

Author: Kinnard

Message ----------------------

Some messages just aren't worth sending.

Author: loceff

Message ----------------------

hello world

testing Message accessors:

Kinnard

hello world

testing Message mutators:

too long (as expected)

Author: Kinnard

Message ----------------------

Some messages just aren't worth sending.

acceptable length (should be)

Author: Kinnard

Message ----------------------

LONG STRING abcde abcde abcde abcde abcde abcde abcde abcde abcde abcde abc

de abcde abcde abcde abcde abcde

---------------------------------------------------------

EMail Derived Class Testing ***********************************

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

From: chloe123@gmail.com

To: lili999@gmail.com

Author: chloe

Message ----------------------

bark bark

testing EMail accessors:

lili999@gmail.com

lili999@gmail.com

testing Email mutators:

too long (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

missing @ char (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

missing DOT char (as expected)

From: lili999@gmail.com

To: hloe123@gmail.com.com

Author: lili koi

Message ----------------------

Arf, arf, arf, arf ........ arf

---------------------------------------------------------

Shweet Derived Class Testing ***********************************

Shweet: Kim Kardashian @kimkardashian

Oh Deer https://www.keek.com/!PYjCdab

Shweet: Katy Perry @katyperry

It's a verb and an adjective.

testing Shweet accessors:

kimkardashian

testing Shweet mutators:

bad shwitter ID (as expected)

Shweet: Kim Kardashian @kimkardashian

Oh Deer https://www.keek.com/!PYjCdab

acceptable shwitter ID (as expected)

Shweet: Kim Kardashian @a_good_user99

Oh Deer https://www.keek.com/!PYjCdab

--------------------------------------------------------- */

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;


class Message{
   private:
       string message;
       string author;
   public:
       static int const MAX_MSG_LENGTH = 10000000;
       static int const DEFAULT_AUTHOR = 60;
       Message(){
           message = "";
           author = "";
       }
       Message(string m,string a){
           message = m;
           author = a;
       }
       string setMessage(string m){
           message = m;
           return message;
       }
       string setAuthor(string a){
           author = a;
           return author;
       }
       string getMessage(){
           return message;
       }
       string getAuthor(){
           return author;
       }
       string toString(){
           string s = "Author : "+getAuthor()+' ';
           s += "Message --------------- ";
           s += getMessage();
           return s;
       }
};

class Email : public Message{
   private:
       string fromAddress;
       string toAddress;
   public:
       static const int MAX_EMAIL_ADDRESS_LENGTH = 255;
       static const int DEFAULT_EMAIL_ADDRESS = 0;
       Email() : Message(){
           fromAddress = "";
           toAddress = "";
       }
       Email(string f,string t,string m,string a) : Message(m,a){
           fromAddress = f;
           toAddress = t;
       }
       string getFromAddress(){
           return fromAddress;
       }
       string getToAddress(){
           return toAddress;
       }
       string setFromAddress(string f){
           fromAddress = f;
           return fromAddress;
       }
       string setToAddress(string t){
           toAddress = t;
           return toAddress;
       }
       string toString(){
           string s = "From : " + getFromAddress()+' ';
           s += "To : " + getToAddress()+' ';
           s += Message::toString();
           return s;
       }
};

class Shweet : public Message{
   private:
       string fromID;
       string stringHasOnlyAlphaOrNumOrUnderscore();
   public:
       static const int MAX_SHWITTER_ID_LENGTH = 15;
       static const int MAX_SHWITTER_LENGTH = 140;
       static const int DEFAULT_USER_ID = 50;
       Shweet() : Message(){
           fromID = "";
       }
       Shweet(string f,string m,string a) : Message(m,a){
           fromID = f;
       }
       string getFromID(){
           return fromID;
       }
       string setFromID(string id){
           fromID = id;
           return fromID;
       }
};

int main(){
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote