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
|
#include"journal.h"
int main()
{
welcome();//calls the welcome function
object.menu();//calls the menu function
termination();//calls the termination function
}
void welcome()
{
cout<<"Welcome to the Electronic Journal Program!" <<endl <<endl;
cout<<"This program will allow you to record your" <<endl;
cout<<"thoughts electronically instead of wasting"<<endl;
cout<<"all of that paper!" <<endl <<endl;
}
journal::journal(int size = 100)
{
my_journal = new entry[100];
my_journal_size = 100;
num_entries = 0;
}
journal::~journal()
{
delete [] my_journal;
my_journal = NULL;
}
void journal::menu() //menu function
{
char choice; //variable to hold the choice
do //loop that keeps prompting the user until a valid choice is inputted
{
cout<<"What would you like to do? " <<endl;
cout<<"Choose Option 1 to add a new Journal Entry " <<endl;
cout<<"Choose Option 2 to display all of your Journal Entries " <<endl;
cout<<"Choose Option 3 to find an entry by the subject " <<endl <<endl;
cout<<"Please enter a choice (1,2, or 3): " <<endl;
cin>>choice; cin.ignore(100, '\n'); //reads in the choice and eats the rest
if (choice == '1')
object.new_entry(); //if 1, Create a new journal entry
else if (choice == '2')
object.display_all();// if 2, Display everything
else if (choice == '3')
object.search(); //if 3, search by subject
else
cout<<"Error, Please try again" <<endl <<endl; //error message, restarting the loop
}while (choice != '1' && choice != '2' && choice != '3');
}
void journal::new_entry() //function for inputting a new journal entry
{
char temp[MAX]; //variable to read in the journal entry temporarily
//loop to read in until we reach the maximum size of the Journal
while (num_entries > my_journal_size);
{
cout<<"Please enter the date for this entry (MM/DD/YYYY): ";
cin.get(my_journal[num_entries].date, DATE, '\n'); //read in the date
cin.ignore(100, '\n'); //eat the carriage return
cout<<"Please enter the subject for this entry ";
cin.get(my_journal[num_entries].subject, SUB, '\n'); //read in subject
cin.ignore(100, '\n'); //eat the carriage return
cout<<"Please enter your Journal entry ";
cin.get(temp, MAX, '\n'); //read in the entry
cin.ignore (100, '\n'); //eat the carriage return
my_journal[num_entries].entry = new char[strlen(temp)+1];
//creates an array of 1+the string length
strcpy(my_journal[num_entries].entry, temp); //copy the temp into entry
++num_entries; //add 1 to the counter
cout<<endl <<endl <<endl;
menu();//calls the menu function to get back
}
}
void journal::display_all() //display everything entered
{
for (int i = 0; i < num_entries; ++i) //loop that displays everything entered
{ //output
cout<< "Date: " << my_journal[i].date <<endl;
cout<< "Subject: " << my_journal[i].subject <<endl <<endl;
cout<< "Journal Entry: " <<endl << my_journal[i].entry <<endl <<endl;
}
menu();
}
void journal::search()//function to search by subject
{
char query[100]; //Variable to hold the search query
cout<< "What subject would you like to search for?: "; //Prompt user
cout<< endl <<endl;
cin.get(query, 100, '\n'); cin.ignore (100, '\n'); //Read in the query
for (int i = 0; i < num_entries; ++i)
{
if(strcmp(query, my_journal[i].subject) == 0)//Compare..MATCH!
{ //output
cout<< "Date: " << my_journal[i].date <<endl;
cout<< "Subject: " << my_journal[i].subject <<endl <<endl;
cout<< "Journal Entry: " <<endl << my_journal[i].entry <<endl;
cout<< endl;
}
}
menu();
}
void termination()
{
cout<< "Thank you for using the Electronic Journal!" <<endl;
cout<< "Press ENTER to exit! ";
}
|