Click here to Skip to main content
15,915,019 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: How to provent text selection in CComboBox ? Pin
David Crow7-Feb-11 3:27
David Crow7-Feb-11 3:27 
AnswerRe: How to provent text selection in CComboBox ? Pin
mesajflaviu7-Feb-11 5:06
mesajflaviu7-Feb-11 5:06 
QuestionReading the file that create from "Print to file" option Pin
Max++6-Feb-11 16:09
Max++6-Feb-11 16:09 
AnswerRe: Reading the file that create from "Print to file" option Pin
Andrew Brock6-Feb-11 18:38
Andrew Brock6-Feb-11 18:38 
Questionhello, anyone have an idea of a code in MFC to shut down with time the pc ? in Vs 2008 ? Pin
leech4ever6-Feb-11 13:49
leech4ever6-Feb-11 13:49 
AnswerRe: hello, anyone have an idea of a code in MFC to shut down with time the pc ? in Vs 2008 ? Pin
«_Superman_»6-Feb-11 15:13
professional«_Superman_»6-Feb-11 15:13 
AnswerRe: hello, anyone have an idea of a code in MFC to shut down with time the pc ? in Vs 2008 ? Pin
Andrew Brock6-Feb-11 15:23
Andrew Brock6-Feb-11 15:23 
QuestionHow to make a book provision for multiple authors Pin
Horace Cheng6-Feb-11 11:49
Horace Cheng6-Feb-11 11:49 
I an't figure it out how to make a provision for multiple authors...
Here is my code....



#include <iostream>
#include <string>
#include <vector>

using namespace std;

const string null = "";
//class(1) Book Title
class bkTitle
{
string ATitle;
public:

//construtor
bkTitle();
bkTitle(string);

//Mutator member functions
void setTitle(string Title) {ATitle = Title;}

//accessor funtions
string getTitle() {return ATitle;}

string toString();
};

//Default construtor

bkTitle::bkTitle()
{
ATitle = null;
}
bkTitle::bkTitle(string Title)
{
ATitle = Title;
}
string bkTitle::toString()
{
string Form;

Form = ATitle;
return Form;
}
//Class(2)First define a class to represent names...
class shortName {
string firstName;
string lastName;

public:
//Declare the constructors...

shortName();
shortName(string, string);

//Define the mutator member functions...

void setFirst(string First) { firstName = First;}
void setLast(string Last) { lastName = Last;}

//...and some accessor functions

string getFirst() { return firstName;}
string getLast() { return lastName;}

string toString();

};

//Define the default constructor...

shortName::shortName()
{
firstName = null;
lastName = null;
}

//...and the initializing one...

shortName::shortName(string First, string Last)
{
firstName = First;
lastName = Last;
}

string shortName::toString()
{
string Form;

Form = firstName + " " + lastName;
return Form;
}

//class(3) Publisher Name
class PbName
{
string PbN;

public:
//constructor

PbName();
PbName(string);

//mutator member funtions

void setPb(string Pb) {PbN = Pb;}

//acessor funtions

string getPb() { return PbN;}

string toString();

};

//default constructor
PbName::PbName()
{
PbN = null;
}

//initializing one
PbName::PbName(string Pb)
{
PbN = Pb;
}
string PbName::toString()
{
string Form;

Form = PbN;
return Form;
}


//Class(4)publisher address
class shortAddress {
string StreetID;
string StreetName;
string CityName;
string StateName;
string ZipCode;

public:
//Declare the constructors...

shortAddress();
shortAddress(string, string, string, string, string);

//Define the mutators...

void setID(string ID) { StreetID = ID; }
void setStreet(string Street) {StreetName = Street; }
void setCity(string City) { CityName = City; }
void setState(string State) { StateName = State; }
void setZip(string Zip) { ZipCode = Zip; }

//...and the accesors...

string getID() { return StreetID; }
string getStreet() { return StreetName; }
string getCity() { return CityName; }
string getState() { return StateName; }
string getZip() { return ZipCode; }

string toString();

};

//Define the default constructor...

shortAddress::shortAddress()
{
StreetID = null;
StreetName = null;
CityName = null;
StateName = null;
ZipCode = null;
}


//Define the initializing constructor...
shortAddress::shortAddress(string ID, string Street, string City, string State, string Zip)
{
StreetID = ID;
StreetName = Street;
CityName = City;
StateName = State;
ZipCode = Zip;
}

string shortAddress::toString()
{
string Form;

Form = StreetID + " " + StreetName + "\n" + CityName + ", " + StateName +
" " + ZipCode;
return Form;
}


//Publisher(Phone Number)
class shortPhone {
string AreaCode;
string Prefix;
string Number;

public:
//Declare the constructors...

shortPhone();
shortPhone(string, string, string);

//Define the mutators...

void setArea(string Area) { AreaCode = Area; }
void setPrefix(string Pref) { Prefix = Pref; }
void setNumber(string Num) { Number = Num; }

//...and the accesors...

string getArea() { return AreaCode; }
string getPrefix() { return Prefix; }
string getNumber() { return Number; }

string toString();

};

//Define the default constructor...

shortPhone::shortPhone()
{
AreaCode = null;
Prefix = null;
Number = null;
}


//Define the initializing one...

shortPhone::shortPhone(string Area, string Pre, string Num)
{
AreaCode = Area;
Prefix = Pre;
Number = Num;
}

string shortPhone::toString()
{
string Form;

Form = "(" + AreaCode +") " + Prefix + "-" + Number;
return Form;
}


//class(5) Catagory
class bkCategory
{
string bkCa;

public:
//constructor
bkCategory();
bkCategory(string);

//mutator member funtions
void setCa(string Ca) {bkCa = Ca;}

//acessor funtions
string getCa() { return bkCa;}
string toString();

};

//default constructor
bkCategory::bkCategory()
{
bkCa = null;
}
//initializing one
bkCategory::bkCategory(string Ca)
{
bkCa = Ca;
}

string bkCategory::toString()
{
string Form;

Form = bkCa;
return Form;
}



//class(6) Date of Publication
class DateofPublication
{
string TDop;

public:
//constructor

DateofPublication();
DateofPublication(string);

//mutator member funtions

void setDop(string Dop) {TDop = Dop;}

//acessor funtions

string getDop() { return TDop;}

string toString();

};

//default constructor
DateofPublication::DateofPublication()
{
TDop = null;
}
//initializing one
DateofPublication::DateofPublication(string Dop)
{
TDop = Dop;
}
string DateofPublication::toString()
{
string Form;

Form = TDop;
return Form;
}


// Class(7) For The Information Of Books In The Library
class BookRecord
{
bkTitle Titlebk;
shortName AuthorName;
PbName PublisherName;
shortAddress PublisherAddress;
shortPhone PublisherPhone;
bkCategory Category;
DateofPublication bkDop;

public:
// Define Constructors
BookRecord();

BookRecord (bkTitle, shortName, PbName, shortAddress, shortPhone, bkCategory, DateofPublication);


// Define Mutators
BookRecord(string, string, string, string, string, string, string,
string, string, string, string, string, string, string);

//Define some mutators...

//Title
void setTitle(string Title) { Titlebk.setTitle(Title); }

//Author Name
void setFirst(string First) { AuthorName.setFirst(First); }
void setLast(string Last) { AuthorName.setLast(Last); }

//Publisher Name
void setPb(string Pb) { PublisherName.setPb(Pb); }

//Publisher Address
void setID(string ID) { PublisherAddress.setID(ID); }
void setStreet(string Street) { PublisherAddress.setStreet(Street); }
void setCity(string City) { PublisherAddress.setCity(City); }
void setState(string State) { PublisherAddress.setState(State); }
void setZip(string Zip) { PublisherAddress.setZip(Zip); }

//Publisher Phone Number
void setArea(string Area) { PublisherPhone.setArea(Area); }
void setPrefix(string Prefix) { PublisherPhone.setPrefix(Prefix); }
void setNumber(string Number) { PublisherPhone.setNumber(Number); }

//Book Category
void setCa(string Ca) { Category.setCa(Ca); }

//Date of Publication
void setDop(string Dop) { bkDop.setDop(Dop); }

//Define appropriate accessors...

//Title
string getTitle() { return Titlebk.getTitle(); }

//Author Name
string getFirst() { return AuthorName.getFirst(); }
string getLast() { return AuthorName.getLast(); }

//Publisher Name
string getPb() { return PublisherName.getPb(); }

//Publisher address...
string getID() { return PublisherAddress.getID(); }
string getStreet() { return PublisherAddress.getStreet(); }
string getCity() { return PublisherAddress.getCity(); }
string getState() { return PublisherAddress.getState(); }
string getZip() { return PublisherAddress.getZip(); }

//Publisher Phone
string getArea() { return PublisherPhone.getArea(); }
string getPrefix() { return PublisherPhone.getPrefix(); }
string getNumber() { return PublisherPhone.getNumber(); }

//Category
string getCa() { return Category.getCa(); }

//Date of Publiation
string getDop() { return bkDop.getDop(); }

// conversion Function
string toString();
};

BookRecord::BookRecord()
{
; //This is a command...that doesn't do anything....
}

//We can use an initializing constructor for the times when
// we have the values before we create the object...

//Initializing Constructor
BookRecord::BookRecord(bkTitle ClientTitle,shortName ClientName,PbName ClientPublisherName,
shortAddress ClientPublisherAddress,shortPhone ClientPublisherPhone,bkCategory ClientCategory,DateofPublication ClientbkDop)
{
Titlebk = ClientTitle;
AuthorName = ClientName;
PublisherName = ClientPublisherName;
PublisherAddress = ClientPublisherAddress;
PublisherPhone = ClientPublisherPhone;
Category = ClientCategory;
bkDop = ClientbkDop;
}

//This alternative initializing constructor can be
// used in different context...
BookRecord::BookRecord(string Title, string First, string Last, string Pb, string ID, string Street,
string City, string State, string Zip, string Area,
string Prefix, string Number, string Ca, string Dop)
{
Titlebk.setTitle(Title);

AuthorName.setFirst(First); //We have to use the mutators because the
AuthorName.setLast(Last); //components are locked away in classes...

PublisherName.setPb(Pb);

PublisherAddress.setID(ID);
PublisherAddress.setStreet(Street);
PublisherAddress.setCity(City);
PublisherAddress.setState(State);
PublisherAddress.setZip(Zip);

PublisherPhone.setArea(Area);
PublisherPhone.setPrefix(Prefix);
PublisherPhone.setNumber(Number);

Category.setCa(Ca);

bkDop.setDop(Dop);
}

// Output The Information Of Books
string BookRecord::toString()
{
string Form;

Form= "\n==============================\nTitle: " +
Titlebk.toString() + "\nAuthor: " +
AuthorName.toString() + "\nPublisher Name: " +
PublisherName.toString() + "\nPublisher address:" +
PublisherAddress.toString() + "\nPublisher Phone Number and Contact Name:" +
PublisherPhone.toString() + "\nCategory: " +
Category.toString() + "\nDate of Publication: " +
bkDop.toString() + "\n" +
"==============================\n";

return Form;
}

//The next task is to package the list processing functions in a class...
const BookRecord NullRecord; //We'll need this object later...

// class(8) For books In The Library
class BookRecordList
{ vector<BookRecord> List; //We need to create a collection object...

public:
BookRecordList() {;} //Right now the default constructor doesn't do much...

void AddBookRecord(BookRecord);
BookRecord FindBookRecord(string);
BookRecord SearchBookRecord(string);
bool RemoveBookRecord(string);
string DisplayAllBookRecords();
};

//The add function is probably the easiest to implement...all the work was
// done in the other definitions...

void BookRecordList::AddBookRecord(BookRecord NewBookRecord)// Add book
{
List.push_back(NewBookRecord);
}

BookRecord BookRecordList::FindBookRecord(string Last)// Search by Author Last Name
{
vector<BookRecord>::iterator FindList; //Define a smart pointer that will take us through the vector..

for(FindList = List.begin() ; FindList != List.end() ; FindList++)
if(FindList->getLast() == Last)
return *FindList; //If we have a match, send back the matching record...


return NullRecord; //We only get here when the entire list was traversed and there's no match.
}

BookRecord BookRecordList::SearchBookRecord(string Pb) // Search by A Title
{
vector<BookRecord>::iterator SearchList; //Define a smart pointer that will take us through the vector..

for(SearchList = List.begin() ; SearchList != List.end() ; SearchList++)
if(SearchList->getPb() == Pb)
return *SearchList;
return NullRecord;
}

bool BookRecordList::RemoveBookRecord(string Title)
{
vector<BookRecord>::iterator RemoveList;

for(RemoveList = List.begin() ; RemoveList != List.end() ; RemoveList++)
if(RemoveList->getLast() == Title) {
List.erase(RemoveList); //If we have a match, it's remove from the vector...
return true; //Let the calling function know it was successful...
}

return false; //The only way it gets here is that there was no match...the calling
//function needs to know that as well...
}

