472,790 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 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 3466
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.
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.