Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- class Organization {
- public:
- Organization() {};
- Organization(const std::string& name) : name(name) {};
- void setName(const std::string& newName);
- std::string getName() const;
- private:
- std::string name;
- };
- void Organization::setName(const std::string& newName){
- this->name = newName;
- }
- std::string Organization::getName() const{
- return this->name;
- }
- void Print1(const std::vector<Organization>& vec) {
- for (auto it = vec.begin(); it < vec.end(); it++) {
- std::cout << it->getName() << std::endl;
- }
- }
- int main(){
- std::vector<Organization> organizations;
- int lenght;
- std::cout << "Input how many objects do you want: ";
- std::cin >> lenght;
- std::string tmpName;
- for (int i = 0; i < lenght; i++) {
- std::cout << "object " << i << ": ";
- std::cin >> tmpName;
- organizations.push_back(Organization(tmpName));
- }
- std::string userDecision;
- std::cout << "If you wanna add one more object then write: yes! ";
- std::cin >> userDecision;
- if (userDecision == "yes") {
- std::cin >> tmpName;
- organizations.push_back(Organization(tmpName));
- }
- for (size_t i = 0; i < organizations.size(); i++) {
- std::cout << organizations[i].getName() << std::endl;
- }
- Print1(organizations);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement