473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Book program with classes

5 New Member
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 3593
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
2357
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 2003 by John Sharp and Jon Jagger ISBN:0735619093
1
1958
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. Addison Wesley 1997. 3rd Edition. 910 pages. "The C++ Programming Language" by Bjarne Stroustrup is the classic C++
13
9978
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 situation. Specifically should i use <arraylist> or a hashtable or is these a better way? Thank you all in advance. here is the assignment... sorry if it is too long. In this assignment you will demonstrate your understanding of designing with...
20
2299
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
2377
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? Thanks to all. -- Email: The handle, (dot seperated), at gmail dot com.
4
2672
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 rather complex without examples of compiling modules or making and using classes. Is there some C++ books that takes you through the whole process of making modules, compiling them and using classes?
14
8066
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 program then should sort the names alphabetically by last name and display a list of all the students names and grades in alphabetical order. I have completed all my functions and classes, but i am getting a god aweful amount of errors and i am not...
11
1452
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 will still be a free version under the GNU FDL. You can see the latest version at thinkpython.com; I am revising now,
6
4319
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
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10578
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.