Trying to return a code

I am trying to figure out why I end up with this error when compiling a code. It says that the 'publisher' is undeclared.
I edited out one part of the code because it involves getting this correct. The function involves a pointer, so I know it needs to see what's in the address in order to return it. should I be using the new operator or this operator. The issue is with the char *getpublisher() function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef ISBN_H
#define ISBN_H

#include <iostream>
#include <cstring>

using namespace std;

class ISBN {
private:
	char group[6];                          // group code is 1-5 digits
	char publisher[8];                      // publisher code is 1-7 digits
	char book[8];                           // book code is 1-7 digits
	char check;  

	char compute_check();                   // compute the check character

public:
	ISBN();
    ISBN(char set[ ]);                                                  // e.g., ISBN book("0-670-82162-4");
    ISBN(char setA[ ], char setB[ ], char setC[ ], char setD);       // 4-argument constructor is passed
                                                                        //  group code, publisher code, book
                                                                        //  code, and check character.  e.g.
                                                                        //  ISBN book("0","670","82162","4");
    ISBN(char setE[ ], char setF[ ], char setG[ ]);                     // 3-argument constructor is passed
                                                                        //  group code, publisher code, and
                                                                        //  book code.  It computes the 
                                                                        //  check character                                    
                                                                        //  e.g. ISBN book("0","670","82162");
    bool valid();                                                       // true if check character is correct
    char *getpublisher();                                               // return publisher code
    void print(ostream &o);                                             // print string with hyphens    

};

#endif



//FUNCTIONS

ISBN::ISBN() {}

ISBN::ISBN(char set[ ]) //full string of ISBN
{
   char deliminator[] = "-";
   char check2[2];
   strtok(set, deliminator);
   strcpy(group, set);
   strtok(NULL, deliminator);
   strcpy(publisher, NULL);
   strtok(NULL, deliminator);
   strcpy(book, NULL);
   strtok(NULL, deliminator);
   strcpy(check2, NULL);
   check = check2[0];               
                
}
ISBN::ISBN(char setA[ ], char setB[ ], char setC[ ], char setD) 
{
   strcpy(group, setA);
   strcpy(publisher, setB);
   strcpy(book, setC);
   check = setD;               
                
}
ISBN::ISBN(char setA[ ], char setB[ ], char setC[ ]) //this will compute the check character
{
   strcpy(group, setA);
   strcpy(publisher, setB);
   strcpy(book, setC);
   
   check = compute_check();
   
   int i = 0;  //setA 
   int k = 0;  //setA 
   int d = 0;  //setB 
   int p = 0;  //setB 
   int x = 0;  //setC 
   int y = 0;  //setC 
   
   int sum1 = 0;
   int sum2 = 0;
   int sum3 = 0;  
   int fsum = 0; 
   

    
   for(k=0; k<i; k++)
            for(setA[i]=0; i>0; i++)
            {
                           sum1=(setA[i]*k)+sum1;
            }
    
   for(p=0; p<d; p++)
            for(setB[d]=0; d>0; d++)
            {
                           sum2=(setB[d]*p)+sum2;
            }
     
   for(y=0; x<y; y++)
            for(setC[x]=0; x>0; x++)
            {
                           sum3=(setC[x]*y)+sum3;
            }
     
     fsum = (sum1+sum2+sum3)/11;
     
     return fsum = 9(sum1+sum2+sum3)/11);
                    
}

bool ISBN::valid() 
{
     char tCheck = compute_check();
     
     return(tCheck = check);
}
char ISBN:: *getpublisher() 
{   
    
     return publisher;    
}
void ISBN::print(ostream &o) 
{
     cout << group << "-" << publisher << "-" << book << "-" << check << endl;
     
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <cstring>
#include "ISBN.h"

//#include "Book.h"
using namespace std;

const int NUMBER_OF_BOOKS = 15;

void check_isbn_class();
void check_book_class();

int main() {
	check_isbn_class();
	check_book_class();
	return 0;
}

void check_isbn_class() {
	char isbns[13][14];
	int index=0;
    strcpy(isbns[index++], "1-57676-074-X");
	strcpy(isbns[index++], "0-12-597121-2");  // correct check digit is 4
	strcpy(isbns[index++], "0-385-49532-3");
	strcpy(isbns[index++], "0-321-19724-X");  // correct check digit is 0
	strcpy(isbns[index++], "0-02-360692-4");
	strcpy(isbns[index++], "0-321-19362-5");  // correct check digit is 8
	strcpy(isbns[index++], "0-201-70433-1");
	strcpy(isbns[index++], "1-56592-324-2");  // correct check digit is 3
    strcpy(isbns[index++], "0-321-19498-5");
	strcpy(isbns[index++], "0-13-034074-9");  // correct check digit is X
	strcpy(isbns[index++], "0-13-790395-2");
	strcpy(isbns[index++], "0-471-46983-0");  // correct check digit is 1
	strcpy(isbns[index++], "0-670-82162-4");
	
	for (int i=0; i<13; i++) {
		ISBN isbn(isbns[i]);
		isbn.print(cout);
		if (isbn.valid()) 
			cout << " is valid\n";
		else cout << " is not valid\n";
	}

	ISBN isbn1("0", "670", "82162"),
	     isbn2("0", "13", "034074");
	isbn1.print(cout);   // should print "0-670-82162-4"
    cout << endl;
    isbn2.print(cout);	 // should print "0-13-034074-X"
	cout << endl;
}
Last edited on
Try this instead:

1
2
3
4
5
char* ISBN::getpublisher() 
{   
    
     return publisher;    
}


Thank you! I can't believe it was that simple. Thanks again
Topic archived. No new replies allowed.