A Tweet is message that has two parts: subject and message. Design a class Tweet
ID: 3792372 • Letter: A
Question
A Tweet is message that has two parts: subject and message. Design a class Tweet that has these two string attributes - subject and message. Your class should have a constructor function, accessor functions for returning the subject and message, and a mutator function which accepts a string newmessage and changes the message attribute to the newmessage. Give BOTH the interface and the member functions as follows. Write the class interface (definition) for Tweet including constructor, accessors, and mutator functions. Write the constructor Tweet which accepts the strings for the subject and message, and sets the attributes accordingly. Write the accessor function which returns the subject attribute. Write the mutator function which accepts a string parameter and uses that string to change the message attribute.
Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
class tweet
{
public:
string subject;
string massege;
tweet(string s1, string s2)
{
subject = s1;
massege = s2;
}
string accesor()
{
return subject;
}
void mutator(string s2)
{
massege = s2;
}
};
int main()
{
tweet t = tweet("Politics", "Trup is President!");
cout << t.accesor() << endl;
t.mutator("Changed massege");
cout << t.massege << endl;
return 0;
}
sample output:
Politics
Changed massege
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.