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

In C++ #include <iostream> #include <fstream> #include <math.h> using namespace

ID: 3677002 • Letter: I

Question

In C++

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;


const int PI = 3.14159265;


int theta(int Q1, int Q2)
//PRE: Assign Q1, Q2
//POST: Q1 to be shifted 2 and Q2 to be shifted 6 units
{
Q1 = Q1 + 2;
Q2= Q2 + 6;

return atan((Q1/Q2) * PI / 180.0);
}

void getThere(int A1[], int A2[], const int n)
//PRE: Assign A1, A2, and size from [0....n-1]
//POST: Writing data to a file
{
bool found = true;
ofstream outfile;
int i;
int r;
double ANG;


  
if (found)
{
while (i < n)
{
r = sqrt((pow(A1, 2) + pow(A2,2));
ANG = theta(A1,A2);
outfile << "(" << A1 << "," << A2 << ") ---> (" << r << ", " << ANG << ")" << endl;
i++;
}
}
outfile.close();
}

int main()
{
// INPUT
const int MAX_SIZE = 1000;
ifstream infile;
int Array1[MAX_SIZE];
int Array2[MAX_SIZE];
infile.open("input.dat");
int i = 1;
int count = 0;
double x;
double y;
double GetThere;

//


while (!infile && i < MAX_SIZE)
{
infile >> x >> y;
if (x < 0 || y < 0)
{
cout << "Read point (" << x << ", " << y << ")" << ", which is not in Quadrant I...ignoring." << endl;
}
else
{
Array1[count] = x;   
Array2[count] = y;
count++;
}
i ++;
if (i % 10 == 0)
{
cout << "Successfully read " << i << " lines of input so far." << endl;
}


infile.close();

getThere(Array1, Array2, MAX_SIZE);

cout << "Data has been output to file outputs.dat, where each line contains r, then theta, with a space between." << endl;
}


return 0;
}

Need to compile to get the following output please !!!!!

Explanation / Answer

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

const int PI = 3.14159265;

double theta(int Q1, int Q2)
//PRE: Assign Q1, Q2
//POST: Q1 to be shifted 2 and Q2 to be shifted 6 units
{
Q1 = Q1 + 2;
Q2= Q2 + 6;
return atan((Q1/Q2) * PI / 180.0);
}
void getThere(int A1[], int A2[], const int n)
//PRE: Assign A1, A2, and size from [0....n-1]
//POST: Writing data to a file
{
bool found = true;
ofstream outfile;
int i;
double r;
double ANG;

if (found)
{
   while (i < n)
   {
   r = sqrt((pow(A1[i], 2) + pow(A2[i],2));
   ANG = theta(A1[i],A2[i]);
   outfile << "(" << A1 << "," << A2 << ") ---> (" << r

<< ", " << ANG << ")" << endl;
   i++;
   }
}
outfile.close();
}
int main()
{
// INPUT
const int MAX_SIZE = 1000;
ifstream infile;
int Array1[MAX_SIZE];
int Array2[MAX_SIZE];
infile.open("input.dat");
int i = 1;
int count = 0;
double x;
double y;
double GetThere;
//

while (!infile && i < MAX_SIZE)
{
   infile >> x >> y;
   if (x < 0 || y < 0)
   {
   cout << "Read point (" << x << ", " << y << ")" <<

", which is not in Quadrant I...ignoring." << endl;
   }
else
{
Array1[count] = x;   
Array2[count] = y;
count++;
}
i ++;
if (i % 10 == 0)
{
cout << "Successfully read " << i << " lines of input so

far." << endl;
}

infile.close();
getThere(Array1, Array2, MAX_SIZE);
cout << "Data has been output to file outputs.dat, where each

line contains r, then theta, with a space between." << endl;
}


return 0;
}