Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Konstr.h"
- #include <iostream>
- #include <string>
- using namespace std;
- CKonstr::CKonstr()
- {
- InitializeAndZeroFillArr();
- s_name = DEFAULT_NAME;
- cout << "bezp: " + s_name << endl;
- }
- CKonstr::CKonstr(string s_name)
- {
- this->s_name = s_name;
- cout << "parametr: " + s_name << endl;
- }
- CKonstr::CKonstr(const CKonstr& source)
- {
- s_name = source.s_name + "_copy";
- InitializeAndZeroFillArr(source.i_size);
- CopyArr(source.arr, arr, i_size);
- }
- CKonstr::~CKonstr()
- {
- delete arr;
- cout << "removing: " + s_name << endl;
- }
- //Zmianę długości tablicy
- void CKonstr::ChangeArrSize(int i_size)
- {
- int* tempArr = new int[i_size];
- for (int i = 0; i < i_size; i++)
- {
- if (i < i_size) tempArr[i] = arr[i];
- else tempArr[i] = 0;
- }
- this->i_size = i_size;
- //arr* = &tempArr; ?????????????????????
- }
- //Przypisanie określonej komórce tablicy wartości typu int
- bool CKonstr::SetValueByIndex(int i_index, int i_value) //
- {
- if (i_index < i_size)
- {
- arr[i_index] = i_value;
- return true;
- }
- else return false;
- }
- //Odczyt wartości określonej komórki
- int CKonstr::GetValueByIndex(int i_index)
- {
- return arr[i_index];
- }
- //Utworzenie klonu obiektu(innego obiektu posiadającego te same wartości w tablicy)
- CKonstr* CKonstr::Clone()
- {
- return new CKonstr(*this);
- }
- //Przypisanie obiektowi A, wartości i stanu tabeli w obiekcie B (po wykonaniu takiej operacji w obiekcie A tabela ma posiadać tą samą długość i te same wartości, co tablica w obiekcie B)
- void CKonstr::CopyArr(int* source, int* dest, int i_size)
- {
- for (int i = 0; i < i_size; i++)
- {
- dest[i] = source[i];
- }
- }
- //Zwrócenie informacji o obiekcie do zmiennej typu string w formacie: (<nazwa obiektu> len: <liczba pozycji> values : <wszystkie wartości z tablicy oddzielone przecinkami>)
- string CKonstr::ToString()
- {
- string res = s_name + " len: " + to_string(i_size) + " values: ";
- for (int i = 0; i < i_size-1; i++)
- {
- res += to_string(arr[i]) + ", ";
- }
- res += to_string(arr[i_size - 1]) + ".";
- return res;
- }
- void CKonstr::SetName(string s_name)
- {
- this->s_name = s_name;
- }
- void CKonstr::InitializeAndZeroFillArr()
- {
- arr = new int[DEFAULT_SIZE];
- i_size = DEFAULT_SIZE;
- for (int i = 0; i < i_size; i++)
- {
- arr[i] = 0;
- }
- }
- void CKonstr::InitializeAndZeroFillArr(int i_size)
- {
- arr = new int[i_size];
- this->i_size = i_size;
- for (int i = 0; i < i_size; i++)
- {
- arr[i] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement