I NEED HELP finishing this program its the last one i have. //******************
ID: 3546228 • Letter: I
Question
I NEED HELP finishing this program its the last one i have.
//***************************************************************************************************************
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "Circle.hpp"
using namespace std;
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using a counting loop.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas1(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using a counting loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
???
// Define an int variable named n and read the first integer from fin into n.
???
// Write a counting loop that will execute n times.
???
// Define three int variables named x, y, and r. Read three integers from fin into x, y, and r.
???
???
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
???
// Display the area of c by calling the Area() function.
???
// End the loop
???
// Close the input file stream.
???
cout << endl;
}
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using a sentinel loop. The sentinel is -1 for x.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas2(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using a sentinel loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
???
// Define three int variables named x, y, and r. Read three integers from fin into x, y, and r.
???
// While x is not the sentinel value Do
???
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
???
// Display the area of c by calling the Area() function.
???
// Read three integers from fin into x, y, and r.
???
// End the loop
???
Burger :: Computer Science & Engineering :: Arizona State University Page 3
CSE100 Principles of Programming with C++ Homework Assignment 3 :: 25 pts
// Close the input file stream.
???
cout << endl;
}
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using an end of file loop.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas3(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using an EOF loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
???
// Define three int variables named x, y, and r.
???
// Write an end of file loop that reads an integer from fin into x in the conditional expression
???
// Read two integers from fin into y and r.
???
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
???
// Display the area of c by calling the Area() function.
???
// End the loop
???
// Close the input file stream.
???
cout << endl;
}
int main()
{
cout << fixed << setprecision(3);
PrintAreas1("Circles1.txt");
PrintAreas2("Circles2.txt");
PrintAreas3("Circles3.txt");
return 0;
}
Assume the Circle class functions are implemented in Circle.cpp. The figure below shows three Circle objects, c1, C2, and c3 drawn on a window of dimensions 450 x 350. The center of C1 is at (126, 119) and the radius is 72. Suppose the information for several circil objects is stored in three text files named Circles1.txt, Circle2.txt, andExplanation / Answer
//***************************************************************************************************************
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "Circle.cpp"
using namespace std;
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using a counting loop.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas1(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using a counting loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
ifstream fin(pFname.c_str());
// Define an int variable named n and read the first integer from fin into n.
int n;
fin>>n;
// Write a counting loop that will execute n times.
int i;
for(i=0;i<n;i++){
// Define three int variables named x, y, and r. Read three integers from fin into x, y, and r.
int x,y,r;
fin>>x>>y>>r;
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
Circle c(x,y,r);
// Display the area of c by calling the Area() function.
c.Area();
// End the loop
}
// Close the input file stream.
fin.close();
cout << endl;
}
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using a sentinel loop. The sentinel is -1 for x.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas2(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using a sentinel loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
ifstream fin(pFname.c_str());
// Define three int variables named x, y, and r. Read three integers from fin into x, y, and r.
int x,y,z;
fin>>x>>y>>z;
// While x is not the sentinel value Do
while(x!=-1){
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
Circle c(x,y,r);
// Display the area of c by calling the Area() function.
c.Area();
// Read three integers from fin into x, y, and r.
fin>>x>>y>>r;
// End the loop
}
//Burger :: Computer Science & Engineering :: Arizona State University Page 3
//CSE100 Principles of Programming with C++ Homework Assignment 3 :: 25 pts
// Close the input file stream.
fin.close();
cout << endl;
}
//---------------------------------------------------------------------------------------------------------------
// Reads a file containing information for several circles using an end of file loop.
//---------------------------------------------------------------------------------------------------------------
void PrintAreas3(string pFname)
{
cout << "Printing the areas of the circles in " << pFname << " using an EOF loop." << endl;
// Define ifstream object named fin and open the file with name pFname for reading. Note: to open the file
// for reading, you must pass pFname.c_str() as the argument to the ifstream ctor.
ifstream fin(pFname.c_str());
// Define three int variables named x, y, and r.
int x,y,r;
// Write an end of file loop that reads an integer from fin into x in the conditional expression
while(fin>>x){
// Read two integers from fin into y and r.
fin>>y>>r;
// Define and create a Circle object named c passing x, y, and r as arguments to the ctor.
Circle c(x,y,r);
// Display the area of c by calling the Area() function.
c.Area();
// End the loop
}
// Close the input file stream.
fin.close();
cout << endl;
}
int main()
{
cout << fixed << setprecision(3);
PrintAreas1("Circles1.txt");
PrintAreas2("Circles2.txt");
PrintAreas3("Circles3.txt");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.