Question: Goal: Learn how to implement friend functions. Assignment: You re developing a feature for a social media app to compare two posts by popularity. A
Goal: Learn how to implement friend functions.
Assignment: Youre developing a feature for a social media app to compare two posts by popularity. A post's popularity is calculated as:
likes comments
Where likes is the number of likes and comments is the number of comments.
Define a class named SocialMediaPost with the following members:
An int member variable named likes.
An int member variable named comments.
A constructor that accepts two int arguments. The first argument should be assigned to likes, and the second argument should be assigned to comments.
The SocialMediaPost class should declare the function getSuggested as a friend.
Outside of the SocialMediaPost class, write a function named getSuggested that takes two pointers to SocialMediaPost objects as arguments. The function should calculate the popularity of each post using the formula above and return a pointer to the SocialMediaPost object with the highest popularity. If both posts have the same popularity, the function should return nullptr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
