| | |
Array and data type help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 101
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
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!
Last edited by skatamatic; Oct 27th, 2008 at 1:13 am.
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 0
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
hope this helps, if not ask further
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
•
•
•
•
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
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
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)
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.
hmmm well have a function similar to this (im not going to right main or any declarations)
C++ Syntax (Toggle Plain Text)
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.
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
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
Note that this won't count zeros, considering them null values
C++ Syntax (Toggle Plain Text)
#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
Last edited by skatamatic; Oct 28th, 2008 at 9:44 pm.
![]() |
Similar Threads
- How to check data type (Visual Basic 4 / 5 / 6)
- How do I convert a vector to a String array ? (Java)
- help understanding "char" data type (C++)
- Combined data type arrays. (C++)
- need halp passing array data (C#)
- Array or String Comparing Assignment (C++)
- C++ Data Types (C++)
- twenty integers in an array (Java)
- Need Help counting Array Length (C++)
- accessing private data members (C++)
Other Threads in the C++ Forum
- Previous Thread: how to parse lines from a text file?
- Next Thread: How to display numbers from an input file and count each one's occurence
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





