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.

  • 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...

  • 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 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...

  • 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...

  • C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention...

    C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention to the rules at the bottom. Extra good rating to whoever can help me with this. TIA. In certain programming situations, such as getting information from web forms, via text boxes, the data coming in may need to be numerical (we want to perform arithmetic on it), but it is stored in the form of a list of characters (the numerical value stored is...

  • please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop...

    please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop a "Schedule Book System that runs in the command line environment. The system stores the schedule of events input by user and allows users to add view or delete events. You can assume that the system can at most store 100 events Each group is required to write a Win32 Console Application program called ScheduleBook.cpp The requirements are listed below. RO When the program...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

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
ADVERTISEMENT