C++ Exercise

Hi
I need help, I have to make in c ++ a table of books with their title, author, editorial, and genre with classes, builders, structures, etc ...
Show us what you have done so far and tell us what problems you are having.
We're not going to write your program for you.
I do not know how to do it.
I'm looking for examples online but I don't find anything good, and I get more and more messy
break it down.
design it before you code it.
how do you represent a book?
after you represent it, how do you get data into it?
what do you need to do to one book (copy? compare by (so can be sorted?)? load/save to disk or serialize? )

how do you make a table of them? is it just an stl container, or do you need more stuff?

what else is going on that you need to support?


void menu(void)
int main()
class book
{
char title;
char author;
char editorial;
char genre;

menu();
};

void menu(void){


cout << "Menu" << "\n";
cout << "1-Insert book" <<\n;

cout << "2-Delete book" <<\n;

cout << "3-Update book" <<\n;


cout << "Choose option" <<\n;
cin >> option
switch (option)

{

case '1':
cout << "Insert title" <<\n;
cin >> title;

cout << "Insert author" <<\n;
cin >> author;

cout << "Insert genre" <<\n;
cin >> genre;


This is all I do ... I think I have to use builders for something, right?




};

Here's a sample book class to get you started:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once 

#include <string>

class Book 
{	std::string title;
	int year;
	std::string author;

public:
    Book ();
    Book (const std::string & new_name, int new_year, const std::string & new_author);
        
    //	Accessors
    const std::string & getTitle() const;
    int getYear() const;
    const std::string & getAuthor() const;
    
    //	Mutators
    void setTitle (const std::string & new_title);    
    void setYear (int new_year);
    void setAuthor (const std::string & new_author);
    
    //	Comparison
    bool match_title (const std::string & target_title) const;
    bool match_author (const std::string & target_author) const;
    bool match_year (const std::string & target_year) const;
    
    friend ostream& operator << (ostream &out, const Book b);
    friend bool operator == (const Book &lhs, const Book &rhs);
};

Last edited on
I need a table with the data of each book in c ++, so I can later save the data in a text document
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void menu(void)
int main()
class book
{
char title;
char author;
char editorial;
char genre;

menu();
};

void menu(void){


cout << "Menu" << "\n";
cout << "1-Insert book" <<\n;

cout << "2-Delete book" <<\n;

cout << "3-Update book" <<\n;


cout << "Choose option" <<\n;
cin >> option
switch (option)

{

case '1':
cout << "Insert title" <<\n;
cin >> title;

cout << "Insert author" <<\n;
cin >> author;

cout << "Insert genre" <<\n;
cin >> genre;

};


Line 1: Your forward declaration needs a ;

Line 2: You forward declare main, but have not main function in your program.
Again, a forward declaration needs a ;

Line 5-8: Are you sure you want to store title, author, editorial and genre and a single character each?





void menu(void)
int main();
class book
{
char title;
char author;
char editorial;
char genre;
int main()
{
cout << "Welcome to table of books" << "\n";


menu();

};

void menu(void){


cout << "Menu" << "\n";
cout << "1-Insert book" <<\n;

cout << "2-Delete book" <<\n;

cout << "3-Update book" <<\n;


cout << "Choose option" <<\n;
cin >> option
switch (option)

{

case '1':
cout << "Insert title" <<\n;
cin >> title;

cout << "Insert author" <<\n;
cin >> author;

cout << "Insert genre" <<\n;
cin >> genre;


};

What do you mean by this? forward declaration needs a ;

Yes , I am sure , I want to store title, author, editorial and genre of each book

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?

What do you mean by this? forward declaration needs a ;

Line 1 and line 2 (see my previous post) appear to be forward declarations. Forward declarations must be terminated with a semicolon.

Yes , I am sure , I want to store title, author, editorial and genre of each book

As I pointed to you before, you're allocating only a single character for title, author, editorial and genre. How many book titles consist of only a single character? Do you know how to use std:string? You want to store those items as a strings not as single characters.

Last edited on
help us help you.
you have 2 mains in that last pile. throwing code on the page isnt helpful. I already said, stop to design a bit before you make a mess. And try to produce a small amount that works, rather than a spew that isnt even close to compiling or correct or useful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void menu(void)  //missing ; 
int main();   
class book   //class inside main 
{
char title;
char author;
char editorial;
char genre;
int main()   //main again?  where is end of class } marker?
{
cout << "Welcome to table of books" << "\n";


menu();  

};


------------------
class book //try this...
{
string title;
string author;
string editorial;
string genre;
};
Last edited on


void menu(void);

class book
{
char title;
char author;
char editorial;
char genre;

};
int main()
{
cout << "Welcome to table of books" << "\n";


menu();
};
void menu(void){


cout << "Menu" << "\n";
cout << "1-Insert book" <<\n;

cout << "2-Delete book" <<\n;

cout << "3-Update book" <<\n;


cout << "Choose option" <<\n;
cin >> option
switch (option)

{

case '1':
cout << "Insert title" <<\n;
cin >> title;

cout << "Insert author" <<\n;
cin >> author;

cout << "Insert genre" <<\n;
cin >> genre;


};

Thank you for wasting your time with me ... I think I have a little clearer now

Last edited on
You have been asked multiple times to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
Topic archived. No new replies allowed.