Postnet Bar Code Program

Hey, so I am trying to create a program that will prompt the user to enter a 5 digit zip code or a 25 character bar code. The program should be able to read both inputs and provide the user with the zip code if they entered a bar code and vice versa.

My program is not compiling and I am not sure why I have read through it countless times. Any help would be much appreciated.

Thanks

here is my code:

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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;


class PostalService
{
public:
	PostalService(int codeNumber);
	PostalService(string barString);

	int getZipCode();
	int getBarCode();

private:
	int zipCode;
	string barCode;

	void findBarCode(int);
	void findZipCode(string);
};

int main() {
	int zip = 0;
	string bar;

	cout << "Enter the zip code number: ";
	cin >> zip;

	while (zip < 10000 || zip > 99999) {
		cout << "Invaild zip Code, Please enter a 5 digit zip code: ";
		cin >> zip;
	}

	PostalService service1(zip);
	cout << "The coresponding bar code string: " << service1.getBarCode() << endl;

	cout << "Enter the bar code string: ";
	cin >> bar;

	while (bar.length() != 25 || bar.at(0) != '1' || bar.at(24) != '1') {

		cout << "Enter the 25 character bar code: ";
		cin >> bar;
	}

	PostalService service2(bar);
	cout << "The user bar code string: " << service2.getBarCode() << endl;

	cout << "The corresponding zip code number: " << service2.getZipCode() << endl;

	system("pause");
	return 0;
}


PostalService::PostalService(int codeNumber) {
	zipCode = codeNumber;
	barCode = "";
	
	findBarCode(zipCode);
}

PostalService::PostalService(string barString) {
	barCode = barString;
	zipCode = 0;
	findZipCode(barString);
}

int PostalService::getZipCode() {
	return zipCode;
}

string PostalService::getBarCode() {
	return barCode;
}

void PostalService::findBarCode(int zipCode) {
	int digit;
	do {
		digit = zipCode % 10;
		zipCode = zipCode / 10;

		switch (digit) {
		case 0: barCode = "||:::" + barCode;
			break;
		case 1: barCode = ":::||" + barCode;
			break;
		case 2: barCode = "::|:|" + barCode;
			break;
		case 3: barCode = "::||:" + barCode;
			break;
		case 4: barCode = ":|::|" + barCode;
			break;
		case 5: barCode = ":|:|:" + barCode;
			break;
		case 6: barCode = ":||::" + barCode;
			break;
		case 7: barCode = "|:::|" + barCode;
			break;
		case 8: barCode = "|::|:" + barCode;
			break;
		case 9: barCode = "|:|::" + barCode;
			break;
		}
	}

	while (zipCode > 0);
}

void PostalService::findZipCode(string barCode) {
	string str;
	str = barCode.substr(0, 5);
	
	if (str == "11000") {
		cout << "Error in the bar code string." << endl;
		system("pause");
		exit(1);
	}

	do {
		str = barCode.substr(0, 5);
		barCode = barCode.substr(5);
		if (str == "||:::")
			zipCode = zipCode * 10 + 0;
		else if (str == ":::||")
			zipCode = zipCode * 10 + 1;
		else if (str == "::|:|")
			zipCode = zipCode * 10 + 2;
		else if (str == "::||:")
			zipCode = zipCode * 10 + 3;
		else if (str == ":|::|")
			zipCode = zipCode * 10 + 4;
		else if (str == ":|:|:")
			zipCode = zipCode * 10 + 5;
		else if (str == ":||::")
			zipCode = zipCode * 10 + 6;
		else if (str == "|:::|")
			zipCode = zipCode * 10 + 7;
		else if (str == "|::|:")
			zipCode = zipCode * 10 + 8;
		else if (str == "|:|::")
			zipCode = zipCode * 10 + 9;

		else {
			cout << "Error in the specified bar code string." << endl;
			system("pause");
			exit(1);
		}

	}
	while (barCode.length() > 0);
}
Last edited on
My program is not compiling and I am not sure why I have read through it countless times. Any help would be much appreciated.

These error messages should give you a big clue as to where to look and what is wrong:
76:8: error: prototype for 'std::string PostalService::getBarCode()' does not match any in class 'PostalService'
15:6: error: candidate is: int PostalService::getBarCode()


What do you not understand about these messages?
Frankly how to fix them. I am still a noob, this is my third program ever I am reading out of the book to understand how to set these up, but there isn't much help in troubleshooting.

I will work on those see if I can come up with it. Thank you for giving me a spot to look.
Last edited on
Remember that your prototype on line 15 must exactly match the function implementation that starts on line 76, and the function call must use the same type and number of parameters.

Last edited on
oh my.... I feel dumb! hah

thank you for humoring my post and helping me. changed int to string and had to fix a couple other minor typing errors and guess what? It compiled and worked flawlessly.

thanks again bud!
Last edited on
Topic archived. No new replies allowed.