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

Write a function int CircleStats( double r, double &d, double &c, double &a ); w

ID: 653015 • Letter: W

Question


Write a function
int CircleStats( double r, double &d, double &c, double &a );
which takes the radius (r) of a circle, and sets, into variables in the calling code, the diameter (d), circumference (c), and the area (a) of the circle. if radius is 0 or negative, return -1, otherwise return 0.
The diameter is twice the radius, the circumference is 2(pi)R, and the area is pi(r2). Use a named constant for PI
Write a main() function that opens two files, one for input and another for output, verifies that the file works, loops reading values from the input file stopping at end-of-file, calls CircleStats() for each value, then prints either an appropriate error message if -1 is returned or the resulting values if O.K. Hard-code the file names as string literals in the program, e.g. "input.txt". Print the radius before calling CircleStats(). Format the output into columns.

Explanation / Answer

import java.util.Scanner;
public class Circle2
{
   public static void main( String args[] )
   {
       Scanner fin = new Scanner(new File("input.txt"));
       final int pi = 3.14159;
       double radius, area;
       radius = fin.nextDouble();
       area = pi*radius*radius;

       System.out.print(

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