Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <string.h>
- using namespace std;
- class SMS{
- protected:
- char broj[12];
- float cena;
- public:
- SMS(){}
- SMS(char *broj, float cena){
- strcpy(this->broj, broj);
- this->cena=cena;
- }
- virtual float SMS_cena()=0;
- float danok(){
- return cena-=(18/cena)*100;
- }
- virtual ~SMS(){}
- };
- class RegularSMS:public SMS{
- private:
- char *text;
- bool roaming;
- public:
- RegularSMS(){}
- RegularSMS(char *broj, float cena, char *text, bool roaming):SMS(broj, cena){
- strcpy(this->broj, broj);
- this->cena=cena;
- this->text=new char[strlen(text)+1];
- strcpy(this->text, text);
- this->roaming=roaming;
- }
- float SMS_cena(){
- if(strlen(text)<160){
- if(roaming==true){
- return SMS::danok()+cena*3;
- }
- else{
- return SMS::danok()+cena*0.18;
- }
- }
- else{
- if(roaming){
- return SMS::danok()+(2*cena*3);
- }
- else{
- return SMS::danok()+(2*cena*0.18);
- }
- }
- }
- friend ostream &operator<<(ostream &o, RegularSMS &rs){
- o<<"Tel: "<<rs.broj<<" - cena: "<<rs.SMS_cena()<<endl;
- return o;
- }
- };
- class SpecialSMS:public SMS{
- private:
- bool humanitarni;
- int procent;
- public:
- SpecialSMS(char *broj, float cena, bool humanitarni):SMS(broj, cena){
- strcpy(this->broj, broj);
- this->cena=cena;
- this->humanitarni=humanitarni;
- }
- float SMS_cena(){
- if(humanitarni){
- return SMS::danok()+cena*1.5;
- }
- else{
- return cena;
- }
- }
- friend ostream &operator<<(ostream &o, SpecialSMS &ss){
- o<<"Tel: "<<ss.broj<<" - cena: "<<ss.SMS_cena()<<endl;
- return o;
- }
- void set_sProcent(int procent){
- this->procent=procent;
- }
- };
- void vkupno_SMS(SMS **poraka, int n){
- int brRegularni=0;
- int brSpecijalni=0;
- for(int i=0; i<n; i++){
- }
- //cout<<"Vkupno ima "<<brRegularni<<" regularni SMS poraki i nivnata cena e: "<<poraka[i]->SMS_cena();
- //cout<<"Vkupno ima "<<brSpecijalni<<" specijalni SMS poraki i nivnata cena e: "<<poraka[i]->SMS_cena();
- }
- int main(){
- char tel[20], msg[1000];
- float cena;
- float price;
- int p;
- bool roam, hum;
- SMS **sms;
- int n;
- int tip;
- int testCase;
- cin >> testCase;
- if (testCase == 1){
- cout << "====== Testing RegularSMS class ======" << endl;
- cin >> n;
- sms = new SMS *[n];
- for (int i = 0; i < n; i++){
- cin >> tel;
- cin >> cena;
- cin.get();
- cin.getline(msg, 1000);
- cin >> roam;
- cout << "CONSTRUCTOR" << endl;
- sms[i] = new RegularSMS(tel, cena, msg, roam);
- cout << "OPERATOR <<" << endl;
- //cout << *sms[i];
- }
- for (int i = 0; i<n; i++) delete sms[i];
- delete[] sms;
- }
- if (testCase == 2){
- cout << "====== Testing SpecialSMS class ======" << endl;
- cin >> n;
- sms = new SMS *[n];
- for (int i = 0; i < n; i++){
- cin >> tel;
- cin >> cena;
- cin >> hum;
- cout << "CONSTRUCTOR" << endl;
- sms[i] = new SpecialSMS(tel, cena, hum);
- cout << "OPERATOR <<" << endl;
- //cout << *sms[i];
- }
- for (int i = 0; i<n; i++) delete sms[i];
- delete[] sms;
- }
- if (testCase == 3){
- cout << "====== Testing method vkupno_SMS() ======" << endl;
- cin >> n;
- sms = new SMS *[n];
- for (int i = 0; i<n; i++){
- cin >> tip;
- cin >> tel;
- cin >> cena;
- if (tip == 1) {
- cin.get();
- cin.getline(msg, 1000);
- cin >> roam;
- sms[i] = new RegularSMS(tel, cena, msg, roam);
- }
- else {
- cin >> hum;
- sms[i] = new SpecialSMS(tel, cena, hum);
- }
- }
- vkupno_SMS(sms, n);
- for (int i = 0; i<n; i++) delete sms[i];
- delete[] sms;
- }
- if (testCase == 4){
- cout << "====== Testing RegularSMS class with a changed percentage======" << endl;
- SMS *sms1, *sms2;
- cin >> tel;
- cin >> cena;
- cin.get();
- cin.getline(msg, 1000);
- cin >> roam;
- sms1 = new RegularSMS(tel, cena, msg, roam);
- //cout << *sms1;
- cin >> tel;
- cin >> cena;
- cin.get();
- cin.getline(msg, 1000);
- cin >> roam;
- cin >> p;
- //RegularSMS::set_rProcent(p);
- sms2 = new RegularSMS(tel, cena, msg, roam);
- //cout << *sms2;
- delete sms1, sms2;
- }
- if (testCase == 5){
- cout << "====== Testing SpecialSMS class with a changed percentage======" << endl;
- SMS *sms1, *sms2;
- cin >> tel;
- cin >> cena;
- cin >> hum;
- sms1 = new SpecialSMS(tel, cena, hum);
- //cout << *sms1;
- cin >> tel;
- cin >> cena;
- cin >> hum;
- cin >> p;
- //SpecialSMS::set_sProcent(p);
- sms2 = new SpecialSMS(tel, cena, hum);
- //cout << *sms2;
- delete sms1, sms2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement