Programming Exercises

1:Consider the following class declaration:
class Cow {
    char name[20];
    char * hobby;
    double weight;
public:
    Cow();
    Cow(const char * nm, const char * ho, double wt);
    Cow(const Cow c&);
    ~Cow();
    Cow & operator=(const Cow & c);
    void ShowCow() const;  // display all cow data
} ;

Provide the implementation for this class and write a short program that uses all the member functions.

2:Enhance the String class declaration (that is, upgrade string1.h to string2.h) by doing the following:
  1. Overload the + operator to allow you to join two strings into one.
  2. Provide a stringlow() member function that converts all alphabetic characters in a string to lowercase. (Don't forget the cctype family of character functions.)
  3. Provide a stringup() ...

Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.