1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Roman55 [17]
3 years ago
8

Retail products are identified by their Universal Product Codes (UPCs). The most commonform of a UPC has 12 decimal digits: The

first digit identifies the product category, the nextfive digits identify the manufacturer, the following five identify the particular product, andthe last digit is acheck digit. The check digit is determined in the following way:
• Beginning with the first digit multiply every second digit by 3.
• Sum all the multiplied digits and the rest of the digits except the last digit.
• If the (10 - sum % 10) is equal to the last digit, then the product code is valid.
• Otherwise it is not a valid UPC.The expression is:sum= 3.x1+x2+ 3.x3+x4+ 3.x5+x6+ 3.x7+x8+ 3.x9+x10+ 3.x11where the x’s are the first 11 digits of the code.
If you choose to add the last digit also in the second step and if the sum is a multiple of 10,then the UPC is valid. Either way, you still need to perform the modular division to checkwhether the given number is a valid code.In this problem, you need to use either a string or long long integer type for the product codebecause it is 12 digits long. If you use string, you can convert one character substring of thestring in to a single digit integer from left to right using the function stoi(str.substr(i,1)).This way you do not need to get last digit of the number and then divide the number by 10.
in c++
problem 3
Translate the following pseudocode for randomly permuting the characters in a string into a C++ program. Read a word. repeat word.length() times Pick a random position i in the word, but not the last position. Pick a random position j > i in the word. swap the letters at positions j and i. Print the word. Please work on this problem after we learn to generate random numbers in the class which is on Wednesday the latest. These problems only deal with simple loop while, for and do loops. You will get a second set of problems next week on nested loops.
Computers and Technology
1 answer:
Dahasolnce [82]3 years ago
8 0

Answer:

#include <iostream>

#include <cmath>

using namespace std;

int main(){

   string upc;

   char last;

   cout<< "Enter UPC number: ";

   cin >> upc;

   if (upc.size() == 12){

       last = upc[-1];

   } else{

       return 0;

   }

   cout<< last;

   char myArr[upc.length()];

   for (int i = 0 ; i < upc.substr(0,11).length(); ++i){

       if (upc[i]%2 != 0){

           myArr[i] = upc[i] * 3;

       }

       else{

           myArr[i] = upc[i];

       }

   }

   int sum = 0;

   for (int x = 0; x < sizeof(myArr); ++x){

       sum += (int)myArr[x] - '0';

   }

   if (sum% 10 == last){

       cout<<"UPC number is valid";

   }

   else{

       cout<<"Invalid UPC number.";

   }

}

Explanation:

The UPC number in the c++ source code input must be 12 digits long for the rest of the code to execute.  The code checks the validity of the number by comparing the reminder of the sum division with the last digit in the UPC number.

You might be interested in
Computer engineering is a career that......
WITCHER [35]

Answer:

Computer engineering is a career that works on the development and research of new technology-related things.

Explanation:

4 0
3 years ago
An _____provider is a business that provides individuals and companies access to the internet for free
boyakko [2]

Answer:A B

access provider Business that provides individuals and companies access to the Internet free or for a fee.

Explanation:

6 0
3 years ago
Read 2 more answers
Some websites are dedicated to cataloguing information. Since these sites contain so much data, these sites are usually organize
swat32
B databooks...........


....
3 0
3 years ago
Generally, information is extracted from __ for communication.
denis-greek [22]
Extracting information from the message.  It i<span>s exclusive to the "interpreting the message" step in a business communication process.</span>
7 0
3 years ago
What part of the cover letter explains how the applicant’s qualifications meet the needs of the company?
kakasveta [241]
The correct answer is C. Argument. 

Next time, learn how to put the whole question.
5 0
3 years ago
Read 2 more answers
Other questions:
  • A series circuit and identify how voltage is split up by each load in the circuit?
    11·1 answer
  • What command would you use to list the text files in your
    7·1 answer
  • What authentication protocol is ticket-based and is used by windows computers that are members of an active directory domain?
    13·1 answer
  • What is one way to improve the upward flow of information?
    12·1 answer
  • Consider two communication technologies that use the same bandwidth, but Technology B has twice the SNR of technology A. If tech
    14·1 answer
  • Which sentence is correctly punctuated? WILL GIVE YU MONEY GIVE ME YOUR CASH APP PLS
    12·2 answers
  • Rate my dog out of ten give explanation why
    12·1 answer
  • Please Help meeeeeeeeeee:
    11·2 answers
  • You are to calculate the property tax for tax payers. You will ask the county tax clerk if they want to run the program and init
    9·1 answer
  • Which computer are used by mobile employees such as meter readers.​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!