zip code program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: zip code program

  1. #1
    Join Date
    Mar 2009
    Posts
    13

    zip code program

    I am testing a program that I am trying to run and having some difficulties with it. If you run this program I am able to compille it fine but will not return anything and stalls on me...Here are the instructions.....

    There are 25 digits split into five groups of five digits each...

    10100 10100 01010 11000 01001

    Next, consider each group fo five digits. Each digit stands for a number. From left to right the digits encode the values 7,4,2,1,0. Multilply the value with the digit and compute the sum to get the final encoded digit for the zip code....

    Here is an example table
    bar code digit 1 0 1 0 0
    value 7 7 2 1 0
    digit * value 7 0 2 0 0

    so the first zip code digit will be 7 + 0 +2 + 0 + 0 = 9

    REpeat this foe each group of five digits and concatenate to get the complete zip code. There is one special value. If the sume of a group of five digits is 11, then represent this with a 0.

    Write z zip code class that encodes and decodes five-digit bar codes. The class should have two constructors. The first constructor should input the zip code as an integer, and the second constructor should input the zip code as a bar code stirng consisting of 0's and 1's. The class should have at least 2 public member functions, one to return the zip code as an integer, and the other to return the zip code as a string. All helper functions should be declared private. Embed your class definition in a suitable test program. Your program should print an error message if an invalid test is passed to the constructor...


    here is my code I have so far...the only help I really need is on why I cannot see and return values but if you see any additional issues I will be having from these instructions please let me know...

    Code:
    
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class POSTNET
    {
    public:
    	void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5);
    	int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);
    	int addDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);
    };
    
    void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5)
    {
    	valueDigit1 = 7;
    	valueDigit2 = 4;
    	valueDigit3 = 2;
    	valueDigit4 = 1;
    	valueDigit5 = 0;
    }
    
    int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
    {
    	int digit1 = 0, digit2 = 0, digit3 = 0, digit4 = 0, digit5 = 0, valueDigit1 = 0, valueDigit2 = 0, valueDigit3 = 0, valueDigit4 = 0, valueDigit5 = 0;
    	productOfDigit1 = digit1 * valueDigit1;
    	productOfDigit2 = digit2 * valueDigit2;
    	productOfDigit3 = digit3 * valueDigit3;
    	productOfDigit4 = digit4 * valueDigit4;
    	productOfDigit5 = digit5 * valueDigit5;
    	return 0;
    }
    
    
    	 
    
    int main()
    {
    	int digit1, digit2, digit3, digit4, digit5, productOfDigit1 = 0, productOfDigit2 = 0, productOfDigit3 = 0, productOfDigit4 = 0, productOfDigit5 = 0;
    	cout << "Enter the first five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	cout << "Enter the second five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	cout << "Enter the third five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	cout << "Enter the fourth five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	cout << "Enter the last five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	valueOfDigits(digit1, digit2, digit3, digit4, digit5);
    	multiplyDigits(productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5);
    	cout << "The zip code is: " << endl;
    	cin >> productOfDigit1 >> productOfDigit2 >> productOfDigit3 >> productOfDigit4 >> productOfDigit5;
    	return 0;
    }

  2. #2
    Join Date
    Mar 2009
    Posts
    13

    Re: zip code program

    Made a few changes and still not returning and values.....

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class ZipCodes
    {
    public:
    	void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5);
    	int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);
    	
    };
    
    //Values of each group of five digits from left to right
    void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5)
    {
    	valueDigit1 = 7;
    	valueDigit2 = 4;
    	valueDigit3 = 2;
    	valueDigit4 = 1;
    	valueDigit5 = 0;
    }
    
    //Multiply the bar code digits and values to get a product of the digits
    int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
    {
    	int digit1, digit2, digit3, digit4, digit5, valueDigit1, valueDigit2, valueDigit3, valueDigit4, valueDigit5, zipDigit;
    	productOfDigit1 = digit1 * valueDigit1;
    	productOfDigit2 = digit2 * valueDigit2;
    	productOfDigit3 = digit3 * valueDigit3;
    	productOfDigit4 = digit4 * valueDigit4;
    	productOfDigit5 = digit5 * valueDigit5;
    	zipDigit = productOfDigit1 + productOfDigit2 + productOfDigit3 + productOfDigit4 + productOfDigit1;
    	return zipDigit;
    }
    
    int main()
    {
    	int digit1, digit2, digit3, digit4, digit5, productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5;
    	cout << "Enter the first five bar code digits " << endl;
    	cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
    	valueOfDigits(digit1, digit2, digit3, digit4, digit5);
    	multiplyDigits(productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5);
    	cout << "The zip code is: " << endl;
    	cin >> productOfDigit1 >> productOfDigit2 >> productOfDigit3 >> productOfDigit4 >> productOfDigit5;
    	return 0;
    }

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,980

    Re: zip code program

    Code:
    int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
    {
    	int digit1, digit2, digit3, digit4, digit5, valueDigit1, valueDigit2, valueDigit3, valueDigit4, valueDigit5, zipDigit;
    	productOfDigit1 = digit1 * valueDigit1;
    Look at what you're doing.

    digit1, digit2, etc. are uninitialized. You multiply those uninitialized values together and assign the result to one of the arguments that was passed in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center