Question: Create a function that will create the index.html file. It should be valid HTML code. The web page should include a heading at the top
- Create a function that will create the index.html file. It should be valid HTML code. The web page should include a heading at the top of the web page and a hypertext to each of the blog web pages. The links should be displayed from newest to oldest. To accomplish this, your sort function should be called by this function. The web page will look something like that shown below. The author names should be the link. The dates should be included. Each link is included within a paragraph tag. The index page and all of the blog web pages must be written to a folder named website. (c++)
My source code so far:
#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); void selectionSort(Blog blog[], int numBlogs); void indexPage(Blog blog[], int numBlogs);
int main() { Blog blog[MAX]; 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: indexPage(blog,numBlogs); case 5: // SAY GOOD BYE cout << "Good bye" << endl; break; default: // INVALID CHOICE cout << "You have entered an invalid choice" << endl; break; } } while (choice != 5);
writeBlogs(blog, numBlogs); return 0; }
void addBlog(Blog blog[],int &numBlogs) { string authorFirst,authorLast, content; int day,month, year; cout<<"Enter the author's first name: " << endl; cin >> authorFirst; cout << "Enter the author's last name: "<
void displayBlogs(Blog blog[],int numBlogs) { string authorFirst,authorLast, content; int day,month, year; for(int i=0; i int menu() { int choice; cout <<"Press 1 to add to blog"< 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 Written by "<< blog[i].getAuthorFirst() << " " << blog[i].getAuthorLast() << " date: " << blog[i].getMonth() << "-" << blog[i].getDay() << "-" << blog[i].getYear() << endl; outfile << "" << endl << " 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 getDaysElasped() const; bool operator<(const Blog &right) const; }; 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 < month-1; i ++) num +=monthDays[i]; time_t now = time(0); // compute days elasped from 0-0-0000 to current date tm *ltm = localtime(&now); int currYear = 1900 + ltm->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 < currMonth-1; i ++) num2 +=monthDays[i]; int daysElasped = num2-num; return daysElasped; } bool Blog::operator<(const Blog &right) const { if (getDaysElasped() }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
