[ create a new paste ] login | about

Link: http://codepad.org/jWthnrbg    [ raw code | output | fork ]

C++, pasted on Nov 1:
#include <iostream>
#include <cstdio>
using namespace std;

class BookClub {

   public:
       //BookClub(); // Default Constructor 
       BookClub(char name[]); 
       BookClub(char name[], int id);
       void enroll(char name[]);
       void deposit(int id);
       char* list();

   private:
       char members_ [30]; 
       int  memberID_;
};

/* Definition of a Default Constructor */
/*BookClub::BookClub() {
   strcpy(members_, "");
   memberID_ = 0;
}*/

/* Definition of a Constructor */
BookClub::BookClub(char name[]) {
   strcpy(members_, name);
   memberID_ = 0;
}

/* Definition of a Constructor */
BookClub::BookClub(char name[], int id) {
   strcpy(members_, name);
   memberID_ = id;
}

void BookClub::enroll(char name[]) {
   strcpy(members_, name);
}

void BookClub::deposit(int id) {
   memberID_ = id;
}

char* BookClub::list() {
   char* buffer = new char[100];
   int buf_size = 100;
   snprintf(buffer, buf_size, "MemberName : %s MemberID : %d ", 
            members_, memberID_);
   return buffer;
}

int main()
{
    // Object Initialisation for the class BookClub
    BookClub mem1; // Constructor is called automatically
    char name[30] = "Shirley";
    int id = 5;
    mem1.enroll(name);
    mem1.deposit(id);
    cout << mem1.list();

    return 0;
}


Output:
1
2
3
In function 'int main()':
Line 57: error: no matching function for call to 'BookClub::BookClub()'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: