Untitled
unknown
plain_text
a month ago
2.3 kB
3
Indexable
#include <iostream> #include <cstring> #include <list> using namespace std; class List { private: int *niza; int n; void copy(const List & other) { this->n = other.n; this->niza = new int [this->n]; for (int i=0;i<n;i++) { this->niza[i] = other.niza[i]; } } public: List() { this->n=0; this->niza = new int [n]; } List(const List & other) { copy(other); } ~List() { delete [] niza; } List operator=(const List & other) { if (this!=&other) { delete [] niza; copy(other); } return *this; } void pecati() { cout<<" List info: "; for (int i=0;i<n;i++) { cout<<niza[i]<<" "; } cout<<" sum:" << sum()<<" average: "<< average()<<endl; } int sum() { int zbir= 0; for (int i=0;i<n;i++) { zbir+=niza[i]; } return zbir; } double average() { float avg = 0; for (int i=0;i<n;i++) { avg+=niza[i]; } return (avg*1.0/n); } }; class ListContainer { private: List * listi; int size_listi; int attempt; void copy(const ListContainer & li) { this->size_listi = li.size_listi; this->attempt = 0; this->listi = new List[li.size_listi]; for (int i=0;i<size_listi;i++) { this->listi[i] = li.listi[i]; } } public: ListContainer() { this->size_listi = size_listi; this->attempt = 0; this->listi = new List[size_listi]; for (int i=0;i<size_listi;i++) { this->listi[i] = listi[i]; } } ListContainer(const ListContainer & li) { copy(li); } ~ListContainer() { delete [] listi; } ListContainer operator=(const ListContainer & li) { if (this!=&li) { delete [] listi; copy(li); } return *this; } void pecati() { if (size_listi==0) { cout<<"nema"<<endl; return; } for (int i=0;i<size_listi;i++) { cout<<"List number: "<<i+1<<" List info: "; listi[i].pecati(); } } }; int main() { return 0; }
Editor is loading...
Leave a Comment