Question

here is the other question from my c++ class. Please help me solve it. Thank you...

here is the other question from my c++ class. Please help me solve it. Thank you so much !!

9. A personal identification number may be set to be any 4 digits.
(a) How many possible PINs are there?
(b) How many possible PINs are there that do not have a repeated digit?
(c) How many possible PINs are there that do have a repeated digit?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
using namespace std;

bool has_repeated_digits(string s) {
    return s[0] == s[1]  || s[0] == s[2] || s[0] == s[3] || s[1] == s[2] || s[1] == s[3] || s[2] == s[3];
}

int main() {
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = '0'; i <= '9'; ++i) {
        for (int j = '0'; j <= '9'; ++j) {
            for (int k = '0'; k <= '9'; ++k) {
                for (int l = '0'; l <= '9'; ++l) {
                    string s;
                    s += i;
                    s += j;
                    s += k;
                    s += l;
                    c1++;
                    if (has_repeated_digits(s)) {
                        c2++;
                    } else {
                        c3++;
                    }
                }
            }
        }
    }
    cout << "Total number of possible PINs = " << c1 << endl;
    cout << "Total number of possible PINs that do not have a repeated digit = " << c3 << endl;
    cout << "Total number of possible PINs that do have a repeated digit = " << c2 << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
here is the other question from my c++ class. Please help me solve it. Thank you...
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
  • Help me please, my example from class aren’t of any help to me. Thank you. 1....

    Help me please, my example from class aren’t of any help to me. Thank you. 1. A mass of 2.85 kg is attached to a spring (k 225 N/m) and set to oscillate orizontally on a frictionless track by stretching the spring 0.48 m. a) Determine the position, velocity, and acceleration as a function of time. c) How much time elapses from the moment the mass is released until it d) What is the maximum velocity and maximum acceleration of...

  • Hi, I need help on my assignment for my discrete structures class. Thank you, and I...

    Hi, I need help on my assignment for my discrete structures class. Thank you, and I will remember to rate your answer! 5. Consider the set of 3-digit integers between 100 and 999 inclusive. a. How many are divisible by 5? b. How many are divisible by 4? C. How many are not divisible by 5? d. How many are divisible by 4 or 5? e. How many are divisible by 4 and 5? f. How many are divisible by...

  • Can anyone help me with these, please? Thank you! Examine a trendy, fad, or other Weight...

    Can anyone help me with these, please? Thank you! Examine a trendy, fad, or other Weight Loss diet that you have heard about/read about/talked about/tried. (Examples include the Atkins, South Beach, Grapefruit Diet, ketogenic diet, cabbage soup diet, etc.) Answer the following questions and submit in class, typewritten, double spaced. No word limit on this, but see breakdown of points per question so make sure answer questions fully. Use any 3 sources; sources do not have to be reputable as...

  • English native speakers can you please help me write an email to my teacher. This morning...

    English native speakers can you please help me write an email to my teacher. This morning I talked to her and she asked me to meet her tomorrow so she could help me review my group presentation that is due on Wednesday. Unfortunately, I won't be able to meet her due to an unforeseen and emergent situation. I was starting to write something but I feel like it sounds dry and without flow. I'd really appreciate if you please help...

  • Can someone help me with these, please? Thank you. 12:28 Examine a trendy, fad, or other...

    Can someone help me with these, please? Thank you. 12:28 Examine a trendy, fad, or other Weight Loss diet that you have heard about/read about/tal ked about/tried. (Examples include the Atkins, South Beach, Grapefruit Diet, ketogenic diet, cabbage soup diet, etc.) Answer the following questions and submit in class, typewritten, double spaced. No word limit on this, but see breakdown of points per question so make sure answer questions fully. Use any 3 sources; sources do not have to be...

  • Make sure that you state your answer in a way that does not lose precision. Show...

    Make sure that you state your answer in a way that does not lose precision. Show all digits. a. The Personal Identification Number (PIN) for your ATM card is four places long. Any number is permitted in each place. How many possible values of a PIN are there? b. Your bank has decided to allow English alphabetic characters (upper or lower case are permitted) as well as any numeric digit in your PIN. How many possible PINs are there when...

  • This is a cell molecular biology question from my class. Can someone please help me with...

    This is a cell molecular biology question from my class. Can someone please help me with this question? Please no diagrams or pictures from online copied and pasted here. I need a detailed explanation. Thank You! Please draw the five levels of M phase in a diploid cell (2n) where n=2.

  • please kindly help me solve this Human computer Interaction question. Thank you so much Good day,...

    please kindly help me solve this Human computer Interaction question. Thank you so much Good day, kindly Help me to solve this Human Computer Interaction Questions. Thank you Question 3 (20 marks): Evaluate and Redesigning Application Interfaces you think are Bad Designs Choose any IT garget, an application or a website of your interest. Study and evaluate the interface of this chosen application or website applying the concepts you have learnt in the HCI class. Redesign the interface, detailing things...

  • Please do it in c++ please show steps as much as possible to help me understand...

    Please do it in c++ please show steps as much as possible to help me understand the code thank you Credit Card error detection check -> Luhn Algorithm, (http://www.freeformatter.com/credit-card-number-generator-validator.html#cardFormats) From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g., 7 * 2 = 14), then sum the digits of the products (e.g., 10: 1 + 0 = 1, 14: 1...

  • Could someone please help me with the following question? Please and thank you! A landscape architect...

    Could someone please help me with the following question? Please and thank you! A landscape architect bought 8 tons of soil, knowing that cach flower bed in the garden she was a. Solve this problem with a drawing. Include fractional amounts of flowerbeds if needed. b. Then, solve the problem again. Start by determining how many flower beds can be filled c. Write a statement of division and then a product to express your solution to this problem d. Justify...

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