zip code program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: zip code program

  1. #1
    Join Date
    Mar 2009
    Posts
    11

    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
    11
    Made a few changes and still not returning any 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
    Join Date
    May 2007
    Posts
    843
    What is your question ?

Similar Threads

  1. Replies: 0
    Last Post: 08-25-2006, 08:29 PM
  2. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  3. Why integer and int32
    By Michael Culley in forum .NET
    Replies: 154
    Last Post: 05-10-2002, 12:06 PM
  4. Replies: 90
    Last Post: 04-17-2001, 12:45 AM
  5. send email
    By marina in forum Java
    Replies: 1
    Last Post: 03-12-2001, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center