Advertisement
serd2011

226386277

Sep 28th, 2021
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. class Organization {
  5. public:
  6.     Organization() {};
  7.     Organization(const std::string& name) : name(name) {};
  8.     void setName(const std::string& newName);
  9.     std::string getName() const;
  10.  
  11. private:
  12.     std::string name;
  13. };
  14.  
  15. void Organization::setName(const std::string& newName){
  16.     this->name = newName;
  17. }
  18.  
  19. std::string Organization::getName() const{
  20.     return this->name;
  21. }
  22.  
  23.  
  24. void Print1(const std::vector<Organization>& vec) {
  25.     for (auto it = vec.begin(); it < vec.end(); it++) {
  26.         std::cout << it->getName() << std::endl;
  27.     }
  28. }
  29.  
  30. int main(){
  31.     std::vector<Organization> organizations;
  32.  
  33.     int lenght;
  34.     std::cout << "Input how many objects do you want: ";
  35.     std::cin >> lenght;
  36.  
  37.     std::string tmpName;
  38.     for (int i = 0; i < lenght; i++) {
  39.         std::cout << "object " << i << ": ";
  40.         std::cin >> tmpName;
  41.         organizations.push_back(Organization(tmpName));
  42.     }
  43.  
  44.     std::string userDecision;
  45.     std::cout << "If you wanna add one more object then write: yes! ";
  46.     std::cin >> userDecision;
  47.     if (userDecision == "yes") {
  48.         std::cin >> tmpName;
  49.         organizations.push_back(Organization(tmpName));
  50.     }
  51.  
  52.     for (size_t i = 0; i < organizations.size(); i++) {
  53.         std::cout << organizations[i].getName() << std::endl;
  54.     }
  55.     Print1(organizations);
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement