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.

Answers

Answer 1

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.


Related Questions

meaning of leanness in organization​

Answers

Answer:It is an organizational structure that is designed to create more customer value using fewer resources than a traditional organisational structure

Which is a conditional statement?
If it is sunny, we can play ball.
It is sunny today.
It is sunny or rainy.
It is sunny across the street, but not sunny here.

Answers

i believe it is “if it is sunny, we can play ball”

Answer:

it is 1, I know this because i got 100% on my quiz

Explanation:

what are the advantages of using a folder?​

Answers

Answer:

1. easy access to files

2. better organization

Explanation:

In the rapid application development (RAD) model, the _____ phase focuses on program and application development tasks similar to the SDLC.A) requirements planningB) user designC) constructionD) cutover

Answers

Answer:

C) construction

Explanation:

Rapid application development abbreviated RAD is an agile software development strategy that reduces time spent on planning so that prototype development takes priority and project turnaround time is greatly reduced consequently. There are four phases in rapid application development :

requirements planning, user design, construction, cutover

The construction phase is the third stage in rapid application development. This stage builds on the progress of the previous stages- the requirements planning stage and user design stage- to go ahead to finalize the application development which has been agreed on through iterations and communication between developer and client in the user design stage. In other words, this stage basically takes the ideas, prototypes and beta products from the previous stages and makes it into a real final product. The rationale or perks behind this is that other problems such as what product would do or look like or any changes or modifications have been worked out in previous stages thereby speeding up development in this stage.

If an app asks for a user's age, it may be because the app requires a user to be over a certain age to use some of the services it provides. Write a function called checkAge that takes one parameter of type String. The function should try to convert this parameter into an Int value and then check if the user is over 18 years old. If he/she is old enough, print "Welcome!", otherwise print "Sorry, but you aren't old enough to use our app." If the String parameter cannot be converted into an Int value, print "Sorry, something went wrong. Can you please re-enter your age?" Call the function and pass in userInputAge below as the single parameter. Then call the function and pass in a string that can be converted to an integer.
Go back and update your function to return the age as an integer. Will your function always return a value? Make sure your return type accurately reflects this. Call the function and print the return value.
func checkage(age: String)->Int?
{
if let age_type = Int(age)
{
if age_type > 18 {
return "Welcome!"
}
else if age_type < 18 {
return"Sorry, but you aren't old enough to use our app."
}
}
else {
return "Sorry, something went wrong. Can you please re-enter your age?"
}
return age_type
}

Answers

Answer and Explanation:

Here the programming language swift is being used. There is a slight error in the program shown above:

var userInputAge=9

func checkage(age: String)->int?

{

if let age_type = Int(age)

{

if age_type > 18 {

return "Welcome!"

}

else if age_type < 18 {

return"Sorry, but you aren't old enough to use our app."

}

}

else {

return "Sorry, something went wrong. Can you please re-enter your age?"

}

return age_type

}

The program should be revised :

func checkage(age: int?)->String

{

if let age_type = Int(age)

{

if age_type > 18 {

return "Welcome!"

}

else if age_type < 18 {

return"Sorry, but you aren't old enough to use our app."

}

}

else {

return "Sorry, something went wrong. Can you please re-enter your age?"

}

return age_type

}

We call the functions :

checkage(userInputAge)

checkage("15")

Note: we revised the program for errors in the first line of the code where the int optional parameter(int?) was supposed to be used instead of the String parameter in the function. We then called the function using the userInputAge variable defined as the parameter and then we now also used a String as the parameter for calling the function the second time.

Answer:

def checkage(age: "String")->int:

   if age >= 18:

       return "Welcome!"

   return "Sorry, but you aren't old enough to use our app."

   

for _ in iter(list,0):

   myage = int(input("Please enter your age: "))

   if myage is int(myage):

       result = checkage(myage)

       print(result)

       break

   print("Sorry, something went wrong. Enter integer value as age.")

   

Explanation:

The python code above lets the user input the age value for continuous comparison. If the age is an integer, it checks to know if the age is greater than 18 or not. If yes, it returns "Welcome!" else "Sorry, but you aren't old enough to use our app". But if the age is not an integer, it displays the message "Sorry, something went wrong. Can you please re-enter your age?" then prompts the user again for the age.

Note: the ': "String" ' and "->int" is for documentation purposes. They are used to describe the type of parameters (for later) and return value (the former).

Other Questions
A "how-to" guide provides a series of steps to build a treehouse. This is an example of _____.sequenceconnotationtone The word for political or social change is... abolition. strike. reform. suffrage. y is directly proportional to x2If y = 12 when X = 2 findX when y = 300 V = LWH solve for the variable w A 58-kg boy swings a baseball bat, which causes a 0.140-kg baseball to move toward 3rd base with a velocity of 38.0 m/s.Calculate the kinetic energy of the baseball (rounding your answer to the integer). what are the possible values for the ones digits when a number is a multiple of 5 I WILL GIVE A LOT OF EXTRA POINTS. PLEASE ANSWER ALL OF THEM Which part of this graph shows a nonlinear relationship?Distance from home2.Time C(5,-5),D(5,3) what is the distance between the points PLEASE I NEED HELPFactor out the coefficient of the variable.The expression 3/8d+3/4 factored is Encierra en un crculo la letra junto a la mejor respuesta.Este nocnie troto Steph makes and sells birthday cakes. Each cake costs 54 to make.She makes a profit of 15% on each cake.What is the selling price of Steph's birthday cakes?(2 marks)= Will give Brainliest.....Does this sound good :)ome kids think that drugs are healthy. Vaping is good for you because it doesnt do anything. Weed is good for you because it helps you calm down and forget. These are perfect examples as to why they are not good. Vaping damages your lungs and can give your body cancer. Over time, smoking weed may cause chronic cough and other health issues. Both vaping, weed, cigarettes, alcohol, and many more drugs are not good for you or your body.Drugs are used across the world. Whether they are used properly or abused. Drugs are easy to become addicted to. They can cause substance abuse, which leads to jail time. While drugs also heal people, for example, prescription drugs when used properly are beneficial. They need to be used in restraint because even medically given to you, they are addictive. For example, pain-reducing opioids, though they are helpful they are addictive. All minds are affected; it's not just a teenager thing. Drugs should be monitored by someone, and while it is slightly out-of-pocket, it's a lot better than spending possible years in prison.Vaping may be a little better than weed or cigarettes but it still harms your body in multiple ways. It causes you to crave and if you dont follow that craving it will lead to withdrawal symptoms. Nicotine is an addictive chemical. It is a toxic substance. It raises your blood pressure and spikes your adrenaline, which then increases your heart rate. Increased heart rate can conclude to having a heart attack.An abundance of alcohol can harm the liver. This can lead to hepatitis, which is the buildup of scar tissue that eventually destroys the organ. Alcohol may cause kidney, bladder, and prostate inflammation. Alcohol is also an addictive substance, though alcohol may relieve pain and make you forget things, too much will make you drunk and incoherent.Opioids are a class of drugs used to reduce pain. Prescription opioids can be prescribed by doctors to treat moderate to severe pain, but can also have serious risks and side effects. Common types are oxycodone (OxyContin), hydrocodone (Vicodin), morphine, and methadone. Fentanyl is a synthetic opioid pain reliever. please solve this i will give you brainliest pls help and explain if u can Which of the following could represent the unit side lengths of a right triangleA 5,8,10B 3,5,7C 6,11,13D 12,16,20 Which of these is a simple sentence?a. The clown frightened the little girl, and she ran c. My brother is fun to be around until he startsoff screaming when she saw it.making animal sounds.b. My aunt enjoyed taking the hayride through d. Even though many kids may not like fallthe overgrown pumpkin patch.festivals, I love going to them.Please select the best answer from the choices providedA.B.C.D. Did slavery exist in West Africa before Africans were brought to America? Solve4x - 9 = 6 - x Is the equation y +1 = 6(x + 5) in point-slope form? Justify your answer.(select) the equation is equivalent to