//The removal function is also traditionalist...we search for the correct one using the last name
//and then we remove it...

string BookRecordList::DisplayAllBookRecords()
{
vector<BookRecord>::iterator OutputList; //a smart pointer will take us through the vector...

string OutputForm;

for(OutputList = List.begin() ; OutputList != List.end() ; OutputList++) {
OutputForm += "======================================\n" + //Keep extending the string until you
OutputList->toString() +
"=======================================\n";
}

return OutputForm;
}

//Class(9)Create a BookList Interface Class
class BookRecordListUI {
BookRecordList Collection; //Create a object that contains a list...

public:
BookRecordListUI() {;} //Still not much for this to do...

void Menu();
void CommandProcessor();

void AddBookRecords();
void RemoveBookRecords();
void SearchbyAuthorLastName();
void SearchbyPublisherName();
void DisplayBookRecords();
};

void BookRecordListUI::CommandProcessor()
{
string Command;

while(true)
{
Menu();

cout << "Command: ";
getline(cin, Command);

if(Command == "Quit" || Command == "q")
break;

else if(Command == "Add Book" || Command == "1")
AddBookRecords();
else if(Command == "Remove a Book" || Command == "2")
RemoveBookRecords();
else if(Command == "Find By The Author Last Name" || Command == "3")
SearchbyAuthorLastName();
else if(Command == "Find By The Publisher Name" || Command == "4")
SearchbyPublisherName();
else if(Command == "Display" || Command == "5")
DisplayBookRecords();
}
}

void BookRecordListUI::Menu()
{
cout << "\nWelcome To Horace Library!" << endl;
cout << "\t1.Add A Book(puts a new book in the collection)" << endl;
cout << "\t2.Remove A Book(remove book from the collection)" << endl;
cout << "\t3.Searh By The Author Last Name(searches the collection for a book that matches the specified Author Last Name)" << endl;
cout << "\t4.Searh By The Publisher Name(searches the collection for a book that matches the specified Publisher Name)" << endl;
cout << "\t5.Display(shows the entire collection)" << endl;
}

void BookRecordListUI::AddBookRecords()
{
BookRecord LocalRecord;
string Title;
string First, Last;
string Pb;
string ID, Street,City, State,Zip;
string Area, Prefix, Number;
string Ca;
string Dop;

cout << "Enter Values Below, Type q To Quit" << endl;

while(true) {
cout << "Title: ";
getline(cin, Title);
if(Title == "q") break;

LocalRecord.setTitle(Title);

cout << "Enter Name..." << endl;
cout << "First: ";
getline(cin, First);
if(First == "q") break;

cout << "Last: ";
getline(cin, Last);
if(Last == "q") break;

LocalRecord.setFirst(First); //Set the name
LocalRecord.setLast(Last);

cout << "Publisher Name: ";
getline(cin, Pb);
if(Pb == "q") break;

LocalRecord.setPb(Pb);

cout << "Enter Address..." << endl;
cout << "Street Number: ";
getline(cin, ID);
if(ID == "q") break;

cout << "Street Name: ";
getline(cin, Street);
if(Street == "q") break;

cout << "City: ";
getline(cin, City);
if(City == "q") break;

cout << "State: ";
getline(cin, State);
if(State == "q") break;

cout << "Zip Code: ";
getline(cin, Zip);
if(Zip == "q") break;

LocalRecord.setID(ID); //...and the address...
LocalRecord.setStreet(Street);
LocalRecord.setCity(City);
LocalRecord.setState(State);
LocalRecord.setZip(Zip);

cout << "Enter Telephone Number..." << endl;
cout << "Area Code: ";
getline(cin, Area);
if(Area == "q") break;

cout << "Prefix: ";
getline(cin, Prefix);
if(Prefix == "q") break;

cout << "Number(please indicate the contact name after the number): ";
getline(cin, Number);
if(Number == "q") break;

LocalRecord.setArea(Area); //...and finally the telephone number...
LocalRecord.setPrefix(Prefix);
LocalRecord.setNumber(Number);

cout << "Book Category: ";
getline(cin, Ca);
if(Ca == "q") break;

LocalRecord.setCa(Ca);

cout << "Date of Publication: ";
getline(cin, Dop);
if(Dop == "q") break;

LocalRecord.setDop(Dop);

Collection.AddBookRecord(LocalRecord); //put it on the list...
}
}

//This function allows the user to look for names on the list...

void BookRecordListUI::SearchbyAuthorLastName()
{
BookRecord LocalRecord;
string Last;

cout << "Enter Author Last Name Below, Type q To Quit" << endl;

while(true) {
cout << "Author Last Name: ";
getline(cin, Last);
if(Last == "q") //Indicates the user is done...
break;

LocalRecord = Collection.FindBookRecord(Last); //Collect the results
if(LocalRecord.getLast() == null) //Didn't find it
cout << "Book Not Found" << endl;
else
cout << LocalRecord.toString(); //Otherwise, show the record...
}
}
void BookRecordListUI::SearchbyPublisherName()
{
BookRecord LocalRecord;
string Pb;

cout << "Enter Author Last Name Below, Type q To Quit" << endl;

while(true) {
cout << "Publisher Name: ";
getline(cin, Pb);
if(Pb == "q") //Indicates the user is done...
break;

LocalRecord = Collection.FindBookRecord(Pb); //Collect the results
if(LocalRecord.getPb() == null) //Didn't find it
cout << "Book Not Found" << endl;
else
cout << LocalRecord.toString(); //Otherwise, show the record...
}
}

void BookRecordListUI::RemoveBookRecords() // Function 3
{
BookRecord LocalRecord;
string Title;

cout << "Enter The Title Below, Type q To Quit" << endl;

while(true)
{
cout << "Title: ";
getline(cin, Title);
if(Title == "q")
break;

if(Collection.RemoveBookRecord(Title))
cout << Title << " Removed" << endl;
else
cout << Title << " Not Found!" << endl;

}
}
void BookRecordListUI::DisplayBookRecords()
{
cout << "=======================================================" << endl;
cout << Collection.DisplayAllBookRecords();
cout << "=======================================================" << endl;
}

//Notice how small the main() has shrunk...

int main()
{
BookRecordListUI Members; //Create a UI object...
Members.CommandProcessor(); //Set it in motion...
}
AnswerRe: How to make a book provision for multiple authors Pin
Maximilien6-Feb-11 17:11
Maximilien6-Feb-11 17:11 
AnswerRe: How to make a book provision for multiple authors Pin
Richard MacCutchan6-Feb-11 22:08
mveRichard MacCutchan6-Feb-11 22:08 
QuestionBluetooth socket programming Pin
Pranit Kothari6-Feb-11 7:05
Pranit Kothari6-Feb-11 7:05 
AnswerRe: Bluetooth socket programming Pin
Cool_Dev6-Feb-11 18:12
Cool_Dev6-Feb-11 18:12 
GeneralRe: Bluetooth socket programming Pin
Pranit Kothari6-Feb-11 18:29
Pranit Kothari6-Feb-11 18:29 
AnswerRe: Bluetooth socket programming Pin
Andrew Brock6-Feb-11 18:43
Andrew Brock6-Feb-11 18:43 
RantRe: Bluetooth socket programming Pin
Pranit Kothari6-Feb-11 18:49
Pranit Kothari6-Feb-11 18:49 
AnswerRe: Bluetooth socket programming Pin
8140320-Apr-11 1:40
8140320-Apr-11 1:40 
QuestionHow to block URL Pin
Pranit Kothari6-Feb-11 6:57
Pranit Kothari6-Feb-11 6:57 
AnswerRe: How to block URL Pin
csrss6-Feb-11 8:24
csrss6-Feb-11 8:24 
QuestionRe: How to block URL Pin
Pranit Kothari6-Feb-11 17:13
Pranit Kothari6-Feb-11 17:13 
AnswerRe: How to block URL Pin
David Crow7-Feb-11 3:31
David Crow7-Feb-11 3:31 
AnswerRe: How to block URL Pin
Rolf Kristensen6-Feb-11 9:11
Rolf Kristensen6-Feb-11 9:11 
GeneralRe: How to block URL Pin
Pranit Kothari6-Feb-11 17:15
Pranit Kothari6-Feb-11 17:15 
GeneralRe: How to block URL Pin
Rolf Kristensen6-Feb-11 20:11
Rolf Kristensen6-Feb-11 20:11 
GeneralRe: How to block URL Pin
Emilio Garavaglia6-Feb-11 20:14
Emilio Garavaglia6-Feb-11 20:14 
QuestionAccessing physical memory under Windows XP Pin
normanS5-Feb-11 21:40
normanS5-Feb-11 21:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.