Guest User

ISBNPrefix.cpp

a guest
Oct 5th, 2010
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include "ISBNPrefix.h"
  6. #include "ISBN.h"
  7.  
  8. using namespace std;
  9.  
  10. int isValid(const char str[]){
  11.     int length=0, run=0, a, b, checkint=0, hold, total=0;
  12.     string check;
  13.    
  14.     cout << str << endl;
  15.     length=strlen(str);
  16.     cout << length << endl;
  17.     if(length==10)
  18.         run=0;
  19.    
  20.     if(run==0){
  21.         check=str;
  22.         if(str[9]=='x'){
  23.             b=10;
  24.             cout << "check with x: " << check << endl;
  25.             for(a=8;a>=0;a--){
  26.                 hold = (int)check[a];
  27.                 hold = hold * b;
  28.                 total = total + hold;
  29.                 b--;
  30.             }
  31.             total = total + 10;
  32.             if(total%11!=0)
  33.                 run=1;
  34.         }
  35.         else{
  36.             b=10;
  37.             checkint = atoi (check.c_str());
  38.             cout << "At x: " << check << endl;
  39.             for(a=0;a<=8;a++){
  40.                 hold = (check[a] - '0');
  41.                 cout << "THIS IS HOLD" << hold << endl;
  42.                 hold = (hold*b);
  43.                 cout << "THIS IS HOLD AFTER MULTIPLYING" << hold << endl;
  44.                 total = total + hold;
  45.                 cout << "THIS IS TOTAL" << total << endl;
  46.                 b--;
  47.             }
  48.             total = total + (check[a]-'0');
  49.             cout << "THIS IS TOTAL" << total << endl;
  50.             if(total%11!=0)
  51.                 run=1;
  52.         }
  53.        
  54.     }
  55.     cout << "THIS IS RUN AT THE END: " << run << endl; 
  56.     if(run!=0)     
  57.         return 0;
  58.     else
  59.         return 1;
  60.        
  61. }
  62.        
  63.  
  64. int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[]){
  65.     int intarea, finished=0, a, length=1, check=1, valid, titlelength, areavalid, publishervalid, truth=1;
  66.     char compare[80], hold[80], holdtwo[80];
  67.     cout << "IN ISREGISTERED" << endl;
  68.     valid=isValid(str);
  69.     cout << "THIS IS VALID" << endl;
  70. if(valid==1){
  71.     cout << "INSIDE VALID" << endl;
  72.     while(finished==0){
  73.         cout << "IN WHILE IN REGISTERED" << endl;
  74.         for(a=0;a<length;a++)
  75.             compare[a]=str[a];
  76.        
  77.         compare[a+1]='\0';
  78.         cout << "THIS IS COMPARE: " << compare << endl;
  79.         intarea = atoi (compare);
  80.         cout << "THIS IS INTAREA: " << intarea << endl;
  81.         truth=registeredArea(fp, intarea);
  82.         if(truth==0){
  83.             finished=1;
  84.             area=compare;
  85.             areavalid=0;
  86.         }
  87.         else if(truth==1){
  88.             areavalid=1;
  89.             if(length < 6)
  90.                 length++;
  91.             else if(length > 5)
  92.                 finished=1;
  93.         }
  94.     }
  95.     finished=0;
  96.     truth=0;
  97.     while(finished==0){
  98.        
  99.         if(check < 10)
  100.             cout << "IN SECOND WHILE" << endl;
  101.    
  102.         for(a=0;a<check;a++)
  103.             holdtwo[a]=str[a+length];
  104.        
  105.        
  106.         holdtwo[check]='\0';
  107.         for(a=0;a<2;a++)
  108.             cout << holdtwo[a] << endl;
  109.        
  110.         truth=registeredAP(fp, intarea, holdtwo);
  111.         if(truth==0){
  112.             finished=1;
  113.             publisher=holdtwo;
  114.             publishervalid=0;
  115.         }
  116.         else if(truth==1)
  117.             publishervalid=1;
  118.    
  119.             check++;
  120.     }
  121.     length=check+length;
  122.     titlelength=(9-length);
  123.     for(a=0;a<titlelength;a++)
  124.         title[a]=str[length];
  125.    
  126.    
  127.     }
  128.     if(areavalid==0 && publishervalid==0)
  129.         return 0;
  130.     else
  131.         return 1;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment