i got this program the other day and ive just started it and i am getting some errors that i cant figure out.
requirements: 1)create a clas called Book. a Book has three data members: m_title, m_id and m_flag to tell whether the book is in or checked out. 2)Write a constructor for Book. write a constructor that takes 3 parameters: Book(char * title, int id, bool flag) and initializes the 3 data members accordingly. in addition print out a message inside your constructor whenever it gets called. 3) Instantiate or create a few Book objects to test your constructor in main()-notice when your constructor is called. Book book1("Petzlod", 100, false);
Book book2("Nagler", 101, true);
Book book3("Meyers", 102, false);
this is where im stuck at. heres the code:
// file: book.h
// CST 136
// Class definition for book class
#ifndef BOOK_H
#define BOOK_H
class Book{
private:
char m_title;
int m_id;
bool m_flag;
public:
Book();
Book(char * title, int id, bool flag); // 3 argument constructor
}
#endif
************************************************** ************************************
// file: book.cpp
// CST 136
// code for the member functions of class Book
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "book.h"
Book::Book()
{
}
Book::Book(char * title, int id, bool flag)
{
char * m_title = title;
int m_id = id;
bool m_flag = flag;
}
************************************************** ************************************
main.cpp
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "book.h"
void main()
{
Book book1("Petzlod", 100, false);
Book book2("Nagler", 101, true);
Book book3("Meyers", 102, false);
}
************************************************** ************************
heres the errors: 1)'Book::{ctor}' : constructors not allowed a return type
2)'Book' followed by 'void' is illegal (did you forget a ';'?)
3)return type of 'main' should be 'int' instead of 'Book'
any help will work and be appreciated. thanks