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

radius float diameter float area float You may assume a maximum of 20 records. Y

ID: 3546818 • Letter: R

Question

radius float diameter float area float                 

You may assume a maximum of 20 records. You may want to include the                 

cmath library.                 

You need to know the formulas for finding the area and circumference of a circle.                 

This assignment is very similar to the program in Lab 12.3.                 

Sample Run:                 

Enter the following information: Radius of circle: 5                 

Enter a Y if you would like to input more data                 

y                 

Enter the following information: Radius of circle: 4                 

Enter a Y if you would like to input more data                 

y                 

Enter the following information: Radius of circle: 7                 

Enter a Y if you would like to input more data                 

n                 

                    That

Explanation / Answer

#include <fstream>

#include <iostream>

#include <cctype> // for toupper function using namespace std;

struct Grades // declaring a structure

{

float radius;

};


int main()

{

char ch;

float area;

float circum;


fstream tests("circle.dat", ios::out | ios::binary);

// defines tests as an output binary file

Grades student; // defines student as a record (struct)

char more; // used to determine if there is more input

do

{

cout << "Enter the radius: ";

cin >> student.radius;

cin.ignore();

// write this record to the file

tests.write((char *) &student, sizeof(student));

cout << "Enter a y if you would like to input more data ";

cin >> more;

cin.ignore();

}

while (toupper(more) == 'Y');


tests.close();

fstream in("circle.dat", ios::in | ios::binary);

fstream out("circle_output.dat", ios::out | ios::binary);

out << "Radius Area Circumferene" << endl;

while ((ch = in.peek()) != EOF) // no need to prime the read

{

infile >> radius;

infile.ignore(10,' '); // ignores the rest of the line

// and consumes end of line marker

area = 3.14 * radius*radius;

circum = 2*3.14*radius;

outfile << radius << setw(3) << area << setw(2) << circum << endl;

}

in.close();

out.close();


return 0;

}