Write a program rootTable.cpp which reads in the number of roots, a value increm
ID: 3528388 • Letter: W
Question
Write a program rootTable.cpp which reads in the number of roots, a value increment and a precision and outputs a table of roots x1=2; x1=3; : : : for the given number of roots and values of x equal to i times the increment up to and including 100. For instance, if the number of roots is 10, and the precision is 2 and the increment is 10, then the table should be: Value x^1/2 x^1/3 x^1/4 x^1/5 x^1/6 x^1/7 x^1/8 x^1/9 x^1/10 x^1/11 10 3.16 2.15 1.78 1.58 1.47 1.39 1.33 1.29 1.26 1.23 20 4.47 2.71 2.11 1.82 1.65 1.53 1.45 1.39 1.35 1.31 30 5.48 3.11 2.34 1.97 1.76 1.63 1.53 1.46 1.41 1.36 40 6.32 3.42 2.51 2.09 1.85 1.69 1.59 1.51 1.45 1.40 50 7.07 3.68 2.66 2.19 1.92 1.75 1.63 1.54 1.48 1.43 60 7.75 3.91 2.78 2.27 1.98 1.79 1.67 1.58 1.51 1.45 70 8.37 4.12 2.89 2.34 2.03 1.83 1.70 1.60 1.53 1.47 80 8.94 4.31 2.99 2.40 2.08 1.87 1.73 1.63 1.55 1.49 90 9.49 4.48 3.08 2.46 2.12 1.90 1.76 1.65 1.57 1.51 100 10.00 4.64 3.16 2.51 2.15 1.93 1.78 1.67 1.58 1.52 1. Prompt and read in the number of roots. Store the number as an integer. 2. Prompt and read in the value increment. Store the number as an integer. 3. Prompt and read in the precision. Store the number as an integer. 4. Compute the width of each column based upon the precision. All columns after the rst should have the same width. All columns should be separated by a blank space. Note that you need a minimum column width to properly display the column headers. However, for greater precision, your column width should increase with the precision. 5. Write a header row for the table. Use the column width to correctly adjust the column headers. Note that you will have to handle columns headers x^1/i dierently when i is a single digit (i < 10) or when i is two digits (i <= 10). You may assume that i has at most two digits. 6. Write the rows of the table. The rst column is x. The i'th column is the value of x1=i. Use xed precision and the given number of digits after the decimal point specied by the precision. The decimal points in each column should line up. This is my code thus far. Everything seems to work except for the gaps between columns. Please help me tweak this to work. #include #include #include using namespace std; int main() { // define initial variables int roots(0); // number of roots to calculate int increment(0); // increments between values int precision(0); // precision of decimal outputs int columnw(0); // stored value for column width float x(0); // counter for x variable // prompt user for inputs cout << "Enter number of roots: "; cin >> roots; cout << "Enter value increment (integer): "; cin >> increment; cout << "Enter precision: "; cin >> precision; // calculate width of column columnw = precision + 3 + 2; if(columnw < 7) { columnw = 7; } // program for table cout << "Value"; cout << setw(precision + 2); for(int i = 2; i < roots + 2; i++) { if(i < 10) { cout << right << setw(columnw - 1) << " x^1/" << i; } else { cout << right << setw(columnw - 2) << " x^1/" << i; } } cout << fixed; cout << setw(columnw); for(int i = increment; i <= 100; i += increment) { x = i; cout << right << setprecision(0) << endl; cout << setw(5) << x; for(int j = 2; j < roots + 2; j++) { cout << setprecision(precision); cout << pow((double)i,1.0/j) << " "; } } return(0); }Explanation / Answer
#include#include#include#include void main() { clrscr(); int roots,pre,incre; float temp; coutroots; coutpre; coutincre; clrscr(); for(int i=incre;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.