https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h
Chapter 15 // Class Definition Drills
1. Define a struct Person containing a string name and an int age.
2. Define a variable of type Person , initialise it with "Goofy" and 63, and write it to the screen (cout).
3. Define an input (>>) and an output (<<) operator for Person; read in a Person from the keyboard (cin) and write it out to the screen (cout).
4. Give Person a constructor initialising name and age.
5. Make the representation of Person private, and provide const member functions name() and age() to read the name and age.
6. Modify >> and << to work with the redefined Person.
7. Modify the constructor to check that age is [0:150] and that name doesn't contain any of the characters ; : " ' [] * & ^ % $ # @ ! . Use error() in case of error. Test.
Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2015/Class%20Definition%20Drills/Drills1-72. Define a variable of type Person , initialise it with "Goofy" and 63, and write it to the screen (cout).
3. Define an input (>>) and an output (<<) operator for Person; read in a Person from the keyboard (cin) and write it out to the screen (cout).
4. Give Person a constructor initialising name and age.
5. Make the representation of Person private, and provide const member functions name() and age() to read the name and age.
6. Modify >> and << to work with the redefined Person.
7. Modify the constructor to check that age is [0:150] and that name doesn't contain any of the characters ; : " ' [] * & ^ % $ # @ ! . Use error() in case of error. Test.
No comments:
Post a Comment