Systems Architecture
Systems Architecture
7th Edition
ISBN: 9781305080195
Author: Stephen D. Burd
Publisher: Cengage Learning
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage