#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<string>
using namespace std;
// Function to read square data from file
void readFile(string fileName)
{
// To store width and height
double width;
double height;
// To store calculated area and total area
double area;
double totalArea = 0;
// Counter for square
int c = 1;
int no;
// To store type of measurement
string type;
// ifstream objects declared to read data from file
ifstream readF;
// Opens the file for reading
readF.open(fileName.c_str());
// Checks if the file unable to open for reading display's error message and stop
if(!readF)
{
cout<<"\n ERROR: Unable to open the file "<<fileName<<" for reading.";
exit(0);
}// End of if condition
// Reads number of records and type of measurement
readF>>no>>no;
readF>>type;
// Loops till end of the file
while(!readF.eof())
{
// Reads a width and height from file
readF>>width>>height;
// Calculates area
area = width * height;
// Calculates total area
totalArea += area;
// Displays information
cout<<"\n Square #"<<c;
cout<<fixed<<setprecision(2)<<"\n \t Width: "<<width<<" "<<type;
cout<<"\n \t Height: "<<height<<" "<<type;
cout<<"\n \t Area: "<<area<<" square "<<type;
// Increases square counter
c++;
}// End of while loop
// Displays total area
cout<<"\n The total area of "<<no<<" squares is "<<totalArea<<" square "<<type;
// Close the file
readF.close();
}// End of function
// main function definition
int main()
{
// To store user choice to continue
char ch;
// To store file name
string fileName;
// Loops till user choice is not 'N' or 'n'
do
{
// Accepts file name from the user
cout<<"\n Enter the file name to test: ";
cin>>fileName;
// Calls the function to read data from file
// calculate area of square
readFile(fileName);
// Accepts user choice to continue
cout<<"\n Would you like to test another file(Y/N): ";
cin>>ch;
// Checks if user choice is not 'N' or 'n' then stop the loop
if(ch == 'N' || ch == 'n')
break;
}while(1);// End of do - while loop
return 0;
}// End of main function
Sample Output:
Enter the file name to test: areaData1.txt
Square #1
Width: 1.50 inches
Height: 2.50 inches
Area: 3.75 square inches
Square #2
Width: 2.50 inches
Height: 3.50 inches
Area: 8.75 square inches
Square #3
Width: 2.40 inches
Height: 1.40 inches
Area: 3.36 square inches
Square #4
Width: 4.10 inches
Height: 1.20 inches
Area: 4.92 square inches
Square #5
Width: 6.20 inches
Height: 7.30 inches
Area: 45.26 square inches
Square #6
Width: 3.80 inches
Height: 2.20 inches
Area: 8.36 square inches
The total area of 6 squares is 74.40 square inches
Would you like to test another file(Y/N): y
Enter the file name to test: areaData2.txt
Square #1
Width: 2.10 feet
Height: 3.20 feet
Area: 6.72 square feet
Square #2
Width: 0.50 feet
Height: 4.00 feet
Area: 2.00 square feet
Square #3
Width: 2.40 feet
Height: 1.40 feet
Area: 3.36 square feet
Square #4
Width: 4.10 feet
Height: 1.20 feet
Area: 4.92 square feet
The total area of 4 squares is 17.00 square feet
Would you like to test another file(Y/N): y
Enter the file name to test: areaData3.txt
Square #1
Width: 1.60 meters
Height: 3.40 meters
Area: 5.44 square meters
The total area of 1 squares is 5.44 square meters
Would you like to test another file(Y/N): y
Enter the file name to test: areaData9.txt
ERROR: Unable to open the file areaData9.txt for reading.
areaData1.txt file contents
2
6 inches
1.5 2.5
2.5 3.5
2.4 1.4
4.1 1.2
6.2 7.3
3.8 2.2
areaData2.txt file contents
1
4 feet
2.1 3.2
0.5 4.0
2.4 1.4
4.1 1.2
areaData3.txt file contents
0
1 meters
1.6 3.4
I need a code that would give me the desired result (the ones in green) from...
The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for the basis of how to do this. Once the input and output file paths have been received, the program will need to open the input and output files, read and process each input file line and create a corresponding output file line, close the input and output files, and then create and output some summary...
Need help with the code for this assignment. Python Assignment: List and Tuples We will do some basic data analysis on information stored in external files. GirNames.txt contains a list of the 200 most popular names given to girls born in US from year 2000 thru 2009: (copy link and create a txt file): https://docs.google.com/document/d/11YCVqVTrzqQgp2xJqyqPruGtlyxs2X3DFWn1YUb3ddw/edit?usp=sharing BoyNames.txt contains a list of the 200 most popular names given to boys born in US from year 2000 thru 2009 (copy link and create...
The
goal of this assignment is to practice one dimensional arrays.
Objective: The goal of this assignment is to practice one-dimensional arrays. Background: A local FedEx ship center needs support to compute volume of the packages that are delivered on each day Assignment: The shipping center manages deliveries of each day in a single text file. Each text file contains exactly three lines. Each line contains n double numbers representing a dimension of n boxes. The first line represents the...
I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know, for each word in the dictionary,...
Calculates the dimensions for various fish pond configurations. Specifically, the program will calculate the volume for the pond in cubic feet, the surface area of the sides and bottom of the fish pond, and the area of a 2-foot wide border around the edge of the pond.Ponds come in predefined sizes and shapes. There are: - circular ponds, diameter: 5 feet - square ponds, side: 5 feet - rectangular ponds, dimensions: 4 feet by 7 feet - ovoid ponds, dimensions:...
Can you give me this program working in C++ please
95% oo H20 LTE 9:01 PM ehacc hacc.edu HACC-Harrisburg Area Community Fahringer College CPS 161 Computer Science Program #7 20 points Program Due: Monday, March 21st Word Series Task: Write a program that displays the contents of the Teams txt file on the screen and prompts the user to enter the name of one of the teams. The program should then display the number of times that team has won...
******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...
I need this Program code made for Java please with the sample
results.
Echo Input from the Console to the Screen Using Methods
Review the resources and instructions in the Discussion Prep
Study before completing this discussion.
For this discussion, you practiced using Java methods to echo
input from the console to the screen. Create a Java program that
reads in any value entered at the console and then prints it out to
the screen. The program must have at...
I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...
I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well. Purpose Learn how to use Java input/output. Due Date Per the Course at a Glance. Can be resubmitted. Submissions In this order: printed copy of...