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

Due Fri., March 3 d by 5:00pm Tip: this assignment is great practice for Exam A2

ID: 3811862 • Letter: D

Question

Due Fri., March 3 d by 5:00pm Tip: this assignment is great practice for Exam A2. Part 1-Program Description Proble You are to create a program that outputs a of numbers and a set of calculations include performed on them. Ask the user for a starting point and the number of they would like to h in the table. You are to output the following table values for -n n by ieac n n2 n3 Vin Vn ceiling(n) floor (m) For example, here is the output for 8 lines starting at 2.0 lease enter the desired number of lines in your table: floor n 3 square-root cube root ceiling 1.4142 1 4.4100 3.2610 1.4491 10,6480 1570 1.5156 4 5.7600 13.8240 1.3389 15.6250 1.6125 17.5760 1.6432 Requirements: what input parameters and return 1. You will write the following functions. Think carefully about values (if any) these functions need to have to work correctly. Do not use global variables, global variables o points on the assignment. a. getStartingvalue i. Prompt the user for the starting point (a double) which must be at least oo. Return this value from the function for later use. ii. Perform input validation inside the function to ensure that a negative number is not entered. use ado...while loop (not a while loop) for input validation. a negative number is entered, ask for a new input for the starting point. b, get NumLines i. Prompt the user for the number of lines to print (an int) which must be greater than 0. Return this value from the function for later use. ii. Perform input validation inside the function to ensure that a positive number is entered. Use a do...while loop (not a while loop) for input validation. lf a negative number or zero isentered, ask for a new input for the number of lines. c, print Header i. Print the header forthe table, including the labels for each column (n, nn2, etc). d. print Border i. Print the border that will appear at the top and bottom of the table. e. print Table

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//function declarations
int getStartingValue();
int getNumLines();
void printHeader();
void printBorder();
void printTable(double n, int lines);

int main()
{
   double n;
   int lines;
   n = getStartingValue();
   lines = getNumLines();
   printHeader();
   printBorder();
   printTable(n,lines);
   printBorder();
}

int getStartingValue()
{
   double value;
   cout << "Please enter a starting vale" << endl;
   cin >> value;
   return value;
}
int getNumLines()
{
   int lines;
   cout << "Please enter the desired number of lines in your table"<<endl;
   cin >> lines;
   return lines;
}
void printHeader()
{
   cout << endl;
   //cout << setw(8) << "n" << " " << setw(8) << "n^2" << " " << setw(8) << "n^3" << " " << setw(8) << "Square_root" << " " << setw(8) << "cuber_root" << " " << setw(6) << "ceiling" << " " << setw(6) << "floor" << endl;
   cout << setw(8) << "n" << " " << setw(8) << "n^2" << " " << setw(8) << "n^3"<< " " << setw(8) << "square_root" << " " << setw(6) << "cube_root" << " " << "ceil" << " " << setw(6) << "floor" << endl;
}
void printBorder()
{
   cout << "--------------------------------------------------------------------------------" << endl;
}
void printTable(double n, int lines)
{
   //cout << fixed << setprecision(1) << n;
   for (int i = 0; i < lines; i++)
   {
       cout << fixed << setprecision(1) << setw(8) << n << " " << fixed << setprecision(4) << setw(8) << pow(n, 2) << " " << fixed << setprecision(4) << setw(8) << pow(n, 3) << " " << fixed << setprecision(4) << setw(8) << sqrt(n) << " " << fixed<<setprecision(4) << setw(6) << cbrt(n) << " " << (int)ceil(n) << " " << setw(6) << (int)floor(n) << endl;
       n = n + 0.1;
   }
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

//output

Please enter a starting vale
2.0
Please enter the desired number of lines in your table
8

n n^2 n^3 square_root cube_root ceil floor
--------------------------------------------------------------------------------

2.0 4.0000 8.0000 1.4142 1.2599 2 2
2.1 4.4100 9.2610 1.4491 1.2806 3 2
2.2 4.8400 10.6480 1.4832 1.3006 3 2
2.3 5.2900 12.1670 1.5166 1.3200 3 2
2.4 5.7600 13.8240 1.5492 1.3389 3 2
2.5 6.2500 15.6250 1.5811 1.3572 3 2
2.6 6.7600 17.5760 1.6125 1.3751 3 2
2.7 7.2900 19.6830 1.6432 1.3925 3 2
--------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote