Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

extShape Media Comment Description: This program is going to define a preparator

ID: 3889764 • Letter: E

Question

extShape Media Comment Description: This program is going to define a preparatory class that you will be using for linked list. You are going to write this class and use it so that you ill be ready to use it for the linked list class. The class is going to be the Node class. Structure Book title - must hold the title of a book including spaces. Author- must hold the author's name including spaces Date read - must be able to contain numerical mo, day, year (digits) Node class data: declaration of the structure class .Pointer to class Node Node class member functions Default constructor Constructor that takes book title, author, and date Mutator function to set pointer Accessor function to return pointer Accessor function to return structure 'compare_data function that will compare a given book title against the one in the class process_data function that will print the data to the screen. Specific information for class: Define a class called Node. The Node class will hold a declaration of the structure and a pointer to a Node. The default constructor will set the book title to your favorite book, author to the author of the book, and the date read to some default date that you chose. The pointer will be set to NULL There will another constructor that will accept the book title, author, and the date. The pointer will be set to NULL Define a mutator function that will allow the pointer to be changed. Write an accessor function that will allow the pointer to be returned.

Explanation / Answer

Node.cpp

#include "stdafx.h"
#include "Node.h"


Node::Node() : _b00k{ "", "", "" }, _next{ NULL }
{
}

Node::Node(std::string book_title, std::string book_author, std::string date) :
   _b00k{ book_title , book_author, date }, _next{ NULL }
{}

void Node::set_next(Node * next)
{
   _next = next;
}

Node * Node::get_next() const
{
   return _next;
}

Book Node::get_b00k() const
{
   return _b00k;
}

bool Node::compare_data(Node node) const
{
   if (_b00k._title == node.get_b00k()._title)
       return true;
   else
       return false;
}

void Node::process_data() const
{
   cout << "Book title: " << _b00k._title <<
       "Book Author: " << _b00k._author <<
       "Read book on: " << _b00k._date_read
       << endl;
}

Node::~Node()
{
}

Node.h

#pragma once

#include <string>
#include <iostream>
using namespace std;

struct Book
{
   std::string _title;
   std::string _author;
   std::string _date_read;
};

class Node
{
private:
   Book _b00k;
   Node *_next;
public:
   Node();
   Node(std::string, std::string, std::string);
   void set_next(Node *);
   Node *get_next() const;
   Book get_b00k() const;
   bool compare_data(Node) const;
   void process_data() const;
   ~Node();
};