Please answer question in C++, thank you.
Read in name of input file. File will be formatted as below:
filename: triangles1.txt
3 4 5 7 7 7
For each line read in the 3 integer values as the 3 sides of a triangle and calculate the area and print on output line with two decimal points.
C++ CODE:
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
using namespace std;
/* main function begins*/
int main()
{
char filename[30];
cout<<"Enter the filename: ";
cin>>filename;
/* opening the file */
ifstream infile(filename);
//variables to store the perimeter
double perimeter;
double p;
if(infile.fail())
{
cout<<"ERROR: File not
found";
}
//variables to store the integers
int a, b,c;
//reading line by line
while (infile >> a >>
b>> c)
{
//calculating
the perimeter
perimeter=a+b+c;
p=perimeter/2;
//calculating the area using heron's formula
double
area=sqrt(p*(p-a)*(p-b)*(p-c));
//displaying the details
cout<<"side 1: "<<a<<endl;
cout<<"side 2: "<<b<<endl;
cout<<"side 3: "<<c<<endl;
cout<<"Area :
"<<area<<fixed<<setprecision(2)<<endl;
cout<<"\n"<<endl;
}
}
CONTENTS OF triangles.txt:
3 4 5 7 7 7
12 5 8
SCREENSHOT FOR OUTPUT:
Please answer question in C++, thank you. Read in name of input file. File will be...
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
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...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
please help in matlab!!! Thank you so much in advance! Modify fn = input('input file name:', 's' ); ofn = input('output file name: ','s' ); ih = fopen( ifn,'r'); oh = fopen( ofn,'w' ); ln = ''; while ischar( ln ) ln = fgets( ih ); if ischar( ln ) fprintf( oh, ln ); end end fclose( ih ); fclose( oh ); % fprintf( oh, ln ) has a paramter oh of file %handle. Ln is written to the...
Python Please, If possible, please continue with/ use code already given File Commands: u/a Write a function named, file_commands, that takes the name of a file as a parameter. The function processes the contents the file as follows: For file lines that begin with the letter 'a', calculate & print the integer average of the numbers on the line. For file lines that begin with the letter 'u', print the upper case format for each word following the u. Sample...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
in c prog only please!! Name this program one.c - This program takes two command line arguments: 1. an input filename 2. a threshold Your program will create two files: 1. even.txt - contains all integers from the input file that are even and greater than the threshold 2. odd. txt - contains all integers from the input file that are odd and greater than the threshold • The input file will exist and only contain a set of integers....
Write a program that will first receive as input the name of an input file and an output file. It will then read in a list of names, id #s, and balances from the input file specified (call it InFile.txt) which you will create from the data provided below. The program will then prompt the user for a name to search for, when it finds the name it will output to a file (call it OFile.txt) the person’s id#, name,...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...