Question: Please do this in C++, COMMENTS that help in explaining are appreciated, if the code runs I will thumbs up to your hard work. Write
Please do this in C++, COMMENTS that help in explaining are appreciated, if the code runs I will thumbs up to your hard work.
Write clean, readable, and well-structured code. 1. You have to write comments that explain each code that you add. 2. Do not change the main function. 3. Do not change the Sensor class.
Accelerometer is a Sensor. 1. Fix the Accelerometer class to fulfill all of the object-oriented concepts] Moreover, the main function has to work as expected (The shallow copy is not accepted). 2. The output format of cout << "Accelerometer1: " << accelerometer1 << endl; must be as follows: Accelerometer1: id: 1, the ratePerSecond: 10 and the type: 1-D
Code is: #include
class Accelerometer { public: Accelerometer(int id, string type, int ratePerSecond) { this->id = id; this->type = type; this->ratePerSecond = new int; *this->ratePerSecond = ratePerSecond; } void setId(int id) { this->id = id; } int getId() { return id; } void setType(string type) { this->type = type; } string getType() { return type; } int getRatePerSecond() { return *ratePerSecond; } void start() { cout << "Start the Accelerometer at rate per second = " << ratePerSecond << endl; }
};
int main() { Accelerometer accelerometer1; accelerometer1.setRatePerSecond(10); accelerometer1.setId(1); accelerometer1.setType("1-D");
cout << "accelerometer1: " << accelerometer1 << endl; Accelerometer accelerometer2(2, "1-D", 20); accelerometer1 = accelerometer2; accelerometer2.setRatePerSecond(30);
cout << "accelerometer1: " << accelerometer1 << endl; cout << "accelerometer2: " << accelerometer2 << endl; Accelerometer accelerometer3 = accelerometer2;
accelerometer2.setRatePerSecond(40); cout << "accelerometer2: " << accelerometer2 << endl; cout << "accelerometer3: " << accelerometer3 << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
