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

I\'m having trouble figuring out where to take this particular c++ assignment. T

ID: 3623270 • Letter: I

Question

I'm having trouble figuring out where to take this particular c++ assignment. The directions are:

Define the function f(x; y) as:
f(x, y) = sqrt(x^2-y^2)

Write a program that produces a table of f(x, y) for integers x and y from 0 to n where
y <= x. The value of f(x, y) appears in row (x+1), column (y +1) of the table. The number
of rows in the table is determined by the user. Format the table so that the columns align
and decimal points align.

(a) Prompt and read in the number of table rows. (You do not need to check that this
number is positive.) If the table has m rows, then the table will contain f(x; y)
for x and y from 0 to m - 1.
(b) Use two nested for loops to print your table, looping over the values of x and y.
Note that x and y should be integers and should both start at 0. Note also that
y should be less than or equal to x.
(c) Print the output in fixed precision with one digit after the decimal point. Columns
and decimal points should be aligned.

This is my code so far, I'm just not sure how to set this up:

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

int main()
{

int n; // Number of rows declared by the user
int i; // Counting variable for number of rows
int x,y,y2; // x and y variables

cout << "Enter number of rows: ";
cin >> n;

while (n<0)

{
cout << "Number must be positive " << endl;

cout << "Enter number of rows: ";
cin >> n;

}

cout.precision(1);

Explanation / Answer

#include<iostream>
#include<math.h>
using namespace std;
inline double f(int x,int y)
{
return x*x-y*y;
}
int main()
{

int n; // Number of rows declared by the user
int i; // Counting variable for number of rows
int x,y,y2; // x and y variables
cout << "Enter number of rows: ";
cin >> n;

while (n<0)

{
cout << "Number must be positive " << endl;

cout << "Enter number of rows: ";
cin >> n;

}
cout.precision(1);
for(int x=0; x<n; x++)
    for(int y=0; y<n; y++)
    if(y<=x) cout << x << " " << y << " "<< f(x,y)<<endl; ;
return 0;
}

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