1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
#include <string.h>
using namespace std;
class list //Class for the elements of a journal entry and the functions for it
{
public:
list();
~list();
void insert();
void display_all();
void read();
private:
char * date; //variable for the date
char * subject; //variable for the subject
char * writing; //variable for the body of the entry
};
struct node //structure to create a node containing the appropriate information
{
list data; //variable to hold the members of the entry struct
node * next;//creates a pointer to the next node
};
list::list()
{
date=NULL;
subject=NULL;
writing=NULL;
}
list::~list()
{
delete[]date;
delete[]subject;
delete[]writing;
}
void list::display_all()
{
node * head=NULL;
node * current=head;
while(current!=NULL)
{
cout<<head->data.date<<'\t'<<head->data.subject<<endl;
cout<<head->data.writing<<endl;
current=current->next;
}
}
void list::insert() //Function to add a journal entry
{
char temp[501]; //temporary variable
node * head; //head is a pointer to a node
head=NULL; //Making sure that head has no value
node * current=head; //temporary pointer
if(!head)
{
head=new node; //assigns what head is pointing to
cout<<"Please enter the date of the entry followed by the enter key"<<endl;
cin.get(temp,501,'\n');
head->data.date=new char[strlen(temp)+1];
strcpy(head->data.date,temp);
cin.ignore(100,'\n');
cout<<"Please enter the subject of the entry followed by the enter key"<<endl;
cin.get(temp,501,'\n');
head->data.subject=new char[strlen(temp)+1];
strcpy(head->data.subject,temp);
cin.ignore(100,'\n');
cout<<"Please type your entry followed by the enter ':' symbol"<<endl;
cin.get(temp,501,'\n');
head->data.writing=new char[strlen(temp)+1];
strcpy(head->data.writing,temp);
cin.ignore(1000,'\n');
head->next=NULL; //attaches the list
}
else
{
char array[501];
node * temp=new node;
cout<<"Please enter the date of the entry followed by the enter key"<<endl;
cin.get(array,501,'\n');
temp->data.date=new char[strlen(array)+1];
strcpy(temp->data.date,array);
cin.ignore(100,'\n');
cout<<"Please enter the subject of the entry followed by the enter key"<<endl;
cin.get(array,501,'\n');
temp->data.subject=new char[strlen(array)+1];
strcpy(temp->data.subject,array);
cin.ignore(100,'\n');
cout<<"Please type your entry followed by the enter ':' symbol"<<endl;
cin.get(array,501,'\n');
temp->data.writing=new char[strlen(array)+1];
strcpy(temp->data.writing,array);
cin.ignore(1000,'\n');
temp->next=head;
}
}
void welcome()
{
cout<<"Welcome to Robin's Electronic Journal"<<endl;
cout<<"You can use this program to create a journal entry"<<endl;
cout<<"to find a journal entry or to display all entries"<<endl<<endl;
}
int main()
{
welcome();
list love;
love.insert();
love.display_all();
cin.get();
return 0;
}
|