Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple Note Taker using linked list. (Most of the project is already done, I just can't figure out a last few steps. Namely the listNotesByComposer

Simple Note Taker using linked list.

(Most of the project is already done, I just can't figure out a last few steps. Namely the listNotesByComposer function, deleteFrontNote function, and a few parts of the main function.)

(I've placed everything but the main function in a header file. The text file (which is sampled below) is a resource file named "input.txt". Thanks, you guys are a great help!)

This assignment implements a very simple note taker system as C++ classes. Each note(message) has several data fields: (1) composer, (2) date (note created date), (3) subject, and (4) a note body (the text of the note).

Given as input a group of notes, listed from the oldest note to the most recent, your program should be able to respond to following queries: Sort and display the created notes from the most recent to the least recent. Delete the most recent note. Display all the (non-deleted) notes of a given composer, arranged the most recent to the least recent.

Notes input data: Contains the notes, will be such that each note has one "paragraph" of several lines, and each note is separated from the next with a line consisting of ##########, that is, 10 consecutive occurrences of #. Note that you are guaranteed that each note in notefile.txt is more recent (has later date) than all the notes before it in that file. The format of the paragraph of a message is:

Composer: a string of at most 10 characters representing the composer. It has no blanks. DATE: a data, formatted as MM-DD-YYYY SUBJECT: a line of at most 60 characters BODY: a string (one or more lines starting at the next line below). It can have of any number of characters, such that no line begins with ##########

Sample of notes.txt:

COMPOSER: yson DATE: 01-21-2021 SUBJECT: Picking up BODY: Reminder: Pick up vegetables for dinner after work. ########## COMPOSER: hskim DATE: 01-22-2019 SUBJECT: Dr. Appointment BODY: Dental office appointment at 3:00, tomorrow. ########## COMPOSER: yson DATE: 11-20-2021 SUBJECT: Team meeting BODY: Team meeting will be held on March 11, 2022, from 1:30 - 3:30 p.m. In the process of hiring a new worker. ##########

Main menu Implement the main menu using while loop. Here is the menu:

1. LIST NOTES BY DATE: lists all the undeleted notes, arranged from the most recent to the least recent note. 2. LIST NOTES OF USER: lists all the undeleted notes from certain user. The notes must be arranged from the most recent to the least recent note. 3. DELETE MOST RECENT NOTE: deletes the most recent note. 4. QUIT: terminate the program

Sample Output: user input is underlined.

** Menu ** 1. LIST NOTES BY DATE 2. LIST NOTES OF COMPOSER 3. DELETE MOST RECENT NOTE 4. Quit Choose: 1 Yson Team meeting 11-20-2021 Yson Picking Up 1-21-2021 Hskim Dr. Assignment 1-22-2019 ** Menu ** 1. LIST NOTES BY DATE 2. LIST NOTES OF COMPOSER 3. DELETE MOST RECENT NOTE 4. Quit Choose: 2 Enter your name: yson Yson Team meeting 11-20-2021 Yson Picking Up 01-21-2021 ** Menu ** 1. LIST NOTES BY DATE 2. LIST NOTES OF COMPOSER 3. DELETE MOST RECENT NOTE 4. Quit Choose: 3 DELETE MOST RECENT NOTE: MESSAGE DELETED

Class Date You must convert string date from input file to Date format using Class Date. Class Date {

private: int month, day, year; public: Date(){} //set all attributes to zero void setDate(string) { //extract day, month, and year from the string using substr method //convert to integer (string to integer) and then assign them to attributes. } string showDate(){ string str = to_string(month) + '-' + to_string(day) + '-' + to_string(year); return str; } //used for comparing recent date before adding to noteList. int calculateDays() { return year * 365 + month * 31 + day; } };

Class Note Declare 4 private attributes: composer(string), date (Date), subject(string), and body (string) Constructor assigns all parameter values to attributes. Note(string c, string d, string s, string b); Note: 2nd parameter, d, is a date string. so, convert it to Date type. Getter method for each attribute.

Class NoteList Declare a noteNode: struct noteNode { Note note; noteNote *next; }; Declare a private attribute: head pointer variable that points to the most recent email. Constructor sets head to NULL. Getter and setter methods. When you run the program, load all data from the input file to noteList. void loadData(const char *)

The addNote method adds new note to noteList and increases the size by 1. For comparing recent note, use calculateDays() method. void addNote(Note) The listNotesByDate method prints all notes in noteList. void listNotedByDate(ostream&) The delete method remove the recent note from the noteList. void deleteFrontNote() The listNotesByComposer method prints all notes the passed composer already sent. void listNotedByDate(String composer) driver.cpp: following code shows partially. int main() { NodeList nList; nList.loadData(input.txt); // Loading data to linked list. Node node; do { //Display menu options //call method for processing each option. } while(.................); return 0; }

Here is the code I have so far, just in case it'll clear anything up.

(Header.h)

#pragma once #include #include #include #include using namespace std;

class Date { private: int month, day, year; public: Date() { month = 0; day = 0; year = 0; }

void setDate(string dateStr) { month = stoi(dateStr.substr(0, 2)); day = stoi(dateStr.substr(3, 2)); year = stoi(dateStr.substr(6, 4)); }

string showDate() { string str = to_string(month) + '-' + to_string(day) + '-' + to_string(year); return str; }

int calculateDays() { return year * 365 + month * 31 + day; } };

class Note { private: string composer, subject, body; Date date; public: Note(string c, string d, string s, string b) { composer = c; date.setDate(d); subject = s; body = b; }

string getComposer() { return composer; }

Date getDate() { return date; }

string getSubject() { return subject; }

string getBody() { return body; } };

class NoteList { private: struct noteNode { Note note; noteNode* next; }; noteNode* head;

public:

NoteList() { head = NULL; }

void loadData(const char* filename) { ifstream inputFile; inputFile.open(filename); if (inputFile.fail()) { cerr << "Error opening input file." << endl; exit(1); }

string line; while (getline(inputFile, line)) { if (line == "##########") { continue; }

string composer = line.substr(11); getline(inputFile, line); string dateStr = line.substr(6); getline(inputFile, line); string subject = line.substr(9); string body = ""; while (getline(inputFile, line)) { if (line == "##########") { break; } body += line + " "; } Note newNote = Note(composer, dateStr, subject, body); addNote(newNote); } inputFile.close(); }

void addNote(Note newNote) { noteNode* newNode = new noteNode; newNode->note = newNote; newNode->next = NULL;

if (head == NULL) { head = newNode; } else { noteNode* current = head; noteNode* prev = NULL; while (current != NULL && newNode->note.getDate().calculateDays() < current->note.getDate().calculateDays()) { prev = current; current = current->next; } if (prev == NULL) { newNode->next = head; head = newNode; } else { prev->next = newNode; newNode->next = current; } } }

void listNotesByDate(ostream& output) { noteNode* current = head; while (current != NULL) { output << current->note.getComposer() << " "; output << current->note.getSubject() << " "; output << current->note.getDate().showDate() << endl; output << current->note.getBody() << endl; output << "##########" << endl; current = current->next; } }

}

(Source.ccp)

#include #include #include #include #include "Header.h"

int main() { NoteList nList; nList.loadData("input.txt"); // Loading data to linked list. Note note(string c, string d, string s, string b); int userInput = 0; do { cout << "1. LIST NOTES BY DATE 2: LIST NOTES OF USER 3:DELETE MOST RECENT NOTE 4: QUIT" << endl; cin >> userInput; if (userInput == 1) { NoteList::listNotesByDate; } else if (userInput == 2) { NoteList::listNotedByComposer; } else if (userInput == 3) { NoteList::deleteFrontNote; } else { cout << "Error"; } //Display menu options //call method for processing each option. } while (userInput != 4); return 0; }

(Main function clearly isn't perfect; tried to make it more like an outline until I got all the header functions finished.)

There's also the text file, but it's a direct copy-paste of the sample mentioned in the question.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

ISBN: 3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

what is the valence state or charge on As in H3AsO3

Answered: 1 week ago