Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Kamion
- #include<iostream>
- #include<cstring>
- using namespace std;
- class ImaMasa
- {
- protected:
- double mass;
- public:
- virtual double vratiMasa() = 0;
- virtual void pecati() = 0;
- };
- class PaketPijalok : virtual public ImaMasa
- {
- private:
- double volumenEden;
- int kolicina;
- static double PaketMass;
- static double density;
- public:
- double vratiMasa()
- {
- return mass;
- }
- void pecati()
- {
- cout << "quantity " << kolicina << ", ";
- }
- int getKolicina();
- void setVolume(double volumen)
- {
- volumenEden=volumen;
- }
- void setKolicina(int k)
- {
- kolicina=k;
- }
- double getVolume()
- {
- return volumenEden;
- }
- static double getDensity()
- {
- return density;
- }
- virtual ~PaketPijalok(){};
- };
- class PaketSok: virtual public ImaMasa, public PaketPijalok
- {
- private:
- bool daliGaziran;
- public:
- PaketSok(double volumen, int kolicina, bool g)
- {
- setVolume(volumen);
- daliGaziran=g;
- setKolicina(kolicina);
- }
- double vratiMasa()
- {
- if(daliGaziran==false)
- return mass*getVolume()*getDensity();
- else
- return mass*getVolume()*getDensity()+0.1;
- }
- void pecati()
- {
- cout << "PaketSok" << endl;
- PaketPijalok::pecati();
- cout << " each of " << getVolume() << "l(dm3)" << endl;
- }
- virtual ~PaketSok();
- };
- class PaketVino: virtual public ImaMasa, public PaketPijalok
- {
- private:
- double procentAlkohol;
- public:
- PaketVino(double volumen, int kolicina, double procent)
- {
- if(procent<0 || procent>1)
- {
- cerr << "Incorrect alcohol percentage!" << endl;
- procentAlkohol=0;
- }
- else
- procentAlkohol=procent;
- setVolume(volumen);
- setKolicina(kolicina);
- }
- double vratiMasa()
- {
- return mass*getVolume()*getDensity()*(0.9+procentAlkohol);
- }
- double getProcentAlkohol()
- {
- return procentAlkohol;
- }
- void pecati()
- {
- cout << "PaketVino" << endl;
- PaketPijalok::pecati();
- cout << procentAlkohol*10 << "% alchocol each of " << getVolume() << "l(dm3)" << endl;
- }
- virtual ~PaketVino();
- };
- class Kamion
- {
- private:
- char *registration;
- char *driver;
- ImaMasa **element;
- int n;
- public:
- Kamion (const char *registrationin="", const char *driverin="")
- {
- if(strlen(registrationin)!=8 || !isalpha(registrationin[0]) || !isalpha(registrationin[6]) || !isalpha(registrationin[7]))
- {
- cerr << "Incorrect registration!" << endl;
- }
- strcpy(registration,registrationin);
- strcpy(driver,driverin);
- element=NULL;
- n=0;
- }
- void dodadiElement(ImaMasa *elementin)
- {
- ImaMasa **temp = element;
- element = new ImaMasa*[n+1];
- for(int i=0; i<n; i++)
- element[i]=temp[i];
- element[n++]=elementin;
- delete [] temp;
- }
- double vratiVkupnaMasa()
- {
- double total=0;
- for (int i=0; i<n; i++)
- total+=element[i]->vratiMasa();
- return total;
- }
- void pecati()
- {
- cout << "Truck with registration " << registration << " and driver " << driver << " transports:" << endl;
- for(int i=0; i<n; i++)
- {
- element[i]->pecati();
- }
- }
- Kamion pretovar(const char *registrationin="",const char *driverin="")
- {
- strcpy(registration,registrationin);
- strcpy(driver,driverin);
- double max=0;
- int index;
- for(int i=0; i<n; i++)
- {
- if(max<element[i]->vratiMasa())
- {
- max=element[i]->vratiMasa();
- index=i;
- }
- }
- ImaMasa **temp = element;
- element = new ImaMasa*[n-1];
- for(int i=0; i<index; i++)
- element[i]=temp[i];
- for(int i=index; i<n-1; i++)
- element[i]=temp[i+1];
- n--;
- delete [] temp;
- return *this;
- }
- };
- int main()
- {
- char ime[20], reg[9];
- double vol;
- int kol;
- bool g;
- double proc;
- cin>>reg;
- cin>>ime;
- Kamion A(reg, ime);
- ImaMasa **d = new ImaMasa*[5];
- cin>>vol>>kol;
- cin>>g;
- d[0] = new PaketSok(vol, kol, g);
- cin>>vol>>kol;
- cin>>proc;
- d[1] = new PaketVino(vol, kol, proc);
- cin>>vol>>kol;
- cin>>proc;
- d[2] = new PaketVino(vol, kol, proc);
- cin>>vol>>kol;
- cin>>g;
- d[3] = new PaketSok(vol, kol, g);
- cin>>vol>>kol;
- cin>>proc;
- d[4] = new PaketVino(vol, kol, proc);
- A.dodadiElement(d[0]);
- A.dodadiElement(d[1]);
- A.dodadiElement(d[2]);
- A.dodadiElement(d[3]);
- A.dodadiElement(d[4]);
- A.pecati();
- cout<<"Total mass: "<<A.vratiVkupnaMasa()<<endl;
- cin>>reg;
- cin>>ime;
- Kamion B = A.pretovar(reg, ime);
- B.pecati();
- cout<<"Total mass: "<<B.vratiVkupnaMasa()<<endl;
- }
- ====================================================================================================================
- TransakcijaSimple
- #include<iostream>
- #include<cstring>
- using namespace std;
- class InvalidDateException{
- int day, mesec, godina;
- public:
- InvalidDateException(int d, int m, int g){
- day = d;
- mesec = m;
- godina = g;
- }
- void pecati(){
- cout << "Invalid Date " << day <<"/"<<mesec<<"/"<<godina<<endl;
- }
- };
- class NotSupportedCurrencyException{
- char valuta[3];
- public:
- NotSupportedCurrencyException(char * v = ""){
- strcpy(valuta, v);
- }
- void print(){
- cout << valuta << " is not a supported currency" << endl;
- }
- };
- class Transakcija {
- protected:
- int den, mesec, godina;
- double iznos;
- static double EUR, USD;
- public:
- Transakcija(int d = 0, int m = 0, int g = 0, double i = 0){
- if (d < 1 || d > 31 || m < 1 || m > 12)
- throw InvalidDateException(d,m,g);
- den = d;
- mesec = m;
- godina = g;
- iznos = i;
- }
- virtual double voDenari() = 0;
- virtual void pecati() {}
- static void setEUR(double newEUR){
- EUR = newEUR;
- }
- static void setUSD(double newUSD){
- USD = newUSD;
- }
- };
- double Transakcija::EUR = 61;
- double Transakcija::USD = 50;
- class DenarskaTransakcija:public Transakcija{
- public:
- DenarskaTransakcija(int d = 0, int m = 0, int g = 0, double i = 0):Transakcija(d,m,g,i){
- }
- double voDenari(){
- return iznos;
- }
- void pecati(){
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<iznos<<" MKD"<<endl;
- }
- };
- class DeviznaTransakcija:public Transakcija{
- char valuta[3];
- public:
- DeviznaTransakcija(int d = 0, int m = 0, int g = 0, double i = 0, char * v = ""):Transakcija(d,m,g,i){
- if (strcmp(v, "EUR") == 0 || strcmp(v, "USD") == 0)
- strcpy(valuta, v);
- else
- throw NotSupportedCurrencyException(v);
- }
- double voDenari(){
- if (strcmp(valuta, "USD") == 0)
- return ((int)iznos) * USD;
- return (int)iznos * EUR;
- }
- void pecati(){
- if (strcmp(valuta, "MKD") == 0)
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<iznos<<" " <<valuta<<endl;
- else
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<(int)iznos<<" " <<valuta<<endl;
- }
- };
- class Smetka{
- Transakcija ** niza;
- int n;
- char broj[15];
- double saldo;
- public:
- Smetka(const char * broj = "", double saldo = 0){
- niza = new Transakcija*[0];
- n = 0;
- strcpy(this->broj, broj);
- this->saldo = saldo;
- }
- Smetka & operator += (Transakcija *k){
- Transakcija ** temp = new Transakcija*[n + 1];
- for (int i = 0; i < n; i++)
- temp[i] = niza[i];
- temp[n++] = k;
- delete [] niza;
- niza = new Transakcija*[n];
- niza = temp;
- return *this;
- }
- void izvestajVoDenari(){
- //Korisnikot so smetka: [број на сметката] ima momentalno saldo od [салдо на сметката пресметано во денари] MKD
- double pocetno = saldo;
- for (int i = 0; i < n; i++)
- pocetno += niza[i] -> voDenari();
- cout << "Korisnikot so smetka: " << broj << " ima momentalno saldo od " << pocetno << " MKD" << endl;
- }
- void pecatiTransakcii(){
- for (int i = 0; i < n; i++)
- niza[i] -> pecati();
- }
- };
- int main () {
- Smetka s ("300047024112789",1500);
- int n, den, mesec, godina, tip;
- double iznos;
- char valuta [3];
- cin>>n;
- cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
- for (int i=0;i<n;i++){
- cin>>tip>>den>>mesec>>godina>>iznos;
- try{
- if (tip==2){
- cin>>valuta;
- Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
- s+=t;
- //delete t;
- }
- else {
- Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
- s+=t;
- //delete t;
- }
- }
- catch(InvalidDateException invalid){
- invalid.pecati();
- }
- catch(NotSupportedCurrencyException invalid){
- invalid.print();
- }
- }
- cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
- s.pecatiTransakcii();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
- double newEUR, newUSD;
- cin>>newEUR>>newUSD;
- Transakcija::setEUR(newEUR);
- Transakcija::setUSD(newUSD);
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- return 0;
- }
- =====================================================================================================
- Transakcija
- #include<iostream>
- #include<cstring>
- using namespace std;
- class NotSupportedCurrencyException{
- private:
- char *valuta;
- public:
- NotSupportedCurrencyException(char *valuta){
- this -> valuta = new char[3];
- strcpy(this -> valuta, valuta);
- }
- void pecatiPoraka(){
- cout<< valuta << " is not a supported currency" << endl;
- }
- };
- class InvalidDateException{
- private:
- int den;
- int mesec;
- int godina;
- public:
- InvalidDateException(int den, int mesec, int godina){
- this -> den = den;
- this -> mesec = mesec;
- this -> godina = godina;
- }
- void pecatiPoraka(){
- cout<< "Invalid Date " << den << "/" << mesec << "/" << godina << endl;
- }
- };
- class Transakcija {
- protected:
- int den;
- int mesec;
- int godina;
- double iznos;
- public:
- static double EUR;
- static double USD;
- static void setEUR(double newEUR);
- static void setUSD(double newUSD);
- Transakcija(int den, int mesec, int godina, int iznos){
- if(den < 1 || den > 31 || mesec < 1 || mesec > 12 ) throw InvalidDateException(den, mesec, godina);
- this -> den = den;
- this -> mesec = mesec;
- this -> godina = godina;
- this -> iznos = iznos;
- }
- virtual double voDenari() = 0;
- virtual void pecati() = 0;
- };
- double Transakcija::EUR = 61;
- double Transakcija::USD = 50;
- void Transakcija::setEUR(double newEUR){
- EUR = newEUR;
- }
- void Transakcija::setUSD(double newUSD){
- USD = newUSD;
- }
- class DenarskaTransakcija : public Transakcija {
- public:
- DenarskaTransakcija(int den, int mesec, int godina, double iznos)
- :Transakcija(den, mesec, godina, iznos){}
- double voDenari(){
- return iznos;
- }
- void pecati(){
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<iznos<<endl;
- }
- };
- class DeviznaTransakcija : public Transakcija {
- private:
- char valuta[3];
- public:
- DeviznaTransakcija(int den, int mesec, int godina, double iznos, char *valuta)
- :Transakcija(den, mesec, godina, iznos){
- if(strcmp(valuta, "USD") != 0 & strcmp(valuta, "EUR") != 0) throw NotSupportedCurrencyException(valuta);
- strcpy(this->valuta, valuta);
- }
- double voDenari(){
- if(strcmp(valuta, "USD") == 0) return this -> iznos * this -> USD;
- return this -> iznos * this -> EUR;
- }
- void pecati(){
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<iznos<<" "<<valuta<<endl;
- }
- };
- class Smetka {
- private:
- Transakcija **transakcii;
- int brTransakcii;
- char brojSmetka[15];
- double saldoDenari;
- public:
- Smetka(char *brojSmetka, double saldoDenari){
- strcpy(this->brojSmetka, brojSmetka);
- this -> saldoDenari = saldoDenari;
- this -> brTransakcii = 0;
- transakcii = new Transakcija*[this -> brTransakcii];
- }
- ~Smetka(){
- delete [] transakcii;
- }
- Smetka& operator+=(Transakcija *novaTransakcija){
- Transakcija** temp = new Transakcija*[brTransakcii + 1];
- for(int i = 0; i < brTransakcii; i++){
- temp[i] = transakcii[i];
- }
- temp[brTransakcii] = novaTransakcija;
- brTransakcii++;
- delete [] transakcii;
- transakcii = temp;
- return *this;
- }
- void pecatiTransakcii(){
- for(int i = 0; i < brTransakcii; i++){
- transakcii[i] -> pecati();
- }
- }
- void izvestajVoDenari(){
- double saldo = saldoDenari;
- for(int i = 0; i < brTransakcii; i++){
- saldo += transakcii[i] -> voDenari();
- }
- cout<<"Korisnikot so smetkaa: "<< brojSmetka << " ima momentalno saldo od "<< saldo <<" MKD"<<endl;
- }
- };
- int main () {
- Smetka s ("300047024112789",1500);
- int n, den, mesec, godina, tip;
- double iznos;
- char valuta [3];
- cin>>n;
- cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
- for (int i=0;i<n;i++){
- cin>>tip>>den>>mesec>>godina>>iznos;
- try{
- if (tip==2){
- cin>>valuta;
- Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
- s+=t;
- //delete t;
- }
- else {
- Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
- s+=t;
- //delete t;
- }
- } catch(InvalidDateException ide){
- ide.pecatiPoraka();
- } catch(NotSupportedCurrencyException ce){
- ce.pecatiPoraka();
- }
- }
- cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
- s.pecatiTransakcii();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
- double newEUR, newUSD;
- cin>>newEUR>>newUSD;
- Transakcija::setEUR(newEUR);
- Transakcija::setUSD(newUSD);
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- return 0;
- }
- ============================================================================================
- SocialNetwork
- #include <iostream>
- #include <cstring>
- #include <cctype>
- using namespace std;
- class InvalidPassword{
- char text[100];
- public:
- InvalidPassword(const char *text){
- strcpy(this->text,text);
- }
- void message()
- {
- cout<<text<<endl;
- }
- };
- class InvalidEmail{
- char text[100];
- public:
- InvalidEmail(const char *text){
- strcpy(this->text,text);
- }
- void message()
- {
- cout<<text<<endl;
- }
- };
- class MaximumSizeLimit{
- int n;
- public:
- MaximumSizeLimit(int n)
- {
- this->n=n;
- }
- void message()
- {
- cout<<"You can't add more than "<<n<<" users"<<endl;
- }
- };
- class User{
- protected:
- char username[50];
- char password[50];
- char email[50];
- bool checkPassword()
- {
- int br1=0,br2=0,br3=0;
- for(int i=0;i<49;i++)
- {
- if(isupper(password[i])) br1++;
- if(islower(password[i])) br2++;
- if(isdigit(password[i])) br3++;
- }
- if(br1&&br2&&br3) return true;
- return false;
- }
- bool checkEmail()
- {
- for(int i=0;i<49;i++)
- {
- if(email[i]=='@') return true;
- }
- return false;
- }
- public:
- User(const char *u="",const char *p="",const char *e="")
- {
- if(checkPassword()==false) throw InvalidPassword("Password is too weak");
- else if(checkEmail()==false) throw InvalidEmail("Mail is not valid");
- else{
- strcpy(username,u);
- strcpy(password,p);
- strcpy(email,e);
- }
- }
- virtual double popularity()=0;
- };
- class FacebookUser:public User{
- private:
- int bp,bl,bk;
- public:
- FacebookUser(const char *u="",const char *p="",const char *e="",int bp=0,int bl=0,int bk=0):User(u,p,e)
- {
- this->bp=bp;
- this->bl=bl;
- this->bk=bk;
- }
- double popularity()
- {
- return bp+(bl*0.1)+(bk*0.5);
- }
- };
- class TwitterUser:public User{
- private:
- int bs,bt;
- public:
- TwitterUser(const char *u="",const char *p="",const char *e="",int bs=0,int bt=0):User(u,p,e)
- {
- this->bs=bs;
- this->bt=bt;
- }
- double popularity()
- {
- return bs+(bt*0.5);
- }
- };
- class SocialNetwork{
- private:
- User **niza;
- int broj;
- static int max;
- public:
- SocialNetwork(){
- broj=0;
- niza=new User*[max];
- }
- SocialNetwork &operator+=(User *u)
- {
- niza[broj++]=u;
- return *this;
- }
- double avgPopularity()
- {
- double av=0;
- for(int i=0;i<broj;i++)
- {
- av+=niza[i]->popularity();
- }
- return av/broj;
- }
- void changeMaximumSize(int n)
- {
- max=n;
- }
- };
- int SocialNetwork::max=5;
- int main() {
- SocialNetwork network = SocialNetwork();
- int n;
- cin >> n;
- char username[50];
- char password[50];
- char email[50];
- int userType;
- for (int i=0; i < n; ++i) {
- cin >> username;
- cin >> password;
- cin >> email;
- cin >> userType;
- if (userType == 1) {
- int friends;
- int likes;
- int comments;
- cin >> friends >> likes >> comments;
- // TODO: Try-catch
- try{
- User * u = new FacebookUser(username,password,email,friends,likes,comments);
- network += u;
- }
- catch(InvalidPassword obj)
- {
- obj.message();
- }
- catch(MaximumSizeLimit obj)
- {
- obj.message();
- }
- catch(InvalidEmail obj)
- {
- obj.message();
- }
- }
- else {
- int followers;
- int tweets;
- cin >> followers >> tweets;
- // TODO: Try-catch
- User * u= new TwitterUser(username,password,email,followers,tweets);
- network += u;
- }
- }
- network.changeMaximumSize(6);
- cin >> username;
- cin >> password;
- cin >> email;
- int followers;
- int tweets;
- cin >> followers >> tweets;
- // TODO: Try-catch
- User * u= new TwitterUser(username,password,email,followers,tweets);
- network += u;
- cout << network.avgPopularity();
- }
- ========================================================================================
- Broevi
- #include<iostream>
- #include<cstring>
- using namespace std;
- class ArithmeticException {
- public:
- void message() {
- cout<<"Division by zero is not allowed"<<endl;
- }
- };
- class NumbersNotDivisibleException {
- private:
- int divider;
- public:
- NumbersNotDivisibleException (int d){
- divider=d;
- }
- void message() {
- cout<<"Division by "<<divider<<" is not supported"<<endl;
- }
- };
- class ArrayFullException{
- public:
- void message() {
- cout<<"The array is full. Increase the capacity"<<endl;
- }
- };
- class IndexOutOfBoundsException {
- private:
- int index;
- public:
- IndexOutOfBoundsException(int i){
- index=i;
- }
- void message() {
- cout<<"Index "<<index<<" is out of bounds"<<endl;
- }
- };
- class NumbersIsNotPositiveException {
- private:
- int number;
- public:
- NumbersIsNotPositiveException(int n) {
- number=n;
- }
- void message() {
- cout<<"Number "<<number<<" is not positive integer"<<endl;
- }
- };
- class PositiveIntegers {
- private:
- int * numbers;
- int size;
- int capacity;
- void copy(const PositiveIntegers &ps){
- numbers = new int [ps.capacity];
- for (int i=0;i<ps.size;i++)
- numbers[i]=ps.numbers[i];
- size=ps.size;
- capacity=ps.capacity;
- }
- public:
- PositiveIntegers(int capacity=0){
- this->capacity=capacity;
- numbers = new int [capacity];
- size = 0;
- }
- PositiveIntegers (const PositiveIntegers &ps){
- copy(ps);
- }
- PositiveIntegers &operator = (const PositiveIntegers &ps){
- if (this!=&ps){
- delete [] numbers;
- copy(ps);
- }
- return *this;
- }
- ~PositiveIntegers() {
- //delete [] numbers;
- }
- void increaseCapacity(int c) {
- int * tmp = new int [capacity+c];
- for (int i=0;i<size;i++){
- tmp[i]=numbers[i];
- }
- delete [] numbers;
- numbers=tmp;
- capacity+=c;
- }
- PositiveIntegers &operator += (int newNumber){
- if (size==capacity)
- throw ArrayFullException();
- if (newNumber<=0)
- throw NumbersIsNotPositiveException(newNumber);
- numbers[size++]=newNumber;
- return *this;
- }
- PositiveIntegers operator * (int x) {
- PositiveIntegers pi (*this);
- for (int i=0;i<pi.size;i++)
- pi.numbers[i]*=x;
- return pi;
- }
- PositiveIntegers operator / (int x){
- if (x==0)
- throw ArithmeticException();
- for (int i=0;i<size;i++)
- if (numbers[i]%x!=0)
- throw NumbersNotDivisibleException(x);
- PositiveIntegers pi (*this);
- for (int i=0;i<pi.size;i++)
- pi.numbers[i]/=x;
- return pi;
- }
- int &operator [] (int i){
- if (i<0 || i>this->size)
- throw IndexOutOfBoundsException(i);
- return numbers[i];
- }
- void print () {
- cout<<"Size: "<<size<<" Capacity: "<<capacity<<" Numbers: ";
- for (int i=0;i<size;i++)
- cout<<numbers[i]<<" ";
- cout<<endl;
- }
- };
- int main() {
- int n,capacity;
- cin >> n >> capacity;
- PositiveIntegers pi (capacity);
- for (int i=0;i<n;i++){
- int number;
- cin>>number;
- try{
- //cout<<number;
- pi+=number;
- }
- catch (ArrayFullException &e){
- e.message();
- }
- catch (NumbersIsNotPositiveException &e){
- e.message();
- }
- }
- cout<<"===FIRST ATTEMPT TO ADD NUMBERS==="<<endl;
- pi.print();
- int incCapacity;
- cin>>incCapacity;
- pi.increaseCapacity(incCapacity);
- cout<<"===INCREASING CAPACITY==="<<endl;
- pi.print();
- int n1;
- cin>>n1;
- for (int i=0;i<n1;i++){
- int number;
- cin>>number;
- try{
- //cout<<number;
- pi+=number;
- }
- catch (ArrayFullException &e){
- e.message();
- }
- catch (NumbersIsNotPositiveException &e){
- e.message();
- }
- }
- cout<<"===SECOND ATTEMPT TO ADD NUMBERS==="<<endl;
- pi.print();
- PositiveIntegers pi1;
- cout<<"===TESTING DIVISION==="<<endl;
- try{
- pi1 = pi/0;
- pi1.print();
- }
- catch (ArithmeticException &e){
- e.message();
- }
- catch (NumbersNotDivisibleException &e){
- e.message();
- }
- try{
- pi1 = pi/1;
- pi1.print();
- }
- catch (ArithmeticException &e){
- e.message();
- }
- catch (NumbersNotDivisibleException &e){
- e.message();
- }
- try{
- pi1 = pi/2;
- pi1.print();
- }
- catch (ArithmeticException &e){
- e.message();
- }
- catch (NumbersNotDivisibleException &e){
- e.message();
- }
- cout<<"===TESTING MULTIPLICATION==="<<endl;
- pi1 = pi*3;
- pi1.print();
- cout<<"===TESTING [] ==="<<endl;
- try{
- cout<<"PositiveIntegers[-1] = "<<pi[-1]<<endl;
- }
- catch (IndexOutOfBoundsException &e){
- e.message();
- }
- try{
- cout<<"PositiveIntegers[2] = "<<pi[2]<<endl;
- }
- catch (IndexOutOfBoundsException &e){
- e.message();
- }
- try{
- cout<<"PositiveIntegers[3] = "<<pi[3]<<endl;
- }
- catch (IndexOutOfBoundsException &e){
- e.message();
- }
- try{
- cout<<"PositiveIntegers[12] = "<<pi[12]<<endl;
- }
- catch (IndexOutOfBoundsException &e){
- e.message();
- }
- return 0;
- }
- ============================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement