Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C Programming C Language Write a Complete program for the following specifica

ID: 3651880 • Letter: I

Question

In C Programming
C Language



Write a Complete program for the following specification:

The SerialNumber class takes a serial number in
the form of LLLLLLLLLLLL-DDDDDDDDD-LLLLLLLLL where each L is a letter
and each D is a digit. The serial number has three groups
of characters, separated by hyphens.

Note: This time any number of letters followed by - followed by any number of digit followed by followed by any number of letters.

Example:

String serial1= "GHFFFFFTRJ-8978888885-AQTTTTWR"; // Valid
String serial2 = "GHT7J-8975-AQWR"; // Invalid
String serial3 = "GHTRJ-8J75-AQWR"; // Invalid
String serial4 = "GHTRJ-8975-AQ2R"; // Invalid

Explanation / Answer

bool Complete(char* serial) { int i = 0; bool shouldBeDigit = false; while (serial[i] != 0) { if(serial[i] == '-') // if we have a hyphen reverse what will cause us to return false { shouldBeDigit = !shouldBeDigit; i++; continue; // skip the rest of the block and jump back to the start of the loop } if((serial[i] < 'A' || serial[i] > 'Z') && !shouldBeDigit) // if it's not a letter but should be return false; if((serial[i] < '0' || serial[i] > '9') && shouldBeDigit) // if it's not a digit but should be return false; i++; } return true; // everything checks out }