Product expiration dates are often encoded using numbers and letters which encode the month day and year. A common technique is to use letters instead of numbers in the dates. Assume that ACME Bakers encodes the months using letters "A" through "L", each digit of the expiration date as the three letters "Q" through "Z", (where "Q" is 0 and "Z" is 9), and the year as the letters "Z" through "A" plus 1988 (where "Z" is 1 and "A" is 26).

Your program (and all design documentation) shall present two options to the user:
First- decode an expiration code and secondly encode a date.

If the decode option is selected, your program will prompt user for an encoded expiration data from ACME Bakers and decodes it. Days of the month that have only one digit (e.g, April 3, 1993) should be printed with a single digit, not with two date digits (e.g, April 03, 1993).

If the encode option is selected, your program will accept as input a date (i.e., October 31, 1993), and encode it into the above described code (i.e., JTRV).

Your program must check for and handle incorrect date and code formats.

I'm having a problem trying to come up with statements(if/else) which could encode and decode. See what I have below, thanks for the assistance.

#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>


using namespace std;


int main()
{
    int monthA=1;//Months during the year.
    int monthB=2;
    int monthC=3;
    int monthD=4;
    int monthE=5;
    int monthF=6;
    int monthG=7;
    int monthH=8;
    int monthI=9;
    int monthJ=10;
    int monthK=11;
    int monthL=12;

    int dayQ=0;//Days
    int dayR=1;
    int dayS=2;
    int dayT=3;
    int dayU=4;
    int dayV=5;
    int dayW=6;
    int dayX=7;
    int dayY=8;
    int dayZ=9;

    int yearA=26+1988;//Years
    int yearB=25+1988;
    int yearC=24+1988;
    int yearD=23+1988;
    int yearE=22+1988;
    int yearF=21+1988;
    int yearG=20+1988;
    int yearH=19+1988;
    int yearI=18+1988;
    int yearJ=17+1988;
    int yearK=16+1988;
    int yearL=15+1988;
    int yearM=14+1988;
    int yearN=13+1988;
    int yearO=12+1988;
    int yearP=11+1988;
    int yearQ=10+1988;
    int yearR=9+1988;
    int yearS=8+1988;
    int yearT=7+1988;
    int yearU=6+1988;
    int yearV=5+1988;
    int yearW=4+1988;
    int yearX=3+1988;
    int yearY=2+1988;
    int yearZ=1+1988;


    cout<<"Decode an expiration date"<<endl;
    cin>>
    cout<<"Encode a date"<<endl;
    cin>>
    cout<<decode<<endl;
    return 0;

here is the new code that i came up with-u can disregard the one that was initially posted.
----------------------------------------------------------------------------------

#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>


using namespace std;


int main()
{
	int January=1;//Months during the year.
	int Febuary=2;
	int March=3;
	int April=4;
	int May=5;
	int June=6;
	int July=7;
	int August=8;
	int September=9;
	int October=10;
	int November=11;
	int December=12;

	int 0=Q;//Days
	int 1=R;
	int 2=S;
	int 3=T;
	int 4=U;
	int 5=V;
	int 6=W;
	int 7=X;
	int 8=Y;
	int 9=Z;

	int Q=0;//Days
	int R=1;
	int S=2;
	int T=3;
	int U=4;
	int V=5;
	int W=6;
	int X=7;
	int Y=8;
	int Z=9;

	int yearA=26+1988;//Years
	int yearB=25+1988;
	int yearC=24+1988;
	int yearD=23+1988;
	int yearE=22+1988;
	int yearF=21+1988;
	int yearG=20+1988;
	int yearH=19+1988;
	int yearI=18+1988;
	int yearJ=17+1988;
	int yearK=16+1988;
	int yearL=15+1988;
	int yearM=14+1988;
	int yearN=13+1988;
	int yearO=12+1988;
	int yearP=11+1988;
	int yearQ=10+1988;
	int yearR=9+1988;
	int yearS=8+1988;
	int yearT=7+1988;
	int yearU=6+1988;
	int yearV=5+1988;
	int yearW=4+1988;
	int yearX=3+1988;
	int yearY=2+1988;
	int yearZ=1+1988;


	cout<<"Decode an expiration date"<<endl;
	cin>>
	cout<<"Encode a date"<<endl;
	cin>>
	cout<<decode<<endl;
	return 0;
}

lines 27-36 are invalid variable names -- variable names can not be numbers. Maybe you just forgot to delete those lines ???

>>“Q” through “Z”, (where “Q” is 0 and “Z” is 9)
that is wrong -- if 'Q' = 0 then 'Z' must be 10 when I count them on my 10 fingers.

>>and the year as the letters “Z” through “A”
How does the alphabet wrap around from the letter 'Z' to the letter 'A' while counting forward ????
I think you need to recheck and verify you posted the instructions correctly. If you did then your instructor is pretty stupid person.

Zandiago, by now, you should have learned how to use code tags.

Enclose your code in code tags.

>How does the alphabet wrap around from the letter 'Z' to the letter 'A' while counting forward ????
I think you need to recheck and verify you posted the instructions correctly. If you did then your instructor is pretty stupid person.

I think it starts counting backward. (even though that really doesn't make sense)

Member Avatar for iamthwee

Ever heard of a loop?

const char* const months = "*ABCDEFGHIJKL" ;

inline char month_to_code( int m ) 
{ 
  assert( m>0 && m<13 ) ;
  return months[ m ] ; 
}

inline int code_to_month( char c ) 
{ 
  const char* p = strchr( months, toupper(c) ) ; 
  assert( p!=0 && p!=months ) ; 
  return p - months ; 
}

// etc

after sorting out issues that Ancient Dragon pointed out

Thanks for insight...Those were the instructions that my professor gave to me. Initially I was thinking about it also as to the assignment of the alphabet letters were like that. With regards to loops, our class has not reached that chapter yet...we are at if/else statements....I'll go through the notes and see if i can get this to work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.