|
ENGN 38 Lab Programming Assignment #7
|
|
Roughness is an important parameter in mechanical systems. Among other things, it is used in determining friction between mating surfaces. It generally costs more money to make a surface smoother.
Mechanical and manufacturing engineers use three principle measures of the roughness of the surface of an object. All are based on measurements at evenly spaced intervals along the surface as diagrammed here and labeled a, b, c….
|
|
Values above the centerline are positive; values below are negative. The three roughness indicators are:
|
|
Instructions: Write a modularized C++ program that does the following:
To turn in: Print out your source code and program output making sure that the formatting is up to C++ standards and professional in appearance. If this does not fit on one page, delete enough so that it does. (Please do not make font size less than 10 points.) What to delete? What to keep? Make sure that you at least have the header as shown in Lab#1 (your student number, your name, the class identifier, the lab number) and the output from your program. As space permits, include any other essentials as you deem appropriate. Make sure that everything is clearly labeled and easy to read and follow. Have this one page ready to turn in by the due date. ...
|
|
surface.txt Roughness Data File Data values are in micrometers -4.1 -2.2 -0.5 1.2 3.3 4.6 5.1 2.1 0.2 -3.6 -4.1 0.2 0.5 2.2 4.1 -0.2 -1.2 -3.3 -4.6 -5.0 -2.2 -1.1 0.8 3.2 -0.1 -4.8
|
|
Output Report Requirements: Surface Roughness Data (micrometers) -4.1 -2.2 0.5 . . .
Roughness Parameters Arithmetic Mean = x.x mm Root-Mean-Square = x.x mm Maximum Roughness = x.x mm
|
|
Example program using functions to modularize:
// This program show the use of arrays to process data.
#include <iostream> using namespace std;
const int SIZE = 20;
void requestNumberToProcess(int& numberToProcess); void readData(double data[], int numberToProcess); void calculateAverage(double data[], int numberToProcess, double& average); void findMaximum(double data[], int numberToProcess, double& maximum); void printReport(double data[], int numberToProcess, double average, double maximum);
int main () { double average, maximum, data[SIZE]; int numberToProcess;
requestNumberToProcess(numberToProcess); readData (data, numberToProcess);
calculateAverage(data, numberToProcess, average); findMaximum(data, numberToProcess, maximum);
printReport (data, numberToProcess, average,maximum);
return 0; }
void requestNumberToProcess(int& numberToProcess) { cout<<"How many numbers do you want to average "; cin >>numberToProcess; while(numberToProcess <= 0 || numberToProcess>SIZE) { cout<<"\n\nYou must enter a number >= 1 and <= "<<SIZE; cout<<"\nHow many numbers do you want to average "; cin >>numberToProcess; } }
void readData(double data[],int numberToProcess) { cout<<"Type in "<<numberToProcess<<" data values\n"; for(int i=0; i<numberToProcess; i++) cin>>data[i]; }
void calculateAverage(double data[],int numberToProcess,double& average) { double sum = 0.0;
for(int i=0;i<numberToProcess;i++) sum += data[i];
average = sum/numberToProcess; }
void findMaximum(double data[],int numberToProcess,double& maximum) { maximum = data[0]; for(int i=1;i<numberToProcess;i++) if(data[i] > maximum) maximum = data[i]; }
void printReport(double data[],int numberToProcess, double average,double maximum) { cout.setf(ios::showpoint | ios::fixed); cout.precision(2);
cout<<"\n\nReport Results\nData Values\n"; for(int i=0;i<numberToProcess;i++) cout<<data[i]<<"\n";
cout<<"\n\nAverage = "<<average; cout<<"\n\nMaximum = "<<maximum<<"\n\n";
}
|