C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 5th, 2008, 09:22 PM
!makes_sense !makes_sense is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 !makes_sense User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 33 sec
Reputation Power: 0
General - ISBN Validation program

Greetings to all members,

I have to write a C++ program which requires that user enters ISBN and the program validates it.

The ISBN can be 13 characters long or 10 characters long to be valid in the first place.

I have implemented a check for the length of these isbn by declaring the isbn as string data type and checking their lengths.

Another major part of the validation program is to determine the checksum.

The tenth digit in the isbn is the checksum which is calculated by first multiplying all the 9 digits by their respective positions in the string and then adding them altogether. Finally, taking the modulus of the sum by 11.

What I do not know is how to implement this checksum. I think that I have to convert the each string character to integer and then do the arithmetic.

But how do I do that. What are the commands for converting string characters to respective integers.

Finally, how do I check that the user has not enter a bad digit such as

0821A11315

when it should be 0821211315 and how to check for sequential dashes such as 157231--866-x.



Any thoughts on how to solve these problems.

Thank you.

Reply With Quote
  #2  
Old May 7th, 2008, 04:01 AM
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 338 MaHuJa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 13 m 10 sec
Reputation Power: 1
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
First of all, you need to figure out how to address each char.
Given
string isbn; cin >> isbn;
then you can access the first character of the user input by isbn[0] the second by isbn[1] and so on, up to isbn[isbn.size()-1].

Once you do that you have the char value, which can be fed to functions like isdigit(), compared to '-', or be "converted" to its (ascii, usually) numeral value (Warning! '1' != 1) by storing it to an int. If you need the numeral value, you can either use lexical_cast from the boost libraries, use atoi() in some fashion, or perhaps make your own function. Note that a switch(c) { case '1': return 1; ...} is probably the only way that is truly portable, without assuming that the ascii charset is used.

These tools should be enough to do what you need to.

Reply With Quote
  #3  
Old May 7th, 2008, 09:08 PM
!makes_sense !makes_sense is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 !makes_sense User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 33 sec
Reputation Power: 0
Thanks for the input.

I know how to access the string characters but I don't know how to do isdigit (), compare to '-';

Can you be more specific how to do these?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - ISBN Validation program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway