Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using C++ program Write a program to determine, and output to the screen, the cl

ID: 3842246 • Letter: U

Question


using C++ program

Write a program to determine, and output to the screen, the class of an earthquake, given its magnitude. A class of minor is given for those in the range of [D, 4], light if in [4, 5), moderole if in [5, 6], strong if in [6, 7], major if in [7, 8] and great if in [8, infinity]. Write a program to guess a magic number m = 4, and output to a file, each of guesses that are made. A sequence of random numbers is generated, each in the range [1, 10]. If the number is equal to m, then the program terminates. Otherwise, it generates another number. Your submission should include the contents of the output file using a random number generator seed of 760.

Explanation / Answer

Ans 1.

#include <iostream>
#include<string> // for string class

using namespace std;

class Earthquake{
        int magnitude;
    string earthquakeClass;
  
    public:

/* this function will determine the class of earthquake based on the magnitude set for the object which is used to call this method */
        void determineEarthquakeClass(){
            if(magnitude >= 0 && magnitude <4){
               setEarthquakeClass("MINOR");
            } else if(magnitude >= 4 && magnitude <5){
               setEarthquakeClass("LIGHT");
            } else if(magnitude >= 5 && magnitude <6){
               setEarthquakeClass("MODERATE");
            } else if(magnitude >= 6 && magnitude <7){
               setEarthquakeClass("STRONG");
            } else if(magnitude >= 7 && magnitude <8){
               setEarthquakeClass("MAJOR");
            } else if(magnitude>=8){
               setEarthquakeClass("GREAT");
            }
        }

// getters and setters for data member variables

       int getMagnitude() {
           return magnitude;
       }
  
       void setMagnitude(int magni) {
           magnitude = magni;
       }
  
       string getEarthquakeClass() {
           return earthquakeClass;
       }
  
       void setEarthquakeClass(string eClass) {
           earthquakeClass = eClass;
       }
};
int main() {
    int magnitude;

//declaring object of class Earthquake
   Earthquake earthquake;
   cout<<"Enter the magnitude";
   cin>>magnitude;

//set value of magnitude for object earthquake
   earthquake.setMagnitude(magnitude);
   if(magnitude<0){
        cout<<" Please enter a valid magnitude value!";
   } else{

//call member function determineEarthquakeClass
   earthquake.determineEarthquakeClass();
   cout<<" This earthquake is rated as: "<<earthquake.getEarthquakeClass();
   }
   return 0;
}