Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- using namespace std;
- class HeartRate {
- private:
- int iSerialMoment;
- int iCurrentRate;
- public:
- /*!****************************************************
- * *
- * Constructors *
- * *
- ******************************************************/
- /*!
- * This constructor is setting default values when the objecti s created
- *
- * @return object - Object of HeartRate class
- *
- */
- HeartRate() :
- iSerialMoment(0),
- iCurrentRate(0)
- {};
- /*!
- * This constructor is explicit and sets the properties of the class
- *
- * @param iSerialMoment - integer, that represents the serial moment
- * @param iCurrentRate - integer, that respresents the current rate
- *
- * @return object - Object of HeartRate class
- *
- */
- explicit HeartRate(int iSerialMoment, int iCurrentRate) :
- iSerialMoment(iSerialMoment > 1 && iSerialMoment < (24 * 60 * 60) ? iSerialMoment : 0),
- iCurrentRate(iCurrentRate > 30 && iCurrentRate < 300 ? iCurrentRate : 0)
- {};
- /*!
- * This constructor is used when copying objects
- *
- * @param obj - Constant instance of HeartRate class to copy data from
- *
- * @return object - Object of HeartRate class
- *
- */
- HeartRate(const HeartRate& obj) :
- iSerialMoment(obj.iSerialMoment),
- iCurrentRate(obj.iCurrentRate)
- {};
- /*!****************************************************
- * *
- * Get Methods *
- * *
- ******************************************************/
- /*!
- * Returns this instance's current rate
- *
- * @return integer - current rate
- *
- */
- inline auto getCurrentRate() -> int {
- return this->iCurrentRate;
- }
- /*!
- * Returns this instance's serial moment
- *
- * @return integer - serial moment
- *
- */
- inline auto getSerialMoment() -> int {
- return this->iSerialMoment;
- }
- /*!****************************************************
- * *
- * Set Methods *
- * *
- ******************************************************/
- /*!
- * Sets the new value of the property iCurrentRate
- *
- * @param iCurrentRate - integer, used to set new current rate value
- *
- */
- inline auto setCurrentRate(int iCurrentRate) -> void {
- if (iCurrentRate > 30 && iCurrentRate < 300)
- this->iCurrentRate = iCurrentRate;
- }
- /*!
- * Sets the new value of the property iSerialMoment
- *
- * @param iSerialMoment - integer, used to set new serial moment value
- *
- */
- inline auto setSerialMoment(int iSerialMoment) -> void {
- if (iSerialMoment > 1 && iSerialMoment < (24 * 60 * 60))
- this->iSerialMoment = iSerialMoment;
- }
- /*!****************************************************
- * *
- * Operators *
- * *
- ******************************************************/
- /*!
- * Operator less than overloading for our class
- *
- * @param object - Constant instance of HeartRate to compare current properties with
- *
- * @return bool - true if the current rate is lower than the object's current rate
- *
- */
- inline auto operator<(const HeartRate& obj) -> bool {
- return (this->iCurrentRate < obj.iCurrentRate ? true : false);
- }
- /*!
- * Operator greater than overloading for our class
- *
- * @param object - Constant instance of HeartRate to compare current properties with
- *
- * @return bool - true if the current rate is higher than the object's current rate
- *
- */
- inline auto operator>(const HeartRate& obj) -> bool {
- return (this->iCurrentRate > obj.iCurrentRate ? true : false);
- }
- /*!
- * The method allows writing to the object through the output operator
- *
- * @param output - Output stream data by reference
- * @param obj - Object of this(HeartRate) class
- *
- * @return ostream - Output stream data
- *
- */
- friend auto operator<<(ostream& output, const HeartRate& obj) -> ostream& {
- output << obj.iSerialMoment << " " << obj.iCurrentRate << "\n\n";
- return output;
- }
- /*!
- * The method allows writing to the object through the input operator
- *
- * @param input - Input stream data by reference
- * @param obj - Object of this(HeartRate) class
- *
- * @return istream - Input stream data
- *
- */
- friend auto operator>>(istream& input, HeartRate& obj) -> istream& {
- input >> obj.iSerialMoment >> obj.iCurrentRate;
- return input;
- }
- /*!****************************************************
- * *
- * Static *
- * *
- ******************************************************/
- /*!
- * The function compares the current Serial moment of the patient and returns integer, based on the result
- *
- * @param left - Constant HeartRate object to readonly from
- * @param right - Constant HeartRate object to readonly from
- *
- * @return
- * 0 - Left object is greater than right object
- * 1 - Left object is less than right object
- * -1 - Left object is equal to right object
- *
- */
- static auto comparison(const HeartRate& left, const HeartRate& right) -> int {
- return (left.iSerialMoment < right.iSerialMoment ? 0 : left.iSerialMoment > right.iSerialMoment ? 1 : -1);
- }
- };
- class HeartData {
- private:
- string iPatientName;
- list<HeartRate> iData;
- public:
- /*!****************************************************
- * *
- * Constructors *
- * *
- ******************************************************/
- /*!
- * This constructor reads from a file and inputs data into its' properties
- *
- * @param iFileName - string, that represents the name of the file
- *
- * @return object - Object of HeartRate class
- *
- */
- explicit HeartData(const string iFileName) {
- try {
- fstream iFile(iFileName, ios::in);
- iFile >> this->iPatientName;
- while (!iFile.eof() && iFile.is_open()) {
- pair<int, int> iHeartRates;
- iFile >> iHeartRates.first >> iHeartRates.second;
- this->iData.push_back(HeartRate(iHeartRates.first, iHeartRates.second));
- }
- }
- catch (exception err) {
- cout << "\n\n" << err.what() << "\n\n";
- }
- }
- /*!****************************************************
- * *
- * Set Methods *
- * *
- ******************************************************/
- /*!
- * The method sets the patient's name in the class
- *
- * @param iPatientName - string, that represents the new name of the patient
- *
- */
- inline auto setPatientName(string iPatientName) -> void {
- this->iPatientName = iPatientName;
- }
- /*!****************************************************
- * *
- * Get Methods *
- * *
- ******************************************************/
- /*!
- * The method returns the patient's name from the class
- *
- * @return string
- *
- */
- inline auto getPatientName() -> string {
- return this->iPatientName;
- }
- /*!****************************************************
- * *
- * Static *
- * *
- ******************************************************/
- /*!
- * The method gathers list of rates below or greater than specified rate
- *
- * @param obj - HeartRate object by reference
- * @param value - Value to be compared with
- * @param comparison - Diversity between comparisons - greater than or less than
- *
- */
- static auto calculateRates(const HeartData& obj, const int value, char comparison = '>') -> list<HeartRate> {
- auto iResult = new list<HeartRate>();
- for (auto element : obj.iData) {
- if (comparison == '<') {
- if (element.getCurrentRate() < value)
- iResult->push_back(element);
- }
- else {
- if (element.getCurrentRate() > value)
- iResult->push_back(element);
- }
- }
- return (*iResult);
- }
- /*!
- * The method gathers list of rates within left value and right value specified range
- *
- * @param obj - HeartRate object by reference
- * @param lvalue - Left value to be compared with
- * @param rvalue - Right value to be compared with
- *
- * @return list - Returns list of HeartRate class
- *
- */
- static auto calculateRatesByTwoNumbers(const HeartData& obj, const int lvalue, const int rvalue) -> list<HeartRate> {
- auto iResult = new list<HeartRate>();
- for (auto element : obj.iData) {
- if (element.getCurrentRate() > lvalue && element.getCurrentRate() < rvalue)
- iResult->push_back(element);
- }
- return (*iResult);
- }
- /*!****************************************************
- * *
- * Streams *
- * *
- ******************************************************/
- /*!
- * The method allows writing to the object through the input operator
- *
- * @param input - Input stream data by reference
- * @param obj - Object of this(HeartData) class
- *
- * @return istream - Input stream data
- *
- */
- friend auto operator>>(istream& input, HeartData& obj) -> istream& {
- auto iHeartRate = new HeartRate();
- input >> obj.iPatientName >> (*iHeartRate);
- obj.iData.push_back(*iHeartRate);
- return input;
- }
- /*!
- * The method allows reading from the object through the output operator
- *
- * @param output - Output stream data by reference
- * @param obj - Object of this(HeartData) class
- *
- * @return ostream - Output stream data
- *
- */
- friend auto operator<<(ostream& output, const HeartData& obj) -> ostream& {
- output << "Patient Name: " << obj.iPatientName << "\n\nRates:\n\n";
- for (auto iRate : obj.iData) {
- output << iRate;
- }
- return output;
- }
- };
- /*!****************************************************
- * *
- * Main Program *
- * *
- ******************************************************/
- int main()
- {
- try {
- auto iObject = new HeartData("C:\\Users\\Stefan.Kolev\\source\\repos\\ConsoleApplication31\\Debug\\test.txt");
- cout << *iObject;
- auto iCalculatedRates = iObject->calculateRatesByTwoNumbers(*iObject, 60, 80);
- cout << "\n\nAfter calculation and between 60 and 80 rate:\n\n";
- for (auto iRate : iCalculatedRates) {
- cout << iRate;
- }
- }
- catch (exception & err) {
- cout << err.what();
- }
- return 0;
- };
Add Comment
Please, Sign In to add comment