(Please Use c++ code) 1. For this assignmaent all you need to do is fix the prog
ID: 3825807 • Letter: #
Question
(Please Use c++ code)
1. For this assignmaent all you need to do is fix the program and make sure it compiles?
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Tweet
{public:
Tweet(string s, string m);
string getSubject();
string getMessage();
void changeMessage(string m);
private:
string subject;
string message;
};
Tweet::Tweet(string s, string m)
{subject = s;
message = m;
}
string Tweet::getSubject()
{return subject;
}
string Tweet::getMessage()
{return message;
}
void Tweet::changeMessage(string m)
{message = m;
}
class Twitter
{public:
Twitter();
void addTweet(Tweet newmessage);
Tweet gettweet(string subject);
private:
vector<Tweet> messages;
};
Twitter::Twitter()
{
}
void Twitter::addTweet(Tweet newmessage)
{messages.push_back(newmessage);
}
Tweet Twitter::gettweet(string subject)
{for(int i=0; i<messages.size();i++)
{if(messages[i].getSubject() == subject)
{return messages[i];
}
}
return Tweet();
}
int main()
{Twitter t = Twitter();
Tweet s = Tweet("FINISHED MIDTERM","ACED IT");
t.addTweet(s);
}
Explanation / Answer
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Tweet
{public:
Tweet(string s, string m);
string getSubject();
string getMessage();
void changeMessage(string m);
private:
string subject;
string message;
};
Tweet::Tweet(string s, string m)
{subject = s;
message = m;
}
Tweet::Tweet()
{
}
string Tweet::getSubject()
{return subject;
}
string Tweet::getMessage()
{return message;
}
void Tweet::changeMessage(string m)
{message = m;
}
class Twitter
{public:
Twitter();
void addTweet(Tweet newmessage);
Tweet gettweet(string subject);
private:
vector<Tweet> messages;
};
Twitter::Twitter()
{
}
void Twitter::addTweet(Tweet newmessage)
{messages.push_back(newmessage);
}
Tweet Twitter::gettweet(string subject)
{for(int i=0; i<messages.size();i++)
{if(messages[i].getSubject() == subject)
{return messages[i];
}
}
return Tweet();
}
int main()
{Twitter t = Twitter();
Tweet s = Tweet("FINISHED MIDTERM","ACED IT");
t.addTweet(s);
}
===========================================================================
FiXED this code, You can have a look and try to check
The added part of the code is highlighted in bold.
Thanks , let me know if there is any concern.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.