Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <memory.h>
- int apole1[10]={2,4,6,8,10,12,14,16,25,37};
- int apole2[9]={2,4,6,8,10,12,14,16,25};
- int apole3[4]={2,4,6,8};
- //1. Vytvořte třídu Cisla, která konstruktorem jakékoliv integer pole
- //různého počtu prvků a poskytne sumu prvků
- //2. Vytvořte funkci která poskytne prvek daný indexem
- //3. Vytvořte funkci srovnává dvě pole
- class Cisla{
- public:
- Cisla(const int* pPole,int iVelikost)
- { //vysvetlit obsah zavorky--> neco zjistovani velikost pole
- //podle poctu prvku a dat.typu
- m_pPole=new int [iVelikost/sizeof(int)];//kde je new tak musi nekde
- //byt destruktor
- //kopirovani zdrovojeho pole do atributu
- m_iVelikostPole = iVelikost;
- memset(m_pPole,0,iVelikost);
- memcpy(m_pPole,pPole,iVelikost);
- }
- //destruktor
- ~Cisla(){
- if(m_pPole)
- delete[] m_pPole;
- }
- int Sum() const //nezmeni se hodnota zadneho atribtu tridy
- {
- if(m_pPole==0)
- return 0;
- //vypocet sumy
- }
- int Get(int index) const{
- return *(m_pPole+index);
- }
- bool GetReference(int index,int &ref) const{
- if((index >= 0 )&& (index < (m_iVelikostPole/sizeof(int))))
- {
- ref = *(m_pPole+index);
- return true;
- }
- return false;
- }
- int * GetPointer(int index)
- {
- if((index >= 0 )&& (index < (m_iVelikostPole/sizeof(int))))
- {
- return (m_pPole+index);
- }
- return 0;
- }
- protected:
- int* m_pPole;
- int m_iVelikostPole;
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- Cisla inst1(apole1, 16);
- Cisla inst2(apole2, 36);
- int cislo = 0;
- if(inst1.GetReference(1,cislo) == false)
- {
- cislo = 100;
- }
- int * uk_cislo = inst1.GetPointer(2);
- if(uk_cislo==0){
- return 0;
- }
- int iv = inst1.Get(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment