Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ##################################
- // ## ISBN ##
- // ## Uebung 3 ##
- // ## Beispiel 4 ##
- // ## Etzlstorfer Simon ##
- // ## Rev 1.0 ##
- // ##################################
- /* Lösungsidee:
- * ISBN einlesen
- * erste Ziffer via 10^i erste Zahl an erste Stelle im Array schreiben
- * i-1 ... bis letzte ziffer im array ist.
- * Prüfziffer errechnen.
- * ISBN formatiert ausgeben.
- */
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main (){
- int isbn[9];
- int in = 0;
- int i = 0;
- int hoch = 8;
- int x = 0;
- int pruf = 0;
- cout << "ISBN ohne Prüfziffer eingeben: ";
- cin >> in;
- cout << endl;
- if (in < 100000000 || in > 999999999){
- cout << "ISBN falsch" << endl;
- }else{
- while ( i <= 8 ){
- isbn[i] = in / pow(10, hoch);
- in = in - (isbn[i] * pow(10, hoch));
- hoch --;
- i ++;
- }
- i = 0;
- while ( i <= 8){
- x = x + (isbn[i]*(i+1));
- i ++;
- }
- pruf = x%11;
- i = 0;
- cout << "ISBN: ";
- while( i <= 8 ){
- cout << isbn[i];
- if (i == 0 || i == 3 ){
- cout << "-";
- }
- i ++;
- }
- if ( pruf < 10){
- cout << "-" << pruf << endl;
- }else{
- cout << "-" << "X" << endl;
- }
- }
- }
- /*
- * Testfälle:
- * ISBN ohne Prüfziffer eingeben: 344621367
- *
- * ISBN: 3-446-21367-8
- * -------------------------------------------
- * ISBN ohne Prüfziffer eingeben: 349913599
- *
- * ISBN: 3-499-13599-X
- * -------------------------------------------
- * ISBN ohne Prüfziffer eingeben: 123456789
- *
- * ISBN: 1-234-56789-X
- * -------------------------------------------
- * ISBN ohne Prüfziffer eingeben: 12345678
- *
- * ISBN falsch
- * -------------------------------------------
- * ISBN ohne Prüfziffer eingeben: 1234567891
- *
- * ISBN falsch
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement