Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. class SMS{
  7. protected:
  8.     char broj[12];
  9.     float cena;
  10. public:
  11.     SMS(){}
  12.     SMS(char *broj, float cena){
  13.         strcpy(this->broj, broj);
  14.         this->cena=cena;
  15.     }
  16.     virtual float SMS_cena()=0;
  17.     float danok(){
  18.         return cena-=(18/cena)*100;
  19.     }
  20.     virtual ~SMS(){}
  21. };
  22.  
  23. class RegularSMS:public SMS{
  24. private:
  25.     char *text;
  26.     bool roaming;
  27. public:
  28.     RegularSMS(){}
  29.     RegularSMS(char *broj, float cena, char *text, bool roaming):SMS(broj, cena){
  30.         strcpy(this->broj, broj);
  31.         this->cena=cena;
  32.         this->text=new char[strlen(text)+1];
  33.         strcpy(this->text, text);
  34.         this->roaming=roaming;
  35.     }
  36.     float SMS_cena(){
  37.         if(strlen(text)<160){
  38.             if(roaming==true){
  39.                 return SMS::danok()+cena*3;
  40.             }
  41.             else{
  42.                 return SMS::danok()+cena*0.18;
  43.             }
  44.         }
  45.         else{
  46.             if(roaming){
  47.                 return SMS::danok()+(2*cena*3);
  48.             }
  49.             else{
  50.                 return SMS::danok()+(2*cena*0.18);
  51.             }
  52.         }
  53.     }
  54.     friend ostream &operator<<(ostream &o, RegularSMS &rs){
  55.         o<<"Tel: "<<rs.broj<<" - cena: "<<rs.SMS_cena()<<endl;
  56.         return o;
  57.     }
  58. };
  59.  
  60. class SpecialSMS:public SMS{
  61. private:
  62.     bool humanitarni;
  63.     int procent;
  64. public:
  65.     SpecialSMS(char *broj, float cena, bool humanitarni):SMS(broj, cena){
  66.         strcpy(this->broj, broj);
  67.         this->cena=cena;
  68.         this->humanitarni=humanitarni;
  69.     }
  70.     float SMS_cena(){
  71.         if(humanitarni){
  72.             return SMS::danok()+cena*1.5;
  73.         }
  74.         else{
  75.             return cena;
  76.         }
  77.     }
  78.     friend ostream &operator<<(ostream &o, SpecialSMS &ss){
  79.         o<<"Tel: "<<ss.broj<<" - cena: "<<ss.SMS_cena()<<endl;
  80.         return o;
  81.     }
  82.     void set_sProcent(int procent){
  83.         this->procent=procent;
  84.     }
  85.    
  86. };
  87.  
  88. void vkupno_SMS(SMS **poraka, int n){
  89.     int brRegularni=0;
  90.     int brSpecijalni=0;
  91.     for(int i=0; i<n; i++){
  92.        
  93.     }
  94.     //cout<<"Vkupno ima "<<brRegularni<<" regularni SMS poraki i nivnata cena e: "<<poraka[i]->SMS_cena();
  95.     //cout<<"Vkupno ima "<<brSpecijalni<<" specijalni SMS poraki i nivnata cena e: "<<poraka[i]->SMS_cena();  
  96. }
  97.  
  98. int main(){
  99.  
  100.     char tel[20], msg[1000];
  101.     float cena;
  102.     float price;
  103.     int p;
  104.     bool roam, hum;
  105.     SMS  **sms;
  106.     int n;
  107.     int tip;
  108.  
  109.     int testCase;
  110.     cin >> testCase;
  111.  
  112.     if (testCase == 1){
  113.         cout << "====== Testing RegularSMS class ======" << endl;
  114.         cin >> n;
  115.         sms = new SMS *[n];
  116.  
  117.         for (int i = 0; i < n; i++){
  118.             cin >> tel;
  119.             cin >> cena;
  120.             cin.get();
  121.             cin.getline(msg, 1000);
  122.             cin >> roam;
  123.             cout << "CONSTRUCTOR" << endl;
  124.             sms[i] = new RegularSMS(tel, cena, msg, roam);
  125.             cout << "OPERATOR <<" << endl;
  126.             //cout << *sms[i];
  127.         }
  128.         for (int i = 0; i<n; i++) delete sms[i];
  129.         delete[] sms;
  130.     }
  131.     if (testCase == 2){
  132.         cout << "====== Testing SpecialSMS class ======" << endl;
  133.         cin >> n;
  134.         sms = new SMS *[n];
  135.  
  136.         for (int i = 0; i < n; i++){
  137.             cin >> tel;
  138.             cin >> cena;
  139.             cin >> hum;
  140.             cout << "CONSTRUCTOR" << endl;
  141.             sms[i] = new SpecialSMS(tel, cena, hum);
  142.             cout << "OPERATOR <<" << endl;
  143.             //cout << *sms[i];
  144.         }
  145.         for (int i = 0; i<n; i++) delete sms[i];
  146.         delete[] sms;
  147.     }
  148.     if (testCase == 3){
  149.         cout << "====== Testing method vkupno_SMS() ======" << endl;
  150.         cin >> n;
  151.         sms = new SMS *[n];
  152.  
  153.         for (int i = 0; i<n; i++){
  154.  
  155.             cin >> tip;
  156.             cin >> tel;
  157.             cin >> cena;
  158.             if (tip == 1) {
  159.  
  160.                 cin.get();
  161.                 cin.getline(msg, 1000);
  162.                 cin >> roam;
  163.  
  164.                 sms[i] = new RegularSMS(tel, cena, msg, roam);
  165.  
  166.             }
  167.             else {
  168.                 cin >> hum;
  169.  
  170.                 sms[i] = new SpecialSMS(tel, cena, hum);
  171.             }
  172.         }
  173.  
  174.         vkupno_SMS(sms, n);
  175.         for (int i = 0; i<n; i++) delete sms[i];
  176.         delete[] sms;
  177.     }
  178.     if (testCase == 4){
  179.         cout << "====== Testing RegularSMS class with a changed percentage======" << endl;
  180.         SMS *sms1, *sms2;
  181.             cin >> tel;
  182.             cin >> cena;
  183.             cin.get();
  184.             cin.getline(msg, 1000);
  185.             cin >> roam;
  186.             sms1 = new RegularSMS(tel, cena, msg, roam);
  187.             //cout << *sms1;
  188.  
  189.             cin >> tel;
  190.             cin >> cena;
  191.             cin.get();
  192.             cin.getline(msg, 1000);
  193.             cin >> roam;
  194.             cin >> p;
  195.             //RegularSMS::set_rProcent(p);
  196.             sms2 = new RegularSMS(tel, cena, msg, roam);
  197.             //cout << *sms2;
  198.  
  199.         delete sms1, sms2;
  200.     }
  201.     if (testCase == 5){
  202.         cout << "====== Testing SpecialSMS class with a changed percentage======" << endl;
  203.         SMS *sms1, *sms2;
  204.             cin >> tel;
  205.             cin >> cena;
  206.             cin >> hum;
  207.             sms1 = new SpecialSMS(tel, cena, hum);
  208.             //cout << *sms1;
  209.  
  210.             cin >> tel;
  211.             cin >> cena;
  212.             cin >> hum;
  213.             cin >> p;
  214.             //SpecialSMS::set_sProcent(p);
  215.             sms2 = new SpecialSMS(tel, cena, hum);
  216.             //cout << *sms2;
  217.  
  218.         delete sms1, sms2;
  219.     }
  220.  
  221.     return 0;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement