Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- using namespace std;
- class Rayd
- {
- double n;
- public:
- Rayd(double _n)
- {
- n = _n;
- }
- virtual void rayd() = 0;
- virtual void summ() = 0;
- double getN()
- {
- return n;
- }
- virtual ~Rayd()
- {
- cout << "---destruct_Rayds" << endl;
- }
- };
- class RaydArifmet : public Rayd
- {
- double finish;
- int k;
- double* arr;
- public:
- RaydArifmet(double n, double v) : Rayd(n)
- {
- finish = v;
- }
- void rayd() override
- {
- int d = 3;
- int i=0;
- double temp = getN();
- cout << "RaydArifmet: ";
- while (temp <= finish) {
- temp = getN() + i * d; i++;
- }
- k = i;i = 0;
- arr = new double[k];
- temp = getN();
- while (temp <= finish) {
- arr[i] = temp;
- cout << arr[i] << " ";
- i++;
- temp = getN() + i * d;
- }
- }
- void summ() override
- {
- int i = 0;
- int num = k-2;
- double summ;
- summ = (num + 1) * (arr[0] + arr[num]);
- cout << endl;
- cout <<"[Summ "<< summ <<" Summ]";
- cout << endl;
- }
- ~RaydArifmet()
- {
- delete[] arr;
- cout << "---destruct_RaydArifmet---" << endl;
- }
- };
- class RaydGeometr : public Rayd
- {
- double finish;
- double* arr;
- int k;
- public:
- RaydGeometr(double n, double vf) : Rayd(n)
- {
- finish = vf;
- }
- void rayd() override
- {
- int r = 3;
- int i = 0;
- double temp = getN();
- cout << "RaydGeometr: ";
- while (temp <= finish) {
- temp = getN()*pow(r,i); i++;
- }
- k = i; i = 0;
- arr = new double[k];
- temp = getN();
- while (temp <= finish) {
- if (getN() == 0) {
- cout << "нет значений" << endl;
- break;
- }
- arr[i] = temp;
- cout << arr[i] << " ";
- i++;
- temp = getN() * pow(r, i);
- }
- }
- void summ() override
- {
- if (getN() == 0) {
- return;
- }
- int i = 0;
- int num = k - 2;
- double summ;
- int r = 3;
- summ = (num + 1) * (arr[0] + arr[num]);
- summ = (arr[0] - arr[num] * r) / (1 - r);
- cout << endl;
- cout << "[Summ " << summ << " Summ]";
- cout << endl;
- }
- ~RaydGeometr()
- {
- delete[] arr;
- cout << "---destruct_Rayd-Geometr" << endl;
- }
- };
- void main()
- {
- setlocale(LC_ALL, "Russian");
- double num1;
- double num2;
- while (1) {
- cout << "Vvedite pervoe chislo ryada (A-нулевое): ";
- cin >> num1;
- cout << "Vvedite poslednee chislo ryada (A-энное): ";
- cin >> num2;
- Rayd* vec;
- vec = new RaydArifmet(num1, num2);
- vec->rayd();
- vec->summ();
- delete vec;
- vec = new RaydGeometr(num1, num2);
- vec->rayd();
- vec->summ();
- delete vec;
- }
- }
Add Comment
Please, Sign In to add comment