Question
Source Code: main.cpp: #include #include Blog.h #include using namespace std; const int MAX =100; int menu(); void addBlog(Blog blog[],int &numBlogs); void displayBlogs(Blog blog[],int numBlogs); void
Source Code:
main.cpp:
#include
using namespace std; const int MAX =100;
int menu(); void addBlog(Blog blog[],int &numBlogs); void displayBlogs(Blog blog[],int numBlogs); void readBlogs(Blog blog[], int &numBlogs); void writeBlogs(Blog blog[], int numBlogs); void createWebPages (Blog blog[], int numBlogs);
int main() { Blog blog[MAX_BLOGS]; int numBlogs = 0; int choice = 0;
readBlogs(blog, numBlogs); do { choice = menu(); switch (choice) { case 1: // ADD BLOG addBlog(blog, numBlogs); break; case 2: // DISPLAY ALL BLOGS displayBlogs(blog, numBlogs); break; case 3: // CREATE THE WEB PAGES createWebPages(blog, numBlogs); break; case 4: //Create index page case 5: // SAY GOOD BYE cout
writeBlogs(blog, numBlogs); return 0; }
void addBlog(Blog blog[],int &numBlogs) { string authorFirst,authorLast, content; int day,month, year; cout> authorFirst; cout > authorLast; cout> ws; getline (cin, content); cout> month; cout> day; cout> year; blog[numBlogs].setBlog(authorFirst, authorLast, content, month, day, year); numBlogs++; }
void displayBlogs(Blog blog[],int numBlogs) { string authorFirst,authorLast, content; int day,month, year; for(int i=0; i int menu() { cout > choice; return choice; } void readBlogs(Blog blog[], int &numBlogs) { ifstream infile("blogs.txt"); numBlogs = 0; string authorFirst = "", authorLast = "", content = ""; int month = 0, day = 0, year = 0; infile >> authorFirst; while (!infile.eof()) { infile >> authorLast; infile >> ws; getline(infile, content); infile >> month >> day >> year; blog[numBlogs].setBlog(authorFirst, authorLast, content, month, day, year); numBlogs++; infile >> authorFirst; } infile.close(); } void writeBlogs(Blog blog[], int numBlogs) { ofstream outfile("blogs.txt"); for (int i=0; i outfile.close(); } void createWebPages (Blog blog[], int numBlogs) { ofstream outfile; string filename; for (int i=0; i } Blog.h: #include class Blog { private: string authorFirst,authorLast,content; int day, month, year; public: Blog(); void setBlog(string,string,string, int, int, int); string getAuthorFirst()const; string getAuthorLast() const; string getContent() const; int getDay() const; int getMonth() const; int getYear() const; int menu(); }; Blog.cpp: #include "Blog.h" #include Blog::Blog() { authorFirst=""; authorLast=""; content=""; month=0; day=0; year=0; } void Blog::setBlog(string authorFirstIn,string authorLastIn,string contentIn, int monthIn, int dayIn, int yearIn) { authorFirst=authorFirstIn; authorLast=authorLastIn; content=contentIn; month=monthIn; day=dayIn; year=yearIn; } string Blog::getAuthorFirst()const { return authorFirst; } string Blog::getAuthorLast() const { return authorLast; } string Blog::getContent() const { return content; } int Blog::getDay() const { return day; } int Blog::getMonth() const { return month; } int Blog::getYear() const { return year; } int Blog::getDaysElasped() const { const int monthDays [12] ={31,28,31,30,31,30,31,30,31,31,30,31}; // compute days elapsed from 0-0-0000 to blog entry int num = 0; num = 365*year +day; int numLeaps = year/4 - year/100 + year/400; num += numLeaps; for(int i=0; i tm_year; int currMonth = 1 + ltm->tm_mon; int currDay= ltm->tm_mday; int num2 = 0; num2 = 365*year +day; int numLeaps2 = year/4 - year/100 + year/400; num2 += numLeaps2; for(int i=0; i } bool Blog::operator }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started