An ISBN (International Standard Book Number) identifies a unique publication. An ISBN is ten digits. The first nine digits must be decimal digits (0...9). The tenth may a decimal digit or the letter X, according to the checksum, discussed below. Three single dashes may be between any of the characters, but an ISBN must not begin or end with a dash.

Some example ISBNs:

0-201-88337-6
0-13-117334-0
0821211315 (no dashes ok)
1-57231-866-X

The last character of an ISBN number is a checksum. The checksum is the determined by the first 9 digits; it is computed by taking modulo 11 (the remainder after dividing by 11) of the sum of each digit multiplied by its position in the ISBN. The letter X corresponds to a value of 10.

Here are two ISBNs and the calculations that show how the check sum is determined:

0-201-88337-6 -> (0*1 + 2*2 + 0*3 + 1*4 + 8*5 + 8*6 + 3*7 + 3*8 + 7*9) mod 11 = 6
1-57231-866-X -> (1*1 + 5*2 + 7*3 + 2*4 + 3*5 + 1*6 + 8*7 + 6*8 + 6*9) mod 11 = 10 (X)

For more info, check out:
www.isbn.org
www.amazon.com Try a book search by ISBN

Some invalid ISBNs:

0-201-8A337-6 (bad digit)
0-201-88337-63 (too many digits)
0-201-88-337-6 (too many dashes)
0-201883376 (not enough dashes)
0-201-88337-3 (wrong check sum)
-013-117334-0 (beginning or ending dash)
157231--866-X (sequential dashes)
013-1134-0 (too few digits)

Write a menu driven program that will verify ISBNs either from user input or from file input (use default filename = isbntest.txt). The file format should be:

integer value that specifies the number of ISBN's to follow (max of 20),

ISBN,              (one ISBN per line)

ISBN, etc.

Example data file:

6

0-201-88337-6

0-13-117334-0

157231--866-X

-013-117334-0

0821211315

1-57231-866-X

can somebody simplify for me what the problem is and some advise to solve it because of my English, I don't really know what itreally means.thank you

Write a parsing program (something that splits a bigger data type ie. a ISBN number to a more manageable datatype ie. an array of char[]). Load in the ISBN number from the file, and make sure it doesn't contain more than 3 dashes (-), that it only contains numbers (other than dashes and possible X checksum value) and that it doesn't start or end with a dash. Then, if all those checks pass, make sure the final digit is the proper checksum (using the method you described). I'm not sure how much clearer this can be made!

Ok, The programm has to read a string to an array, check if there is no more then 3 deshis, check if first 9 characters excluding the deshis are numbers, make shure there is 9 numbers and the 10th digit is eather a number or "x", after then multiplay firs 9 mumerical didgit by its position, and add the result, now the result devide by 11 and get reminder, it should be equal to the last 10th digit of the number.. if reminder is 10 the 10th digit will suppost to be 'X', if all of thous conditions are true, the number is correct, the other way it is incorrect

hope this helps, if not ask further

Ok, The programm has to read a string to an array, check if there is no more then 3 deshis, check if first 9 characters excluding the deshis are numbers, make shure there is 9 numbers and the 10th digit is eather a number or "x", after then multiplay firs 9 mumerical didgit by its position, and add the result, now the result devide by 11 and get reminder, it should be equal to the last 10th digit of the number.. if reminder is 10 the 10th digit will suppost to be 'X', if all of thous conditions are true, the number is correct, the other way it is incorrect

hope this helps, if not ask further

I don't think your spelling is going to help his understanding of English much better >.<

yes i do have problems with the spelling in English, but didn't you understand what i was trying to say ?

yes i do have problems with the spelling in English, but didn't you understand what i was trying to say ?

Yes, but he may need to translate words, and incorrect spelling will give him nothing but grief.

Write a parsing program (something that splits a bigger data type ie. a ISBN number to a more manageable datatype ie. an array of char[]). Load in the ISBN number from the file, and make sure it doesn't contain more than 3 dashes (-), that it only contains numbers (other than dashes and possible X checksum value) and that it doesn't start or end with a dash. Then, if all those checks pass, make sure the final digit is the proper checksum (using the method you described). I'm not sure how much clearer this can be made!

hmmm well have a function similar to this (im not going to right main or any declarations)

bool Parse(char const * szString)
{
bool bFail(false), bWasDash(false);
int checksum(0), realchksum(0), dashes(0);
for (int i(0); i < strlen(szString); i++)
{
    if (szString[i] != '-')
        bWasDash = false;
    if (isdigit(szString[i]))
      checksum += szString[i] - 30; //numbers start at 30 on ascii chart
    else if (i == strlen(szString) && tolower(szString[i]) == 'x')
      realchksum = 10;
    else if (i == strlen(szString) && isdigit(szString[i]))
      realchksum = szString[i] - 30;
    else if (((i == 0 || i == strlen(szString) || bWasDash) && szString[i] == '-') || isalpha(szString[i])) 
    {
       bFail = true;
       break;
    }
     else if (szString[i] = ='-')
    {
        bWasDash = true;
        dashes++;
     }
     //add more checks here i dont know/care if i got them all
}

//now check the checksum
if (checksum != realchksum)
   bFail = true;
return bFail;  //returns true if its a bad number
}

I don't know if this will actually run, i didnt compile it. And it probably doesn't cover all of the checks. And you'll have to figuire out the file i/o part - since that's pretty elementary. I really don't like writing whole functions for people, but since you don't understand english very well, maybe you'll understand code better.

Here is a pretty crappy version of a more dynamic solution. It would make more sense to make the array internal to the class, but it still demonstrates my point

#include<iostream>
using namespace std;


class Numbers
{
	int iValue;
	int iCount;
public:
	inline bool bExists (Numbers * numarray, int iSize, int iVal)
	{
		for (int i(0); i < iSize; i++)
			if (numarray[i].iValue == iVal)
				return true;
		return false;
	}
	inline int GetCount (Numbers * numarray, int iSize, int iVal)
	{
		for (int i(0); i < iSize; i++)
			if (numarray[i].iValue == iVal)
				iCount++;
		return iCount;
	}
	inline int GetIndex (Numbers * numarray, int iSize, int iVal)
	{
		for (int i(0); i < iSize; i++)
			if (numarray[i].iValue == iVal)
				return i;
		return -1;
	}
	inline void AddNum (Numbers * numarray, int iSize, int iVal)
	{
		if (!bExists(numarray, iSize, iVal))
			numarray[GetFreeSpot(numarray, iSize)].iValue = iVal;
		else
			numarray[GetIndex(numarray, iSize, iVal)].iCount++;
	}
	inline int GetFreeSpot(Numbers * numarray, int iSize)
	{
		return GetIndex(numarray, iSize, 0);
	}
	inline int GetNum () 
	{
		return iValue;
	}
	Numbers(void): iValue(0), iCount(0) {}
	~Numbers(void) {};
};
int main()
{
	Numbers * pNums;
	int iSize(0);
	int iNum(0);
	cout << "Enter array size: ";
	cin >> iSize;
	pNums = new Numbers [iSize];
	//load in the values
	for (int i(0); i < iSize; i++)
	{
		cout << "\nValue " << i + 1 << ": ";
		cin >> iNum;
		pNums[i].AddNum(pNums, iSize, iNum);
	}
	for (int i(0); i < iSize; i++)
	{
		if (pNums[i].GetNum())
			cout << "Number: " << pNums[i].GetNum() << " " << "Count: " << pNums[i].GetCount(pNums, iSize, pNums[i].GetNum()) << endl; 
	}
	cin.ignore(cin.rdbuf()->in_avail());
	cin.get();
                delete [] pNums;
	return 0;
}

Note that this won't count zeros, considering them null values

This article has been dead for over six months. Start a new discussion instead.