Question

1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individ


Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<string.h>
#include<math.h>

using namespace std;

// function to get the desired integer value corresponding to each
// valid character specified in the definition
int lookupValue(char ch){

   int value ;

   switch(ch){
       case '0' : value = 0; break;
       case '1' : value = 1; break;
       case '2' : value = 2; break;
       case '3' : value = 3; break;
       case '4' : value = 4; break;
       case '5' : value = 5; break;
       case '6' : value = 6; break;
       case '7' : value = 7; break;
       case '8' : value = 8; break;
       case '9' : value = 9; break;
       case 'A' : value = 10; break;
       case 'C' : value = 11; break;
       case 'D' : value = 12; break;
       case 'E' : value = 13; break;
       case 'F' : value = 14; break;
       case 'H' : value = 15; break;
       case 'J' : value = 16; break;
       case 'K' : value = 17; break;
       case 'L' : value = 18; break;
       case 'M' : value = 19; break;
       case 'N' : value = 20; break;
       case 'P' : value = 21; break;
       case 'R' : value = 22; break;
       case 'T' : value = 23; break;
       case 'V' : value = 24; break;
       case 'W' : value = 25; break;
       case 'X' : value = 26; break;
       default : value = -1;
   }

   return value;
}


// function to replace the value of the characters
// which are confusing
char exchange(char ch) {

   char value;

   switch(ch){
       case 'B' : value = '8'; break;
       case 'G' : value = 'C'; break;
       case 'I' : value = '1'; break;
       case 'O' : value = '0'; break;
       case 'Q' : value = '0'; break;
       case 'S' : value = '5'; break;
       case 'U' : value = 'V'; break;
       case 'Y' : value = 'V'; break;
       case 'Z' : value = '2'; break;
       default : value = ch;
   }

   return value;
}


// function to convert base 27 number to base 10 number
long long int getBase10Value(string s){

   long long int value = 0;

   for(int i=0;i<8;i++){
       value += lookupValue(s[i])*pow(27,7-i);
   }

   return value;
}

// function to validate if the value of the number we get using the formula
// matches the check bit
bool validateCheckSum(string s){

   int sum = 0;
   sum += 2*lookupValue(s[0]);
   sum += 4*lookupValue(s[1]);
   sum += 5*lookupValue(s[2]);
   sum += 7*lookupValue(s[3]);
   sum += 8*lookupValue(s[4]);
   sum += 10*lookupValue(s[5]);
   sum += 11*lookupValue(s[6]);
   sum += 13*lookupValue(s[7]);
   sum = sum % 27;

   if(sum == lookupValue(s[8])){
       return true;
   }else{
       return false;  
   }
  
}


int main(){

   string ucn;

   cout<<"Enter the UCN : ";
   cin>>ucn;

   // for loop to replace conflict characters
   for(int i=0;i<9;i++){
       ucn[i] = exchange(ucn[i]);  
   }

   // validating check sum and printing output
   if(validateCheckSum(ucn)){
       cout<<ucn<<" decimal value is : "<<getBase10Value(ucn)<<endl;
   }else {
       cout<<ucn<<"- Invalid"<<endl;
   }

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Please I need help with this c++ code. please show all steps , write comments and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please write psedocodes for all of the questions and an algorithm for 2. no coding is...

    please write psedocodes for all of the questions and an algorithm for 2. no coding is required . FIUJELI 95 PIOL 1. (Geometry: Area of a Pentagon) Write a C# program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing the area of a pentagon is Area = 2 , where s is the length...

  • i need know how Write a program that tests whether a string is a valid password....

    i need know how Write a program that tests whether a string is a valid password. The password rules are: It must have at least eight characters. It must contain letters AND numbers It must contain at least two digits It must contain an underscore (_) Write a program that prompts the user to enter a password and displays the password entered and whether it is valid or invalid.

  • Using Visual Studio 2017 Create This Program Using C# implement source code Program 5: The concept...

    Using Visual Studio 2017 Create This Program Using C# implement source code Program 5: The concept of a 5-digit palindrome number is a 5-digit number that reads the same from left to right and from right to left. For example, 12121, 45454, and 14741 are valid 5-digit palindrome numbers. Design (pseudocode) and implement (source code) a program (name it FiveDigitPalindrom) that reads a 5-digit number from the user (as integer value, not string) and then mathematically (using division and remainder...

  • hello. i need help with number 2 ONLY 1. Use if statements to write a Java...

    hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...

  • I need it in c++ The U.S. Banking System The code assigned to a bank is...

    I need it in c++ The U.S. Banking System The code assigned to a bank is an eight digit number plus a ninth check digit. To check for validity, the first eight digits are assigned weights (left to right) of 7, 3, and 9 repetitively. Each digit is multiplied by its weight and the products summed. The resulting sum (mod 10) should equal the check digit. The assigning of weights insures that all single digit errors and most transposition errors...

  • Given java code is below, please use it! import java.util.Scanner; public class LA2a {      ...

    Given java code is below, please use it! import java.util.Scanner; public class LA2a {       /**    * Number of digits in a valid value sequence    */    public static final int SEQ_DIGITS = 10;       /**    * Error for an invalid sequence    * (not correct number of characters    * or not made only of digits)    */    public static final String ERR_SEQ = "Invalid sequence";       /**    * Error for...

  • I really need help with the code for this, in C++ please, I know there's a...

    I really need help with the code for this, in C++ please, I know there's a similar question but the answer isn't correct :[ A palindrome is a string that reads the same forwards and backwards (ignoring spaces, punctuation, and capitalization). Examples are the familiar ``If I had a hi-fi,'' the grander ``A man, a plan, a canal, Panama,'' and ``Some men interpret nine memos.'' So the goal: Design, implement, document, and test a program that reads a line of...

  • Need help answering the following using java 2a. Write a java program (just a “void main”)...

    Need help answering the following using java 2a. Write a java program (just a “void main”) that will reverse the digits of a user entered, positive three-digit number. You can assume the user enters an integer. Your code segment should first verify that the user has entered a number from 100 to 999 (error message if not). If the user has entered a three-digit number, output a new number with the original digits reversed. 2b. Instead of being limited to...

  • please I need help with the question: Problem: Write a C++ program that reads each character...

    please I need help with the question: Problem: Write a C++ program that reads each character from a user input, extracts the character if it is a digit, and calculates the sum of all the digits. The program stops reading the user input when the new line character ‘\n’ is encountered. For the output of the program, you should print each digit extracted from the user input and the sum of all the digits. (*The main difference between “cin >>...

  • Please write c++ (windows) in simple way and show all the steps with the required output

    please write c++ (windows) in simple way and show all the steps with the required output Write a C++ program that simulates the operation of a simple online banking system The program starts by displaying its main menu as shown in Figure1 splay Account nformatson verity Your credit Card elect vour choice Figure 1 Main menu of the program The menu is composed of the following choices 1. When choice 1 is selected (Display Account information), the program should display...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT