Docsity

Introduction to Computing for Engineers - Programming Assignment 9 | CS 145, Assignments of Computer Science

Toggle sidebar
bg1
CS 145—Programming Assignment 9
Due on: Thursday,April 23
Weight: 6%
The National Earthquake Information Center really liked your last program (Programming Assignment 5) but, as is usually the case
with clients, they would like you to make just a few more enhancements to the program. The new program must meet all of the
previous specifications and the following additional (and revised) ones:
1) Name the project, solution, and program EarthQuake4 <id> where <id> is your (or your partner’s) seat number.
2) Input earthquake data from the data file quakes2.txt (the same file used before), but change the program so that it prompts the
user for the name of the input file. This allows the user to have the program process a different file of earthquakes. Output the
analysis report to the data file report2.txt, but change the program so that it prompts the user for the name of the report file.
This allows the user to have the program place the analysis report into a file having a different name.
3) The program must interact with the user exactly as specified in Programming Assignment 5 but with three modifications. First,
the program id header should read EarthQuake4. Second, immediately after outputting the program id header, the program
should prompt for and input the name of the input data file and analysis report file . That is, the sample interaction should begin
as shown below. (The sample interaction need not include the entering of invalid magnitudes.) And finally, the quakes that
were incorrectly predicted must be listed in the analysis report in ascending order of their magnitude.
**** Program EarthQuake4 <id> ****
Enter the name of the earthquake data file: quakes2.txt
Enter the name for the analysis report file: report2.txt
Enter minimum magnitude of Earthquakes you wish to analyze: 3.0
Processing.......
Number of earthquakes analyzed: 28
Number of correct predictions: 19
Number where level of damage was
off by just one category: 8
off by more than one category: 1
Analysis Report on Incorrect Predictions is available in report2.txt.
4) To improve maintenance and reuse of code in other programs dealing with earthquakes, rewrite parts of the program using a more
object-oriented approach. That is, define a class called Earthquake that defines an earthquake object. The Earthquake class
should be constructed as follows. It should have four private data members recording the earthquake's magnitude (Rs), the
shear-wave velocity (average) of surrounding soils (Vs), the code for the resulting damage (A - E), and the code for the
predicted damage. Each data member should have a corresponding accessor function. The class must also have a default
constructor that sets the predicted damage code to blank and two other public member functions. A PredictDamage() function
determines the predicted damage based on the Rs and Vs for the earthquake. An operator< function is declared as:
bool operator< (const Earthquake& eQ)
// Return true iff the *this earthquake is less than eQ in magnitude.
Finally, declare a friend function as follows:
friend istream& operator>> (istream& is, Earthquake& eQ);
// Input an earthquake into eQ from input stream is by reading three values:
// an Rs as a float, a Vs as an int, and a damage code as a char.
5) To sort the incorrectly predicted earthquakes, define and appropriately call the following procedure:
void SortEarthquakes(Earthquake a[], int size);
// Sort an array a of earthquakes in ascending order of their magnitudes.
// Note: A selection sort algorithm is used.
6) Finally, display a period after every 5th earthquake is output to the analysis report (in addition to the periods being displayed when
inputting every 5th earthquake).
On the date due, bring to class a printout containing the source code for your program. Yours or your programming partner’s printout
—the one whose seat number was used in naming the program—must also contain a screen shot of the console window showing the
exact program interaction given in 3) above and a printout of the report2.txt file produced by your program .
Before class on the date due place your program in the drop box of the student identified by the <id> used in the program name.

Partial preview of the text

Download Introduction to Computing for Engineers - Programming Assignment 9 | CS 145 and more Assignments Computer Science in PDF only on Docsity!

CS 145—Programming Assignment 9

Due on: Thursday,April 23

Weight: 6%

The National Earthquake Information Center really liked your last program (Programming Assignment 5) but, as is usually the case

with clients, they would like you to make just a few more enhancements to the program. The new program must meet all of the

previous specifications and the following additional (and revised) ones:

1) Name the project, solution, and program EarthQuake4 where is your (or your partner’s) seat number.

2) Input earthquake data from the data file quakes2.txt (the same file used before), but change the program so that it prompts the

user for the name of the input file. This allows the user to have the program process a different file of earthquakes. Output the

analysis report to the data file report2.txt, but change the program so that it prompts the user for the name of the report file.

This allows the user to have the program place the analysis report into a file having a different name.

3) The program must interact with the user exactly as specified in Programming Assignment 5 but with three modifications. First,

the program id header should read EarthQuake4. Second, immediately after outputting the program id header, the program

should prompt for and input the name of the input data file and analysis report file. That is, the sample interaction should begin

as shown below. (The sample interaction need not include the entering of invalid magnitudes.) And finally, the quakes that

were incorrectly predicted must be listed in the analysis report in ascending order of their magnitude.

**** Program EarthQuake4 **** Enter the name of the earthquake data file: quakes2.txt Enter the name for the analysis report file: report2.txt Enter minimum magnitude of Earthquakes you wish to analyze: 3. Processing....... Number of earthquakes analyzed: 28 Number of correct predictions: 19 Number where level of damage was off by just one category: 8 off by more than one category: 1 Analysis Report on Incorrect Predictions is available in report2.txt.

4) To improve maintenance and reuse of code in other programs dealing with earthquakes, rewrite parts of the program using a more

object-oriented approach. That is, define a class called Earthquake that defines an earthquake object. The Earthquake class

should be constructed as follows. It should have four private data members recording the earthquake's magnitude ( Rs ), the

shear-wave velocity (average) of surrounding soils ( Vs ), the code for the resulting damage (A - E), and the code for the

predicted damage. Each data member should have a corresponding accessor function. The class must also have a default

constructor that sets the predicted damage code to blank and two other public member functions. A PredictDamage() function

determines the predicted damage based on the Rs and Vs for the earthquake. An operator< function is declared as:

bool operator< (const Earthquake& eQ) // Return true iff the *this earthquake is less than eQ in magnitude.

Finally, declare a friend function as follows:

friend istream& operator>> (istream& is, Earthquake& eQ); // Input an earthquake into eQ from input stream is by reading three values: // an Rs as a float, a Vs as an int, and a damage code as a char.

5) To sort the incorrectly predicted earthquakes, define and appropriately call the following procedure:

void SortEarthquakes(Earthquake a[], int size); // Sort an array a of earthquakes in ascending order of their magnitudes. // Note: A selection sort algorithm is used.

6) Finally, display a period after every 5th^ earthquake is output to the analysis report (in addition to the periods being displayed when

inputting every 5th^ earthquake).

On the date due, bring to class a printout containing the source code for your program. Yours or your programming partner’s printout

—the one whose seat number was used in naming the program—must also contain a screen shot of the console window showing the

exact program interaction given in 3) above and a printout of the report2.txt file produced by your program.

Before class on the date due place your program in the drop box of the student identified by the used in the program name.