Convert Code Into Python and Eliminate Syntax errors: #include #include #include #include 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..."<>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]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):"<

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 12VE
icon
Related questions
Question

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;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 10 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr