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
Use the drop-down menus to select the type of goal described in each statement. I want to finish all of my social studies homewo
nalin [4]

Answer:

I want to finish all of my social studies homework by dinner. - <u>Short term goal. </u>

Short term goals are targets that are to be achieved in the near and immediate future such as in a day or in a week. As the goal listed is to be done on the same day, it is a short term goal.

I want to graduate in three years in the top 15% of my class.  - <u>Normative Goal</u>

Normative goals are the goals people set based on what society looks upon as desirable and a good thing to do. Academic excellence is a normative goal as it is looked upon favorably by society.

I want to earn a good grade on my math test tomorrow. - <u>Intrapersonal goals.</u>

Intrapersonal goals are goals that we set within ourselves to motivate ourselves to do better. The writer here wants to do a good job in the math test which makes it intrapersonal.

I want to qualify for Honors Spanish next year. - <u>Long term goal</u>

A long term goal is one that is to be achieved in the future most likely after a period of a year. Qualifying for an Honors in Spanish in the next year is therefore a long term goal.

4 0
4 years ago
The process of identifying and removing logical errors and runtime errors is called ..............
9966 [12]
The process of finding and eliminating errors is called debugging.

Hope that helps
VexPlayz
6 0
3 years ago
Read 2 more answers
A company is deploying a file-sharing protocol across a network and needs to select a protocol for authenticating clients. Manag
VARVARA [1.3K]

Answer:

The answer is "Option C".

Explanation:

Among all four of the above, the application of Kerberos is securer. The consumer not just to validates the provider but also verifies the product to the clients with secure authentication.  

  • It offers a common interface between windows as well as other operating systems.  
  • The user login Smart Card gives much higher protection as it allows security with two factors, that's why except Option C other choices were wrong.
6 0
3 years ago
You are creating a presentation and you have come to the last slide. you still have more information to add. what should you do?
ohaa [14]
If you are using Google Slides, Click the plus arrow in the top left hand corner of the webpage. That will add another slide to the presentation you are working on
7 0
3 years ago
Read 2 more answers
Why is the total number of cylinders in an engine an even number?
gogolik [260]
Well there are 4 cylinders but there are also, 6, 8, 12, 16
5 0
3 years ago
Other questions:
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • Design and implement a GUI application that uses text fields to obtain two integer values (one text field for each value) along
    9·1 answer
  • Which data type structures best for insersion/ removal - Stack, linked list, queue?
    15·1 answer
  • Which statement is LEAST accurate? Select one: a. A common reason for ERP failure is that the ERP does not support one or more i
    14·1 answer
  • ___________ is related to mass, but also includes the gravitational pull of the Earth.
    14·1 answer
  • A(n) ________ CPU has two processing paths, allowing it to process more than one instruction at a time. Group of answer choices
    5·1 answer
  • For what reasons do readers use text-to-speech tools? Check all that apply.
    8·2 answers
  • 2.3 Code Practice: Question 1
    5·1 answer
  • When investigating the serial position curve, delaying the memory test for 30 seconds
    10·1 answer
  • are there any hexadecimal digits that cannot be created using 4 bits? how many bits would you need to represent the hexadecimal
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!