#include <stdio.h>
int validateIrishLicense( int year, int halfYear, char County, int Sequence1) ;
int main( void ) {
int valid= validateIrishLicense( 13 , 1 , 'D' , 21 ) ;
printf ( "Valid or not %i\n " , valid
) ;
int retVal = validateIrishLicense ( 13 , 2 , 'X' , 1 ) ;
printf ( "Valid or not retVal: %i\n " , retVal
) ;
int retVal2 = validateIrishLicense ( 24 , 1 , 'C' , 1245891 ) ;
printf ( "Valid or not retVal2: %i\n " , retVal2
) ; return 0 ;
}
//***********************************************************************************************************************************
// Function: validateIrishLicense
//
// Purpose: Receives information on the year, half year,
// county, and a one to six-digit sequence number which
// are used to validate an Irish license plate and return
// a True value (1) if the license plate is valid,
// otherwise a False value (0)
//
// Parameters:
//
// year - Two digit year (2013 would be 13, 2014 would be 14, and so on .. through 24 for 2024. Any other year is invalid)
// halfYear - Number used to represent the half year. A 1 indicates the car was sold between Jan-Jun, while a 2 between July-Dec
// county - A character value that represents the Irish County where the car was registered
// sequence1 - A one to six-digit sequence number, starting with the first vehicle registered in the county/city that year/period
//
//
// Returns: a True value (1) if the license plate is valid, otherwise a False value (0)
//
//***********************************************************************************************************************************
int validateIrishLicense( int year, int halfYear, char county, int sequence1) {
int criteriaMet= 0 ; /*local variable that will be used to represent the number of criteria for a license plate to be valid that are met*/
if ( year>= 13 & year<= 24 ) {
criteriaMet+= 1 ; /*if year is in the appropriate range, then increment the number of criteria met (criteriaMet) by 1 */
}
if ( halfYear== 1 | halfYear== 2 ) {
criteriaMet+= 1 ; /*if the half year is in the appropriate range, then increment the number of criteria met (criteriaMet) by 1 */
}
char valid_county[ ] = { 'C' , 'c' , 'D' , 'd' , 'G' , 'g' , 'L' , 'l' , 'T' , 't' , 'W' , 'w' } ; /*list of the valid character values that can be used to represent Irish counties*/
const VAL_COUNTIES= 12 ; /*number of valid character values that can be used to represent Irish counties*/
for ( int i= 0 ; i < VAL_COUNTIES; i++ ) {
if ( county== valid_county[ i] ) {
criteriaMet+= 1 ; /*if the value for county is in the list of valid counties, then increment the criteria met variable by 1*/
}
}
int digits= 1 ; /*creating a variable to represent the number of digits in a sequence and setting it to 1 to start*/
if ( sequence1> 0 ) {
while ( ( sequence1/ 10 ) > 0 ) {
digits+= 1 ; /*dividing the numeric sequence by 10 and it is still greater than 0, then it has another digit */
sequence1 /= 10 ; /*continuing to do this until the total number of digits have been counted*/
}
}
if ( digits>= 1 & digits<= 6 ) {
criteriaMet+= 1 ; /*if the sequence is the appropriate number of digits (i.e., 1-6 digits)
then incrementing the number of criteria met by 1*/
}
if ( criteriaMet== 4 ) {
return 1 ; /*checking if all 4 criteria for identifying a license plate as valid have been met
and if so, returning a value of 1 (to represent a valid license plate)*/
}
else {
return 0 ; /*if it's not the case that all the criteria have been met, returning a value of 0*/
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgdmFsaWRhdGVJcmlzaExpY2Vuc2UoaW50IHllYXIsIGludCBoYWxmWWVhciwgY2hhciBDb3VudHksIGludCBTZXF1ZW5jZTEpOwoKaW50IG1haW4odm9pZCkgewoJaW50IHZhbGlkPXZhbGlkYXRlSXJpc2hMaWNlbnNlKDEzLDEsJ0QnLDIxKTsKICAgIHByaW50ZigiVmFsaWQgb3Igbm90ICVpXG4iLCB2YWxpZCk7CgogICAgaW50IHJldFZhbCA9IHZhbGlkYXRlSXJpc2hMaWNlbnNlICgxMywgMiwgJ1gnLCAxKTsgCiAgICBwcmludGYoIlZhbGlkIG9yIG5vdCByZXRWYWw6ICVpXG4iLCByZXRWYWwpOwoKICAgIGludCByZXRWYWwyID0gdmFsaWRhdGVJcmlzaExpY2Vuc2UgKDI0LDEsJ0MnLDEyNDU4OTEpOwogICAgcHJpbnRmKCJWYWxpZCBvciBub3QgcmV0VmFsMjogJWlcbiIsIHJldFZhbDIpOwoJcmV0dXJuIDA7Cn0KCi8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqK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