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

Write a C program that reads a sequence of nine digit numbers from a file and ou

ID: 3565291 • Letter: W

Question

Write a C program that reads a sequence of nine digit numbers from a file and outputs each number with a message indicating whether it is or is not a valid SIN. You can use a negative number at the end of the file to signal the end of data or you can use the file handling features of C to determine the end of the file. SIN. You should read the numbers as integers and define a function that extracts the individual digits into an array. You should use this array in performing the verification steps. You can use the same function to extract digits for the values described in the methodology below. The file used to test your program should include the following numbers:

Explanation / Answer

public static IEnumerable ToDigitEnumerable(this int number) { IList digits = new List(); while(number > 0) { digits.Add(number%10); number = number/10; } //digits are currently backwards, reverse the order return digits.Reverse(); } public static bool IsSocialInsuranceNumber(int number) { var digits = number.ToDigitEnumerable(); if (digits.Count() != 9) return false; //The left side of the addition is adding all even indexes (except the last digit). //We are adding even indexes since .NET uses base 0 for indexes //The right side of the addition, multiplies the odd index's value by 2, then breaks each result into //individual digits, then adds them together var total = digits.Where((value, index) => index%2 == 0 && index != 8).Sum() + digits.Where((value, index) => index%2 != 0).Select(v => v*2) .SelectMany(v => v.ToDigitEnumerable()).Sum(); //The final modulous 10 operator is to handle the scenarios where the total //is divisble by 10, in those cases, the check sum should be 0, not 10 var checkDigit = (10 - (total%10)) % 10; return digits.Last() == checkDigit; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote