#include "baseset.h"
int main()
{
int arr[] = {1,2,3,4,5,6,7,8,9};
BaseSet bset(arr, 9);
BaseSet bset2(bset);
bset.Print();
bset2.Print();
//Проверка операции деления
BaseSet bset3 = bset/bset2;
bset3.Print();
//Проверка операции вычитания
bset3 = bset - bset2;
bset3.Print();
//До сюда всё работает. Дальше - фиг
//Проверка операции умножения
bset3 = bset - bset2;
bset3.Print();
//Проверка операции сложения
// bset3 = bset + bset2;
// bset3.Print();
return 0;
}
#include "baseset.h"
int main()
{
int arr[] = {1,2,3,4,5,6,7,8,9};
BaseSet bset(arr, 9);
BaseSet bset2(bset);
bset.Print();
bset2.Print();
//Проверка операции деления
BaseSet bset3 = bset/bset2;
bset3.Print();
//Проверка операции вычитания
bset3 = bset - bset2;
bset3.Print();
//Проверка операции умножения
bset3 = bset - bset2;
bset3.Print();
//Проверка операции сложения
// bset3 = bset + bset2;
// bset3.Print();
return 0;
}
//baseset.h
//базовый класс - Множество
#ifndef BASESET_H
#define DASESET_H
#include <stdlib.h>
#include <iostream>
using namespace std;
//Класс - Множество
class BaseSet
{
protected:
int* Array; //Массив хранения значений множества
unsigned int Count; //Количество хранящихся в массиве значений
//Удаление массива хранения
void Destroy()
{
if (Array)
{
delete [] Array;
Array = NULL;
Count = 0;
}
}
//Копирование значений из другого массива
void Copy(int *pIntArray, unsigned int len)
{
if (pIntArray)
{
Destroy();
Array = new int[len];
for (size_t i = 0; i < len; ++i)
{
Array[i] = pIntArray[i];
}
Count = len;
}
}
public:
//Конструкторы. Без параметров
BaseSet() : Array(0), Count(0)
{
}
//С созданием пустого множества
//Параметры:
//len - количество ячеек хранения
BaseSet(unsigned int len) : Array(0), Count(len)
{
Array = new int[Count];
for (unsigned int i = 0; i < Count; i++)
{
Array[i] = 0;
}
}
//С передачей указателя на целочисленный массив
//Параметры:
//*pIntArray - указатель на массив
//len - количество элементов в массиве
BaseSet(int *pIntArray, unsigned int len) : Array(0), Count(0)
{
if (pIntArray != NULL)
{
Copy(pIntArray, len);
}
else
{
cout << "Множество не создано. Видимо это пустой массив..." << endl;
}
}
//Конструктор копирования
//Параметры:
//Other - другой объект, из которого надо скопировать значения
BaseSet(const BaseSet& Other) : Array(0), Count(0)
{
Copy(Other.Array, Other.GetCount());
}
//Деструктор
~BaseSet()
{
Destroy();
}
//Получить количество ячеек хранения
unsigned int GetCount() const
{
return Count;
}
//Вывод значений множества на экран по горизонтали
void Print()
{
for (unsigned int i = 0; i < Count; i++)
{
cout << Array[i] << " ";
}
cout << endl;
}
//Перегрузка операций
//Индексация
int &operator[] (unsigned int Index) const
{
if (Index >= (Count))
{
cout << "Индекс " << Index << " больше, чем количество данных..." << endl;
exit(1);
}
return Array[Index];
}
//Присваивание
BaseSet & operator=(const BaseSet& Other)
{
if (this != &Other)
{
Copy(Other.Array, Other.Count);
}
return *this;
}
//Сложение
BaseSet operator+(const BaseSet& Other) const
{
unsigned int cnt = min(Count, Other.Count);
BaseSet result(cnt);
for (unsigned int i = 0; i < cnt; i++)
{
result.Array[i] = Array[i] + Other.Array[i];
}
return result;
}
//Вычитание
BaseSet operator-(const BaseSet& Other) const
{
unsigned int cnt = min(Count, Other.Count);
BaseSet result(cnt);
for (unsigned int i = 0; i < cnt; i++)
{
result.Array[i] = Array[i] - Other.Array[i];
}
return result;
}
//Умножение
BaseSet operator*(const BaseSet& Other) const
{
unsigned int cnt = min(Count, Other.Count);
BaseSet result(cnt);
for (unsigned int i = 0; i < cnt; i++)
{
result.Array[i] = Array[i] * Other.Array[i];
}
return result;
}
//Деление
BaseSet operator/(const BaseSet& Other) const
{
unsigned int cnt = min(Count, Other.Count);
BaseSet result(cnt);
div_t x;
for (unsigned int i = 0; i < cnt; i++)
{
x = div(Array[i], Other.Array[i]);
result.Array[i] = x.quot;
}
return result;
}
};
#endif
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a = 12.0 / 1;
cout<<"a="<<left<<setw(3)<<a<<right<<setw(15)<<"finite(a)="<<boolalpha<<(bool)finite(a)<<endl;
double b = 12.0 / 0;
cout<<"b="<<left<<setw(3)<<b<<right<<setw(15)<<"finite(b)="<<boolalpha<<(bool)finite(b)<<endl;
return 0;
}
a=12 finite(a)=true
b=inf finite(b)=false
#include <iostream>
#include <eh.h>
#include <float.h>
using namespace std;
class my_seh_exception:public exception
{
public:
my_seh_exception()
:exception("SEH Exception!!!")
{
}
};
void handler(unsigned int code, struct _EXCEPTION_POINTERS* ep)
{
_clearfp();
throw my_seh_exception();
}
class test
{
public:
test()
{
cout<<"constructor test"<<endl;
}
~test()
{
cout<<"destructor test"<<endl;
}
};
int main()
{
_set_se_translator(handler);
#pragma warning(disable:4996)
_controlfp(FPE_ZERODIVIDE,_MCW_EM);
try
{
test t;
double x=0;
double iy=10.0/x;
cout<<iy<<endl;
}
catch(exception& e)
{
cerr<<e.what()<<endl;
}
system("pause");
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.