Write a program that generates all the factors of a number

Assignment Help Programming Languages
Reference no: EM13165789

Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3. This program has the following requirements:

 

A. The user must enter a positive integer. If the user enters something else, your program should output an error message and let the user enter a new value. Use a do/while loop to make sure the user input is successful.

 

B. The factors must be output in increasing order. The lowest factor your program should report is 2.

 

C. Your program should output 4 factors per line, each factor in a field of 10 characters. (Hint: the number of factors output determines when to output endl!)

 

D. You will need a while loop to report the factors. Here are some helpful hints:

 

1. If (a % b == 0) then a is a factor of b.

 

2. When you have found a factor, output the factor and then reduce the number you are working with by dividing the number by the factor... ie) b = b / a;

 

1. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get each input and to report the output. Include steps to deal with error cases as specified above.

 

 

2. Identify three test cases, one using a number with 4 factors, one using a negative number, and one using a number with more than 4 factors. For each of the three test cases show what inputs you will use and what your expected outputs should be.

 

 

 

3. Write the program to implement your algorithm. Test your program using your test cases.

 

 

 

 

 

Programming Problem 2

 

This program is designed to analyze the growth of two cities. Each city has a starting population and annual growth rate. The smaller city has the larger growth rate (required). Show the comparative populations of each city year by year until the smaller city has grown larger than the bigger city.

 

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown has a population of 7000 growing at 10% annually. The projected populations are:

Year Dogville Cattown

1 6000 7700

2 7200 8470

3 8640 9317

4 10368 10249

 

1. Identify the inputs and outputs of the problem.

 

 

2. Identify the processing needed to convert the inputs to the outputs.

 

 

3. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get each input and to report each output.

 

 

4. Identify three significant test cases including one for incorrect input (ie Small town has lower growth rate). For each of the three test cases show what inputs you will use and calculate what your expected outputs should be.

 

 

 

5. Write the program to implement your algorithm. Test your program using your test cases.

 

 

Reference no: EM13165789

Questions Cloud

Javascript program that asks the use : Design a javascript program that asks the user for a username with at least eight characters, beginning with a letter and including at least one digit. Next, write a validation loop to ensure that these conditions have been met
Design, simulate and verify a 16-bit ripple-carry : Design, simulate and verify a 16-bit ripple-carry adder by performing the following additions/subtractions (the values of a and b are given in decimal): (i) (-10) + (100), (ii) (63) - (-127), (iii) (15) + (95), (iv) (-32) + (79), (v) (-59) + (-16)..
Displays a single character at 100 random screen : Write a program that displays a single character at 100 random screen locations, with a delay factor of 100 milliseconds.Hint: set the console window screen height to 200 at runtime.
Populate a one-dimensional array : Populate a one-dimensional array with the following grades in this order: 93, 61, 72, 45, 84, 51, 70, 83, 96, and 66. Use a loop to call a method from main() that adds
Write a program that generates all the factors of a number : Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3.
Java method for radix sort in binary : java method for radix sort in binary but I want to understand how to do it so please make it as simple as possible
C string and two int reference parameters : Write a complete function, not an entire program, that has a C string and two int reference parameters (call them a and b), returning nothing.
Reads a line of characters from the user : Write a segment of code (not an entire program) that reads a line of characters from the user and outputs "too long" if the user enters more than 5 characters (not counting hitting the enter/return key).
The "continue" and "break" statements : How are the "continue" and "break" statements different from the "exit" and "return" statements?

Reviews

Write a Review

Programming Languages Questions & Answers

  Describe issues-web site designers when adding multimedia

Describe some of the issues web site designers must consider when adding multimedia to a web site. Consider issues such as bandwidth, server load, or others you consider to be important. Please provide references.

  Create set-list of enumerated constants called week

Create set/list of enumerated constants called week which contains days of week. Have variable called today that is of kind week. Allot a value to today.

  Write a program to read student data from standard input

Write a program to read student data from standard input, sort it by last name / first name, and print result to standard output.

  Write function to receive two passed parameters single value

Write down the function which will receive as two passed parameters single precision value for product price and integer value for quantity.

  Program to overload addition operator

The class should also provide the following overloaded operator capabilities: Overload the addition operator (+) to add two Polynomials.

  Explaining law of diminishing returns

As computer word size gets larger and larger, there is a law of diminishing returns; speed of execution of application programs doesn't increase and may, in fact, decrease.

  Create class uses element array of digits to store integers

Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods input, output, add and subtract.

  Develop the algorithms needed for designer robot

You have been hired as a system designer to develop the algorithms needed for a designer robot that can paint different patterns on the floor based on the commands it receives.

  Program to accept inputs from user beginning temperature

Physicists tell us that lowest possible temperature is absolute zero. Absolute zero is -459.69 degrees Fahrenheit. Accept inputs from user: a beginning temperature, ending temperature, and increment value (all Fahrenheit).

  Use shared mutex for synchronization and locking mechanism

Execute two programs of matrix multiplication with thread programming. Use the shared mutex for synchronization and locking mechanism.

  Write program to input number of hours worked

Write a program that allows the user to input the number of hours worked and hourly pay rate for employees and outputs their total pay.

  Program to read an employee-s number from keyboard

Write a program that reads an employee's number from the keyboard, number of hours worked and an hourly rate of pay.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd