most people can identify the components of a “post” on a social media network like Instagram. Create your own Post struct consisting of at least five member variables and zero member functions. Each variable must have 1) a well-chosen type, 2) a well-chosen name and 3 Please use the correct syntax to declare a struct, for instance look at the Movie struct in tmdb.cpp  below is tmdb.cpp #include #include #include #include #include #include // data source: https://www.kaggle.com/tmdb/tmdb-movie-metadata struct Movie { std::string Title; std::string ReleaseDate; // YYYY-MM-DD, so we can compare as a string unsigned int RuntimeInMinutes; uint64_t BudgetInDollars; uint64_t RevenueInDollars; void print() { //std::cout.precision(17); std::cout << BudgetInDollars << ";" << ReleaseDate << ";" << RevenueInDollars << ";" << RuntimeInMinutes << ";" << Title << ";" << std::endl; } }; // convert line in csv to Movie struct // columns: budget, release date, revenue, runtime, title Movie parse(const std::string line) { Movie movie; int idxBudget = line.find(';'); std::string strBudget = line.substr(0, idxBudget); movie.BudgetInDollars = std::stoll(strBudget); int idxDate = line.find(';', idxBudget + 1); movie.ReleaseDate = line.substr(idxBudget + 1, idxDate - idxBudget - 1); int idxRevenue = line.find(';', idxDate + 1); movie.RevenueInDollars = std::stoll(line.substr(idxDate + 1, idxRevenue - idxDate - 1)); int idxRuntime = line.find(';', idxRevenue + 1); movie.RuntimeInMinutes = std::stoi(line.substr(idxRevenue + 1, idxRuntime - idxRevenue - 1)); std::string title = line.substr(idxRuntime + 1, line.length() - idxRuntime - 2); movie.Title = title; return movie; } struct MovieComparer {// no member variables // one member function... custom "less than" bool operator()(Movie m1, Movie m2) { return m1.ReleaseDate < m2.ReleaseDate; // string comparison } }; int main() { // open a file std::string path = "tmdb.csv"; std::ifstream file(path); // think of ifstream as cin // did it open? if (!file.is_open()) { std::cout << "ERROR: the file " << path << " did not open" << std::endl; return -1; } // populate vector std::vector movies; std::string line; while (std::getline(file, line)) { Movie movie = parse(line); // convert std::string to Movie movies.push_back(movie); } // sort vector std::sort(movies.begin(), movies.end(), MovieComparer()); // echo movies for (int idx = 0; idx < movies.size(); idx++) { movies[idx].print(); } return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

most people can identify the components of a “post” on a social media network like Instagram. Create your own Post struct consisting of at least five member variables and zero member functions. Each variable must have 1) a well-chosen type, 2) a well-chosen name and 3

Please use the correct syntax to declare a struct, for instance look at the Movie struct in tmdb.cpp 

below is tmdb.cpp

#include <algorithm>
#include <string>
#include <vector>
#include <cstdint>
#include <fstream>
#include <iostream>
// data source: https://www.kaggle.com/tmdb/tmdb-movie-metadata
struct Movie
{
std::string Title;
std::string ReleaseDate; // YYYY-MM-DD, so we can compare as a string
unsigned int RuntimeInMinutes;
uint64_t BudgetInDollars;
uint64_t RevenueInDollars;
void print()
{
//std::cout.precision(17);
std::cout
<< BudgetInDollars << ";"
<< ReleaseDate << ";"
<< RevenueInDollars << ";"
<< RuntimeInMinutes << ";"
<< Title << ";"
<< std::endl;
}
};
// convert line in csv to Movie struct
// columns: budget, release date, revenue, runtime, title
Movie parse(const std::string line)
{
Movie movie;
int idxBudget = line.find(';');
std::string strBudget = line.substr(0, idxBudget);
movie.BudgetInDollars = std::stoll(strBudget);
int idxDate = line.find(';', idxBudget + 1);
movie.ReleaseDate = line.substr(idxBudget + 1, idxDate - idxBudget - 1);
int idxRevenue = line.find(';', idxDate + 1);
movie.RevenueInDollars = std::stoll(line.substr(idxDate + 1, idxRevenue - idxDate
- 1));
int idxRuntime = line.find(';', idxRevenue + 1);
movie.RuntimeInMinutes = std::stoi(line.substr(idxRevenue + 1, idxRuntime -
idxRevenue - 1));
std::string title = line.substr(idxRuntime + 1, line.length() - idxRuntime - 2);
movie.Title = title;
return movie;
}
struct MovieComparer
{// no member variables
// one member function... custom "less than"
bool operator()(Movie m1, Movie m2)
{
return m1.ReleaseDate < m2.ReleaseDate; // string comparison
}
};
int main()
{
// open a file
std::string path = "tmdb.csv";
std::ifstream file(path); // think of ifstream as cin
// did it open?
if (!file.is_open())
{
std::cout << "ERROR: the file " << path << " did not open" << std::endl;
return -1;
}
// populate vector
std::vector<Movie> movies;
std::string line;
while (std::getline(file, line))
{
Movie movie = parse(line); // convert std::string to Movie
movies.push_back(movie);
}
// sort vector
std::sort(movies.begin(), movies.end(), MovieComparer());
// echo movies
for (int idx = 0; idx < movies.size(); idx++)
{
movies[idx].print();
}
return 0;
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY