21.10.2012, 20:18. Просмотров 317. Ответов 2
Помогите пожалуйста, с созданием класса.
Необходимон аписать класс - DigitalTimeException со след:
- конструктор с 2 аргументами: int error_number, и текстовой error_message;
- любое целое значение и любое текстовое значение string было бы valid;
- private member variables to store the error number and error message. хранить error message как string type variable.
- Public member function errorNumber и errorMessage возвращают error number и error message соответственно.
Пример: DigitalTimeException thisError(101, "Something is completely messed up!");
The value of thisError.errorNumber() would be 101 while thisError.errorMessage would return "Something is completely messed up!".
Мой код:
Header file:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| #ifndef DIGITALTIMEXCEPTION_H
#define DIGITALTIMEXCEPTION_H
#include <string>
using namespace std;
class DigitalTimeException
{
public:
DigitalTime(int error_number, char error_message); //A constructor that accepts two arguments
DigitalTimeException(string thisErrorMessage);
string errorMessage();
private:
string message;
int error_number;
char error_message;
};
#endif |
|
Implementation file:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
| #include <string>
#include "DigitalTimetException.h"
using namespace std;
DigitalTimeException::DigitalTimeException(string whatWentWrong)
{
message = whatWentWrong;
}
// Return the error message stored inside the object
string DigitalTimeException::errorMessage()
{
return message;
} |
|