Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- using namespace std::literals::string_literals;
- class rollno {
- private:
- std::string name_;
- uint32_t nr_;
- public:
- rollno(std::string const & name = ""s, uint32_t nr = 0u) : name_ { name }, nr_ { nr } {}
- rollno(rollno const & that) = default;
- rollno(rollno && that) = default;
- ~rollno() = default;
- rollno & operator=(rollno const & that) = default;
- rollno & operator=(rollno && that) = default;
- std::string name(void) const { return name_; }
- std::string name(std::string const & name) { name_ = name; return name_; }
- unsigned nr(void) const { return nr_; }
- unsigned nr(uint32_t nr) { nr_ = nr; return nr_; }
- };
- int main() {
- auto roll = std::vector<rollno> {
- { "Rohit"s, 3u, },
- { "Priya"s, 4u, },
- { "Sneha"s, 5u, },
- };
- auto rt1 = rollno("Nish"s, 10u);
- roll.push_back(rt1);
- rt1.name("Mehrdad"s);
- rt1.nr(11u);
- roll.push_back(rt1);
- std::cout << "Student rollcall is:\n"s;
- for (rollno & rn : roll) {
- std::cout << std::setw(10) << rn.name()
- << std::setw(3) << rn.nr()
- << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement