Last active
          August 29, 2015 14:10 
        
      - 
      
- 
        Save mariusmg2/e84c6ea9e35329ee661e to your computer and use it in GitHub Desktop. 
    Tema 2 Lab. POO
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Version2, pastebin: http://pastebin.com/raw.php?i=Q4A83hdM [OUTDATED] | |
| // clang++ -Wall -O3 -g tema2poo.c++ -o poo -std=c++14 | |
| #include <iostream> | |
| #include <string> | |
| #include <list> | |
| using std::cin; | |
| using std::cout; | |
| using std::string; | |
| using std::endl; | |
| using std::list; | |
| using std::getline; | |
| class Phone { | |
| private: | |
| string producer, color; | |
| int weight, dimension; | |
| public: | |
| Phone(string &producer, string &color, int &weight, int &dimension): | |
| producer(producer), color(color), weight(weight), dimension(dimension) {}; | |
| Phone(void): | |
| producer(""), color(""), weight(0), dimension(0) {}; | |
| virtual ~Phone(void) {}; | |
| string getProducer(void) const; | |
| string getColor(void) const; | |
| int getWeight(void) const; | |
| int getDimension(void) const; | |
| virtual void displayInfo(void) const; | |
| }; | |
| class mobilePhone: public Phone { | |
| private: | |
| string operatingSystem, displayType; | |
| public: | |
| mobilePhone(string &producer, string &color, int &weight, int &dimension, string &operatingSystem, string &displayType): | |
| Phone(producer, color, weight, dimension), operatingSystem(operatingSystem), displayType(displayType) {}; | |
| ~mobilePhone(void) {}; | |
| string getOS(void) const; | |
| string getDisplayType(void) const; | |
| virtual void displayInfo(void) const; | |
| }; | |
| class wirePhone: public Phone { | |
| private: | |
| string type; | |
| unsigned int ringtoneVolume; | |
| public: | |
| wirePhone(string &producer, string &color, int &weight, int &dimension, string &type, unsigned int ringtoneVolume): | |
| Phone(producer, color, weight, dimension), type(type), ringtoneVolume(ringtoneVolume) {}; | |
| ~wirePhone(void) {}; | |
| string getType(void) const; | |
| unsigned int getRingtoneVolume(void) const; | |
| virtual void displayInfo(void) const; | |
| }; | |
| string Phone::getProducer(void) const { | |
| return (string)producer; | |
| } | |
| string Phone::getColor(void) const { | |
| return (string)color; | |
| } | |
| int Phone::getWeight(void) const { | |
| return (int)weight; | |
| } | |
| int Phone::getDimension(void) const { | |
| return (int)dimension; | |
| } | |
| void Phone::displayInfo(void) const { | |
| cout << endl << "Producer: " << producer; | |
| cout << endl << "Color: " << color; | |
| cout << endl << "Weight: " << weight; | |
| cout << endl << "Dimension: " << dimension; | |
| } | |
| string mobilePhone::getOS(void) const { | |
| return (string)operatingSystem; | |
| } | |
| string mobilePhone::getDisplayType(void) const { | |
| return (string)displayType; | |
| } | |
| void mobilePhone::displayInfo(void) const { | |
| Phone::displayInfo(); | |
| cout << endl << "Operating system: " << operatingSystem; | |
| cout << endl << "Display type: " << displayType << endl; | |
| } | |
| string wirePhone::getType(void) const { | |
| return (string)type; | |
| } | |
| unsigned int wirePhone::getRingtoneVolume(void) const { | |
| return (unsigned int)ringtoneVolume; | |
| } | |
| void wirePhone::displayInfo(void) const { | |
| Phone::displayInfo(); | |
| cout << endl << "Type: " << type; | |
| cout << endl << "Ringtone volume: " << ringtoneVolume << endl; | |
| } | |
| Phone *readPhone(int phtype) { | |
| string producer, color, operatingSystem, displayType, type; | |
| int weight, dimension; | |
| unsigned int ringtoneVolume; | |
| cout << endl << endl << "Producer: ", cin >> producer; | |
| cout << "Color: ", cin >> color; | |
| cout << "Weight: ", cin >> weight; | |
| cout << "Dimension: ", cin >> dimension; | |
| if(phtype == 1) { | |
| cout << "Operating System: ", cin >> operatingSystem; | |
| cout << "Display type: ", cin >> displayType; | |
| return (Phone*)(new mobilePhone(producer, color, weight, dimension, operatingSystem, displayType)); | |
| } | |
| else if(phtype == 2) { | |
| cout << "Type: ", cin >> type; | |
| cout << "Ringtone volume: ", cin >> ringtoneVolume; | |
| return (Phone*)(new wirePhone(producer, color, weight, dimension, type, ringtoneVolume)); | |
| } | |
| return NULL; | |
| } | |
| int main(int argc, char **argv) { | |
| list<Phone*> phones; // Linked list of 'Phone' objects (actually pointers to 'Phone' objects). | |
| int opt = {0}; | |
| string aux; | |
| while(1) { | |
| cout << endl << endl << "1) Adauga telefon mobil."; | |
| cout << endl << "2) Adauga telefon fix."; | |
| cout << endl << "3) Afiseaza telefoanele."; | |
| cout << endl << "4) Cauta un telefon (dupa producator)."; | |
| cout << endl << "5) Sterge un telefon (dupa producator)."; | |
| cout << endl << "6) Iesire."; | |
| cout << endl << endl << "Optiunea aleasa: ", cin >> opt; | |
| switch(opt) { | |
| case 1: | |
| phones.push_back(readPhone(1)); | |
| break; | |
| case 2: | |
| phones.push_back(readPhone(2)); | |
| break; | |
| case 3: | |
| for(auto i : phones) { | |
| cout << "\n\n----------------------------|"; | |
| i->displayInfo(); | |
| cout << "----------------------------|"; | |
| } | |
| break; | |
| case 4: | |
| cout << "\nNumele producatorului: ", cin >> aux; | |
| for(auto i : phones) { | |
| if(i->getProducer() == aux) { | |
| i->displayInfo(); | |
| } | |
| } | |
| break; | |
| case 5: | |
| cout << "\nNumele producatorului: ", cin >> aux; | |
| for(auto i : phones) { | |
| if(i->getProducer() == aux) { | |
| phones.remove(i); | |
| cout << endl << "Producatorul " << i->getProducer() << " a fost sters.\n"; | |
| break; | |
| } | |
| } | |
| break; | |
| case 6: | |
| for(auto i : phones) { | |
| delete i; | |
| } | |
| phones.clear(); | |
| return 0; | |
| default: | |
| continue; | |
| } | |
| } | |
| return 0; | |
| } | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment