Question

In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all...

In C++ Programming

Write a program in a file named SeedFinder.cpp that finds and displays all the seeds of a integer given by the user. Let’s define a seed of an integer, n, to be a positive value that equals n when multiplied by its individual digits. For example, 23 is a seed of 138 because 23 × 2 × 3 = 138. 111 is an example of a seed of itself because 111 × 1 × 1 × 1 = 111. Many numbers have no seeds (e.g., 2) and some numbers have multiple seeds (e.g., 24 and 32 are seeds of 192).

Implement the following functions as parts of your overall solutions:

  1. getPositiveWholeNumber: This function asks the user for a positive whole number (integer) repeatedly until the input is correct. The number is then returned. You can assume that the user will only input whole numbers, but you need to check if they are positive.
  2. checkIfSeed: This function takes two parameters: (1) the number with possible seeds and (2) a possible seed to check. The function returns a bool. The function returns true if the possible seed is in face a seed of the first parameter; otherwise, the function returns false. The function should first check if the number is divisible by the possible seed, otherwise it cannot be a seed and no further checks are necessary. If the number is dividable by the possible seed, multiple the seed by each of its digits using a loop. Finally, compare that product with number. Hint: use the modulus operator to extract the last digit of a number and divide by 10 to remove the last digit of a number.
    This function should not get any input from the user or display any information (i.e., do not use cin or cout in this function).
  3. findAndDisplaySeeds: This is a void function that accepts a single integer as a parameter. The function should output "The seed(s) of N are:" (but replacing N with the parameter's value). After that, find and display each seed by looping through each possible seed value for the parameter and using checkIfSeed to see which values should be displayed. Output the word "none" if no seed values were found.
  4. The main function should simply display the header “--- Seed Finder ---”, call getPositiveWholeNumber(), and then findAndDisplaySeeds(). Also, it may define any variables that are necessary.

Make sure your programs output matches the format of the example output.

Sample Output (user input is in yellow)

--- Seed Finder ---

Enter a positive whole number: -1

Enter a positive whole number: 0

Enter a positive whole number: 24

The seed(s) of 24 are:  12.

Sample Output (user input is in yellow)

--- Seed Finder ---

Enter a positive whole number: 289

The seed(s) of 289 are: none.

Sample Output (user input is in yellow)

--- Seed Finder ---

Enter a positive whole number: 549504

The seed(s) of 549504 are:  1696  2862  3392  3816.

ACTIONS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include <iostream>
#include <math.h>

using namespace std;

long long int getPositiveWholeNumber() {
   long long int number;
   do {
       cout << endl << "Enter a positive whole number: ";
       cin >> number;
   } while (number <= 0);

   return number;
}

bool checkIfSeed(long long int number, long long int possibleSeed) {
   if (number % possibleSeed == 0) {
       long long int result = possibleSeed;
       while (possibleSeed > 0) {
           int remainder = possibleSeed % 10;
           result *= remainder;
           possibleSeed /= 10;
       }

       if (result == number)
           return true;
       else
           return false;
   }
   else
       return false;
}

void findAndDisplaySeeds(long long int number) {
   //it becomes true when at least one seed is found
   bool flag = false;

   cout << endl << "The seed(s) of " << number << " are: ";
   for (long long int i = 2; i <= number / 2; i++) {
       if (checkIfSeed(number, i)) {
           cout << i << " ";
           flag = true;
       }
   }
   if (!flag)
       cout << "none";

   cout << "." << endl << endl;
}

int main()
{
   cout << "_________ SEED FINDER _________";

   long long int number;
   number = getPositiveWholeNumber();

   findAndDisplaySeeds(number);
}

OUTPUT

GR. C:\WINDOWS\system32\cmd.exe SEED FINDER Enter a positive whole number: -1 Enter a positive whole number: 0 Enter a positi

PLEASE MAKE SURE TO LIKE THE ANSWER. IF YOU HAVE ANY QUERY ABOUT THE ANSWER, THEN FEEL FREE TO ASK IN COMMENTS. THANKS SO MUCH IN ADVANCE.

Add a comment
Know the answer?
Add Answer to:
In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all...
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
  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • Programming Problem HW1 Question 1

    Write a function createNum() that takes as a parameter an integer n, builds an n -digit integer using input from the user, and returns the integer. The function repeatedly prompts the user to enter single, positive (>0) digits and creates a number out of them, with the first valid digit entered being the most significant and the last valid digit entered being the least significant. If the user enters a zero, a negative number, more than one digit, or anything...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".

    Project DescriptionWrite a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".Project SpecificationsInput for this project:the user must enter the number of employees in the company.the user must enter as integers for each employee:the employee number (ID)the number of days that employee missed during the past year.Input Validation:Do not accept a number less than 1 for the number of employees.Do not accept a negative...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

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