Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi i need help with these qeustions here and the source codes. Programming Probl

ID: 655017 • Letter: H

Question

hi i need help with these qeustions here and the source codes.

Programming Problem 1

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

Explanation / Answer

#include <iostream> //for input/output stream
#include <iomanip> //for manip setw
#include <string> //for string and function getline
using namespace std;
int main()
{
int popSmall, popLarge, year = 1; //population variables
double groRate1, groRate2; //growth rate of small and large city
string smallCity, largeCity;
cout << "What is the name of the smaller city?" << endl;
getline (cin, smallCity); //get the whole name of the small city
cout << "What is the name of the larger city?" << endl;
getline (cin, largeCity); //get the whole name of the large city
do
{
cout << "What is the population of ";
cout << smallCity << endl;
cin >> popSmall; //get population of smmall city
cout << "What is the population of ";
cout << largeCity << endl;
cin >> popLarge; //get population of large city
if (popSmall >= popLarge)
{
cout << "The smaller city should have the smallest population";
cout << endl;
} //if small pop is greater than or equal to large pop output "The smaller city....."
}
while (popSmall >= popLarge); //while the population of small city is more than large city redo loop
do
{
cout << "What is the annual growth rate of ";
cout << smallCity << endl;
cin >> groRate1; //get annual growth rate of small city
cout << "What is the annual growth rate of ";
cout << largeCity << endl;
cin >> groRate2; //get annual growth rate of large city
if (groRate1 <= groRate2)
{
cout << "Annual growth rate of smaller city should be larger ";
cout <<"than annual growth rate of larger city.";
cout << endl;
} //if growth rate of small city is less than growth rate of large city output "Annual growth rate......."
}
while (groRate1 <= groRate2); //while growth rate of small city is less than growth rate of large city redo loop
cout << "The projected populations are:"; //beginning of output
cout << endl << endl; //skip two lines for easier to read format
cout << "Year";
cout << setw (10); //output year and skip 10 spaces
cout << smallCity;
cout << setw (15); //output smallCity value and skip 15 spaces
cout << largeCity;
cout << endl; //output largeCity value and endline
while (popSmall <= popLarge) //while statement: loop below repeats until the pop of small city is great than pop of large city
{
popSmall = popSmall*groRate1+popSmall;
popLarge = popLarge*groRate2+popLarge; //formulas to find yearly pop growth of small and large city
cout << year;
cout << setw (10); //year number output and skip 10 spaces
cout << popSmall;
cout << setw (15); //output popSmall value and skip 15 spaces
cout << popLarge;
cout << endl; //output popLarge value and endline
year++; //add 1 to variable year in order show progress from year 1, year 2, year 3, etc.
}
system ("pause"); //used to keep cmd open for execution test.
return 0;
}
}