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

  Design program that determines males live in zip code area

Design a program that determines how many males and females live in each of the Zip Code areas in the Student Enrollment Records Set.

  Write down script to report cumulative size of all files

Write down script which will report cumulative size of all files in and below given directory. Your script will also report name and size (in bytes) of largest file with that directory tree.

  Write constructor which needs two string parameters

Generate a class named Student which includes String data fields for firstName and lastName. Prepare a constructor which needs two String parameters to populate firstName and lastName fields.

  Statements to find array elements are null or not

Write down statements needed to find whether any of the array elements are null or refer to the empty String. Set the variable hasEmpty to true.

  Projects for the falling letters game

Design and implement two projects for the Falling Letters game using C# and Windows Presentation Foundation (WPF) template in Visual Studio 2012 or newer.

  Write class postfixevaluator to evaluate postfix expression

Write a class PostFixEvaluator that evaluates postfix expression such as 6 2 + 5 * 8 4 / -. Program must read a postfix expression consisting of digits and operators into a StringBuffer.

  Design gui application with jframe to enter series of names

Design  GUI application with JFrame which permits user to enter series of friends' names and phone numbers. Each time user clicks the button, data entered must be written to sequential access file.

  Create a menu type form that gives user to select subforms

Create a menu type form that provides the user the capability to select one of the following two subforms. Means of selection is programmers choice.

  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.

  Program to read employee information into array of objects

Consider a program that will read employee information into an array of objects, sort the array by employee identification number, write out the sorted array.

  Create a college course to display the course data

Create a CollegeCourse that does not include the lab fee. Then display the course data. Save the files as CollegeCourse.java, LabCourse.java, and UseCourse.java.

  Xhtml page to display current date time in client-s computer

Create the XHTML page which will display current date time in client's computer. Use document.write method in immediate script.

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