Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. //  ##################################
  2. //  ##  ISBN                        ##
  3. //  ##  Uebung 3                    ## 
  4. //  ##  Beispiel 4                  ##
  5. //  ##  Etzlstorfer Simon           ##
  6. //  ##  Rev 1.0                     ##
  7. //  ##################################
  8.  
  9. /* Lösungsidee:
  10.  * ISBN einlesen
  11.  * erste Ziffer via 10^i erste Zahl an erste Stelle im Array schreiben
  12.  * i-1 ... bis letzte ziffer im array ist.
  13.  * Prüfziffer errechnen.
  14.  * ISBN formatiert ausgeben.
  15. */
  16. #include <iostream>
  17. #include <cmath>
  18. using namespace std;
  19. int main (){
  20.     int isbn[9];
  21.     int in = 0;
  22.     int i = 0;
  23.     int hoch = 8;
  24.     int x = 0;
  25.     int pruf = 0;
  26.     cout << "ISBN ohne Prüfziffer eingeben: ";
  27.     cin >> in;
  28.     cout << endl;
  29.     if (in < 100000000 || in > 999999999){
  30.         cout << "ISBN falsch" << endl;
  31.     }else{
  32.         while ( i <= 8 ){
  33.             isbn[i] = in / pow(10, hoch);
  34.             in = in - (isbn[i] * pow(10, hoch));
  35.             hoch --;
  36.             i ++;
  37.         }
  38.         i = 0;
  39.         while ( i <= 8){
  40.             x = x + (isbn[i]*(i+1));
  41.             i ++;
  42.         }
  43.         pruf = x%11;
  44.         i = 0;
  45.         cout << "ISBN: ";
  46.         while( i <= 8 ){
  47.             cout << isbn[i];
  48.             if (i == 0 || i == 3 ){
  49.                 cout << "-";
  50.             }
  51.             i ++;
  52.         }
  53.         if ( pruf < 10){
  54.             cout << "-" << pruf << endl;
  55.         }else{
  56.             cout << "-" << "X" << endl;
  57.         }
  58.     }
  59. }
  60.  
  61. /*
  62.  * Testfälle:
  63.  * ISBN ohne Prüfziffer eingeben: 344621367
  64.  *
  65.  * ISBN: 3-446-21367-8
  66.  * -------------------------------------------
  67.  * ISBN ohne Prüfziffer eingeben: 349913599
  68.  *
  69.  * ISBN: 3-499-13599-X
  70.  * -------------------------------------------
  71.  * ISBN ohne Prüfziffer eingeben: 123456789
  72.  *
  73.  * ISBN: 1-234-56789-X
  74.  * -------------------------------------------
  75.  * ISBN ohne Prüfziffer eingeben: 12345678
  76.  *
  77.  * ISBN falsch
  78.  * -------------------------------------------
  79.  * ISBN ohne Prüfziffer eingeben: 1234567891
  80.  *
  81.  * ISBN falsch
  82. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement