
Convert Code Into Python and Eliminate Syntax errors:
#include<iostream>
#include<fstream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
//declare input and output file sterams
ifstream inFile;
ofstream outFile;
//declare required variables
double roughness[50], min, max, sum=0, sqSum=0;
double Ra, Rq, maxRoughness;
int i = 0;
//open input file
inFile.open("Surface.txt");
//check input file exist or not
if(!inFile)
//display error message
cout<<"Error in opening the file..."<<endl;
else
{
//read the first value from file
inFile>>roughness[i];
//initialise min and max values
min = max = roughness[i];
//initialise sum
sum+=roughness[i];
//initialise sqSum
sqSum+=roughness[i]*roughness[i];
//loop till end of file
while(!inFile.eof())
{
i++;
//read value from file; one at a time
inFile>>roughness[i];
//check value is less than min or not
if(roughness[i]<min)
min=roughness[i];
//check value is greater than max or not
if(roughness[i]>max)
max=roughness[i];
//calculate cumulative sum
sum+=roughness[i];
//calculate cumulative sum square if the value
sqSum+=roughness[i]*roughness[i];
}
//close infile
inFile.close();
//increment i as it started from 0
i++;
//calculate value of Ra
Ra = abs(sum)/i;
//calculate value of Rq
Rq = sqrt(sqSum/i);
//calculate value of Maximum roughness
maxRoughness = max-min;
//open out put file
outFile.open("Indicators.txt");
//write message to output file
outFile<<"Input data (measures of the roughness"
<<" of the surface of an object):"<<endl<<endl;
//for formatting
outFile<<"\t";
//loop to write 6 values per line
for(int j=0; j<i; j++)
{
outFile<<roughness[j]<<" ";
//insert new line after 6 values
if((j+1)%6==0)
outFile<<endl<<"\t";
}
//for formatting
outFile<<endl<<endl<<endl;
//write the 3 surface roughness indicators to file
outFile<<"Arithmetic mean value (Ra) : "<<Ra<<endl;
outFile<<"Root-mean square average (Rq) : "<<Rq<<endl;
outFile<<"Maximum roughness height : "<<maxRoughness;
outFile.close();
}
//display message
cout<<"Calculations completed and the results are stored in Indicators.txt"
<<endl;
system("PAUSE");
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 10 images

- (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.arrow_forward(Data processing) Write a C++ program that reads the file created in Exercise 4, permits the user to change the hourly wage or years for any employee, and creates a new updated file.arrow_forward(Data processing) Your professor has asked you to write a C++ program that determines grades at the end of the semester. For each student, identified by an integer number between 1 and 60, four exam grades must be kept, and two final grade averages must be computed. The first grade average is simply the average of all four grades. The second grade average is computed by weighting the four grades as follows: The first grade gets a weight of 0.2, the second grade gets a weight of 0.3, the third grade gets a weight of 0.3, and the fourth grade gets a weight of 0.2. That is, the final grade is computed as follows: 0.2grade1+0.3grade2+0.3grade3+0.2grade4 Using this information, construct a 60-by-7 two-dimensional array, in which the first column is used for the student number, the next four columns for the grades, and the last two columns for the computed final grades. The program’s output should be a display of the data in the completed array. For testing purposes, the professor has provided the following data:arrow_forward
- (File creation) Write a C++ program that creates an array containing the integer numbers 60, 40, 80, 90, 120, 150, 130, 160, 170, and 200. Your program should then write the data in the array to a text file. (Alternatively, you can create the file with a text editor.)arrow_forward(Data processing) Write a C++ program that allows the user to enter the following information from the keyboard for each student in a class (up to 20 students): Name Exam 1 Grade Exam 2 Grade Homework Grade Final Exam Grade For each student, your program should first calculate a final grade, using this formula: FinalGrade=0.20Exam1+0.20Exam2+0.35Homework+0.25FinalExam Then assign a letter grade on the basis of 90100=A,8089=B,7079=C,6069=D, and less than 60=F . All the information, including the final grade and the letter grade, should then be displayed and written to a file.arrow_forwardWhen you perform arithmetic operations with operands of different types, such as adding an int and a float, ____________. C# chooses a unifying type for the result you must choose a unifying type for the result you must provide a cast you receive an error messagearrow_forward
- Mark the following statements as true or false. A double type is an example of a simple data type. (1) A one-dimensional array is an example of a structured data type. (1) The size of an array is determined at compile time. (1,6) Given the declaration: int list[10]; the statement: list[5] - list[3] * list[2]; updates the content of the fifth component of the array list. (2) If an array index goes out of bounds, the program always terminates in an error. (3) The only aggregate operations allowable on int arrays are the increment and decrement operations. (5) Arrays can be passed as parameters to a function either by value or by reference. (6) A function can return a value of type array. (6) In C++, some aggregate operations are allowed for strings. (11,12,13) The declaration: char name [16] = "John K. Miller"; declares name to be an array of 15 characters because the string "John K. Miller" has only 14 characters. (11) The declaration: char str = "Sunny Day"; declares str to be a string of an unspecified length. (11) As parameters, two-dimensional arrays are passed either by value or by reference. (15,16)arrow_forward(Data processing) Write a C++ program that reads the file created in Exercise 4 one record at a time, asks for the number of hours each employee worked each month, and calculates and displays each employee’s total pay for the month.arrow_forward(Numerical) Write and test a function that returns the position of the largest and smallest values in an array of double-precision numbers.arrow_forward
- (Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?arrow_forward(Data processing) Construct a three-dimensional weather array for a two-week time period. Include this array in a C++ program that displays the temperatures correctly in response to any of the following user requests: • Any day’s high and low temperatures • Average high and low temperatures for a given month • Month and day with the highest temperature • Month and day with the lowest temperaturearrow_forward(Practice) a. Write output statements using cout that can be used to display values from the first, third, and seventh elements of each array declared in Exercise 2. b. Write a for loop that can be used to display values for the complete array declared in Exercise 2.arrow_forward
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage




