Good Morning DIC
I recently returned from my vacation to home. While home, I spent some time thinking about my next project. I wanted to create something practical, that I could evolve into something useful. I noticed that my father has his science fiction collection scattered across many shelves, with no rational order made obvious. I also enjoy science fiction, and decided that I should write a program that my father could use to catalog his collection. Tonight I finished the first draft. It is a functioning program, but still requires a good scrub and the addition of features I would like to make available. I would like to share this first draft with you, and allow you to try it if you so wish. It needs some work, but at this phase it represents the idea of what this program is supposed to do. Enjoy, and I will bring you updates as I keep working.
-alias
UI.cpp
includes misc.h
SF_Catalog.rtf (79.48K)
Number of downloads: 101
includes misc.rtf (1.43K)
Number of downloads: 104
I recently returned from my vacation to home. While home, I spent some time thinking about my next project. I wanted to create something practical, that I could evolve into something useful. I noticed that my father has his science fiction collection scattered across many shelves, with no rational order made obvious. I also enjoy science fiction, and decided that I should write a program that my father could use to catalog his collection. Tonight I finished the first draft. It is a functioning program, but still requires a good scrub and the addition of features I would like to make available. I would like to share this first draft with you, and allow you to try it if you so wish. It needs some work, but at this phase it represents the idea of what this program is supposed to do. Enjoy, and I will bring you updates as I keep working.
-alias
UI.cpp
#include"includes misc.h"
using namespace Functions;
using namespace Variables;
class Node
{
string author;
string title;
string date;
friend class Book;
};
class Book
{
private:
fstream obj;
string author;
string title;
int date;
string file_read;
void Title_search();
void Author_search();
void Remove_book(Node &obj);
public:
Book();
Book(int i);
~Book();
void Cat_search();
void Cat_view();
void Cat_add_to();
void Cat_remove();
void Cat_help();
};
Book::Book(int i)
{
author = " ";
title = " ";
date = 0;
switch(i)
{
case 1:
Cat_search();
break;
case 2:
Cat_view();
break;
case 3:
Cat_add_to();
break;
case 4:
Cat_remove();
break;
case 5:
Cat_help();
break;
case 6:
break;
default:
Error("Error: Unknown option.");
}
}
Book::Book()
{
}
Book::~Book()
{
}
void Book::Cat_search()
{
int nav_choice = 0;
Clear_screen();
cout<<"--Search--"<<endl;
cout<<"\nYou can either search by Title, or Author."<<endl;
cout<<"1. Title \n"
<<"2. Author "<<endl;
cout<<"\nChoice: ";
if(!(cin>>nav_choice)) Error("Error: Incorrect Choice.");
switch(nav_choice)
{
case 1:
Title_search();
break;
case 2:
Author_search();
break;
default:
Error("Error: Unknown Option.");
}
}
void Book::Title_search()
{
Clear_screen();
Node obj;
cin.sync();
string t_search = " ";
string c_space = " ";
cout<<"\nPlease enter the Title you are searching for: ";
getline(cin, t_search);
ifstream search("SF_Catalog.doc");
while(search.is_open())
{
getline(search, obj.title);
getline(search, obj.author);
getline(search, obj.date);
getline(search, c_space);
if(obj.title == t_search)
{
cout<<"\nFound match: \n\n"
<< obj.title << endl
<< obj.author << endl
<< obj.date << endl
<< endl;
}
if(search.eof()) break;
}
cout<<"\nPress any key to return to menu..."<<endl;
cin.get();
Clear_screen();
}
void Book::Author_search()
{
Clear_screen();
Node obj;
cin.sync();
string t_search = " ";
string c_space = " ";
cout<<"\nPlease enter the Author you are searching for: ";
getline(cin, t_search);
ifstream search("SF_Catalog.doc");
do
{
getline(search, title);
if(title.size() == 0) break;
obj.title = title;
getline(search, author);
if(author.size() == 0) break;
obj.author = author;
getline(search, obj.date);
getline(search, c_space);
if(obj.author == t_search)
{
cout<<"\nFound match: \n\n"
<< obj.title << endl
<< obj.author << endl
<< obj.date << endl
<< endl;
}
}while(!(search.eof()));
cout<<"\nPress any key to return to menu..."<<endl;
cin.get();
Clear_screen();
}
void Book::Cat_view()
{
Clear_screen();
cout<<"--Full Catalog--\n"<<endl;
ifstream obj("SF_Catalog.doc",ios::out);
while(obj.is_open())
{
getline(obj, file_read);
cout<< file_read <<endl;
if(obj.eof()) break;
}
cout<<"\nPress any key to return to menu..."<<endl;
cin.ignore();
cin.get();
Clear_screen();
}
void Book::Cat_add_to()
{
Clear_screen();
cout<<"--Add Entry--"<<endl;
cin.sync();
cout<<"\nEnter the Title: ";
getline(cin,title);
cout<<"\nEnter the Author: ";
getline(cin,author);
cout<<"\nEnter the Publication Date: ";
cin>>date;
ofstream obj("SF_Catalog.doc",::ios::app); //Change to append or ate file
if(!obj) Error("Error: Could not open file");
obj << title <<endl
<< author << endl
<< date << endl
<< endl;
cout<<"\nEntry made."<<endl;
cout<<"\nPress any key to return to menu..."<<endl;
cin.ignore();
cin.get();
Clear_screen();
}
void Book::Cat_remove()
{
Clear_screen();
cin.sync();
Node obj;
string r_search = " ";
string c_space = " ";
char choice = ' ';
cout<<"--Remove from Catalog--\n"<<endl;
cout<<"You can search for a title to remove, "
<<"please enter your search critera below.\n"<<endl;
cout<<"Title: ";
getline(cin, r_search);
ifstream search("SF_Catalog.doc");
while(search.is_open())
{
getline(search, obj.title);
getline(search, obj.author);
getline(search, obj.date);
getline(search, c_space);
if(obj.title == r_search)
{
cout<<"\nLooking...\n"<<endl;
cout<<"\nFound match: \n\n"
<< obj.title << endl
<< obj.author << endl
<< obj.date << endl
<< endl;
cout<<"\nWas this the Title you wanted to remove?\n"
<<"(y or n): ";
cin >> choice;
switch(choice)
{
case 'y':
Remove_book(obj);
return;
case 'n':
Clear_screen();
break;
default:
Error("Invalid Option");
}
if(choice != 'y' && choice != 'n') Error("Invalid option");
}
if(search.eof()) break;
}
cout<<"\nPress any key to return to menu..."<<endl;
cin.sync();
cin.get();
Clear_screen();
}
void Book::Remove_book(Node &obj)
{
string author = " ";
string title = " ";
string date = " ";
string c_space = " ";
ifstream find("SF_Catalog.doc");
ofstream temp("Temp.doc", ios::ate);
do
{
getline(find, title);
if(title.size() == 0) break;
getline(find, author);
if(author.size() == 0) break;
getline(find, date);
getline(find, c_space);
if(date == obj.date && author == obj.author && title == obj.title)
{
cout<<"\nTitle removed."<<endl;
cin.get();
}
else
{
temp << title <<endl
<< author << endl
<< date << endl
<< c_space <<endl;
}
}while(!(find.eof()));
system("copy Temp.doc SF_Catalog.doc");
temp.close();
system("del Temp.doc");
cout<<"\nPress any key to return to menu..."<<endl;
cin.sync();
cin.get();
Clear_screen();
}
void Book::Cat_help()
{
Clear_screen();
cout<<"--Help--"<<endl;
cout<<"\nIf this is your first time using this program, \n"
<<"here are some tips you might find useful: \n"
<<"\n1. Wherever you have this program saved, \n"
<<"your catalog will appear in the same location.\n"
<<"2. Your catalog will appear after you make your \n"
<<"first entry.\n"
<<"3. Navigate the menu by the number associated \n"
<<"with that option.\n"
<<"4. Entries are made as Title: Author: Date:."
<<endl;
cout<<"\nPress any key to return to menu..."<<endl;
cin.ignore();
cin.get();
Clear_screen();
}
int main()
{
cout<<"Welcome to the Sci-Fi cataloging program."<<endl;
cout<<endl;
cout<<"\nPlease enter your password: ";
while(!(cin>>passtry))
{
Error("Invalid password.");
}
if(passtry != password) Error("Incorrect Password.");
cout<<endl;
cout<<"\nWelcome Sci-fi reader!"<<endl;
cout<<"If this is your first time, choose Help."<<endl;
cout<<"\nPlease press enter to view cataloging mode..."<<endl;
cin.ignore();
cin.get();
Clear_screen();
cout<<"(Please select an option by it's number.)"<<endl;
do
{
cin.sync();
Show_catalog();
cout<<"Navigate to: ";
if(!(cin>>choice)) Error("Error: Unknown option.");
Book obj(choice);
}while(choice != 6);
cout<<"\nThank you for using our program, Goodbye."<<endl;
cout<<endl;
cin.ignore();
cin.get();
return 0;
}
includes misc.h
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include"stdio.h"
using namespace std;
namespace Variables
{
string password = "asimov";
string passtry = " ";
int choice = 0;
}
namespace Functions
{
int Error(string s)
{
cout<< s << ", Goodbye.\n" <<endl;
cin.sync();
cin.get();
exit(1);
}
void Clear_screen()
{
system("CLS");
}
void Show_catalog()
{
cout<<"--Catalog Menu--"<<endl;
cout<<" 1. Search\n"
<<" 2. View all\n"
<<" 3. Add to catalog\n"
<<" 4. Remove from catalog\n"
<<" 5. Help\n"
<<" 6. Quit\n" <<endl;
}
}
SF_Catalog.rtf (79.48K)
Number of downloads: 101
includes misc.rtf (1.43K)
Number of downloads: 104
1 Comments On This Entry
Page 1 of 1
Page 1 of 1
Trackbacks for this entry [ Trackback URL ]
Tags
My Blog Links
Recent Entries
-
-
-
A new project: Sci-Fi Novel Cataloging programon Sep 10 2010 03:32 AM
-
-
Recent Comments
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
|
|



1 Comments










|