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
There are some network modeling tools that can ________ the existing network.
lesya [120]
<span>There are some network modeling tools that can scan the existing network.</span>
4 0
3 years ago
Read 2 more answers
Which windows command always navigates the command-line interface back to the root directory?
Pie
The answer is "cd \".
5 0
3 years ago
Which of the following represents knowledge as a set ofâ rules? A. Neural networks.B. Machine learning systems.C. Robotics.D. Ex
sveta [45]

Answer:

D. Expert systems

Explanation:

Artificial intelligence (AI) also known as machine learning can be defined as a branch of computer science which typically involves the process of using algorithms to build a smart computer-controlled robot or machine that is capable of performing tasks that are exclusively designed to be performed by humans or with human intelligence.

Artificial intelligence (AI) provides smarter results and performs related tasks excellently when compared with applications that are built using conventional programming.

Generally, there are two (2) main characteristics of artificial intelligence (AI) systems and these include;

I. Non-algorithmic processing.

II. Symbolic processing.

In artificial intelligence (AI), the field of expert systems is the most important applied area because it models human knowledge.

Hence, expert systems represents knowledge as a set of rules.

Although, all expert systems are generally lacking in human capabilities and can only use inference procedures to proffer solutions to specific problems that would normally require human expertise or competence.

Some of the areas where expert systems can be applied are; monitoring, diagnosis, scheduling, classification, design, process control, planning, etc.

5 0
2 years ago
What occurs in a steam engine?
VARVARA [1.3K]
Fist one correct.
second wrong because not all heat is used for work, some of it lost to other.
third wrong because fuel burn inside is called combustion engine
 <span />
7 0
3 years ago
Read 2 more answers
Make a webpage that shows news <br>​
Nataly_w [17]
Well it all depends how you plan on making it as you would need to know Web Development or you could just copy paste code from YT
8 0
2 years ago
Other questions:
  • End-user development: the process by which an organization's non-it specialists create software applications.
    8·1 answer
  • I'm the state of Florida, your first conviction for DUI can result in your vehicle being impounded for
    5·1 answer
  • By Carl Sandburg
    6·1 answer
  • When a compiler finds errors, it usually indicates what they are so you can correct the code and compile the program again?
    11·1 answer
  • What games do you play?<br><br><br> Be sure not to report any answers!
    5·1 answer
  • In the early 1800's, a “computer" was not a machine, it was a person who did math
    8·2 answers
  • Software that enables the organization to centralize data is called A. Data Repository B. Data Base Management System C. Data Wa
    6·1 answer
  • State the functions of the parts of the computer​
    11·2 answers
  • Fort Nite is the best u can’t say it’s not
    13·2 answers
  • Select each of the steps involved in creating a table in a presentation.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!