473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

C++ Book program with classes

5
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
Jan 27 '08 #1
1 3559
weaknessforcats
9,208 Expert Mod 8TB
1) You forgot the semi-colon at the end of your class declaration.

2) Your data member for the title is one char. That's a short title.
I recommend a string object. If that's not possible, then use an array.
If you use an array, you will need to copy the constructo argument to the array.

3) main() returns an int. Only as Microsoft does main() return a void- and they have been backing away from that screw-up for years.
Jan 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Dragon | last post by:
Hi, I have 'some' experience in VB. I would like to learn C-Sharp and would like to know if the following book is any good or not. Thank you. Microsoft Visual C# .NET Step by Step - Version...
1
by: Mike | last post by:
Hi, I'm auctioning the book "The C++ Programming Language" 3rd Ed. by Bjarne Stroustrup on ebay, details as follows or see eBay item number 250030480853. Softback. Condition : Good. Pub....
13
by: YoVoltron | last post by:
I am just starting this "appointment book" java program and would appreciate some basis direction. I do not expect anyone to write the code for me but i would like opinions on how to best handle the...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
14
by: At_sea_with_C | last post by:
Hello all, Im some way in C and i have to start on C++ to. I want your opinions on Teach yourself C++ in 21 days by Jessi Liberty. Can I go with it as my first book are are there better ones? ...
4
by: Johs | last post by:
I am looking for a good C++ book for beginners. I have some experience with C and a lot of experience with Java. I am currently reading Bjarne Stroustrups C++ Programming Language but it starts off...
14
by: xtheendx | last post by:
I am writing a gradbook type program. It first allows the user to enter the number of students they want to enter. then allows them to enter the first name, last name, and grade of each student. The...
11
by: allendowney | last post by:
Hi All, I am working on a revised edition of How To Think Like a Computer Scientist, which is going to be called Think Python. It will be published by Cambridge University Press, but there...
6
by: nembo kid | last post by:
According to accu.org, Deitel's "How to program" is not reccomended. I don't agree. I have the 3rd ed. and I find it ok. What do you think about this book? Thanks in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.