c++ programming

Please help!!!! This is my program:
Last edited on
This is my main.cpp:
#include <iostream>
#include <fstream>
#include <stdlib.h>

#include "book.h"
#include "book.cpp"
using std::ifstream;
using std::ofstream;
using std::cout;

int main()
{
ifstream inStream;
ofstream outStream;

inStream.open("library_holdings.txt");
if(inStream.fail())
{
cout <<"Input file opening failed.\n";
exit(1);
}
outStream.open("computational_task_1.txt");
if(outStream.fail())
{
cout <<"Output file opening failed.\n";
exit(1);
}

outStream<<Book.output();


inStream.close();
outStream.close();
system ("PAUSE");
return 0;
}

This is my book.h
#ifndef _BOOK_H_
#define _BOOK_H_

class Book
{
public:
void output();
string getCatalogue_Number();
string getAuthor_Last_Name();
string getAuthor_First_Name();
string getBook_Title;
string getGenre;
string getAvailability;

private:
string str = ("catalogue_number""author_last_name""author_first_name""book_title""genre""availabilty");
string catalogue_number;
string author_last_name;
string author_first_name;
string book_title;
string genre;
string availabilty;
};
#endif

This is my book.cpp:
#include <stdlib.h>
#include <string>
#include "book.h"

string Book::getCatalogue_Number()
{
return catalogue_number;
}

string Book::getAuthor_Last_Name()
{
return author_last_name;
}

string Book::getAuthor_First_Name()
{
return author_first_name;
}

string Book::getBook_Title()
{
return book_title;
}

string Book::getGenre()
{
return genre;
}

string Book::getAvailability()
{
return availability;
}


void Book::output()
{
cout<<catalogue_number<<author_last_name<<author_first_name<<book_title<<genre<<availabilty;
}


My input file has the a list of books in the format:
catalogue_number, author_last_name, author_first_name, book_title, genre, availabilty

I'm have to output this back to my a file using my own functions. I don't understand why my program is not doing this.


Anyone?? I really need help.
I could post my program clearer, but I don't know how to.

Please put your code in code tags
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
This is my main.cpp :
#include <iostream>
#include <fstream>
#include <stdlib.h>

#include "book.h"
#include "book.cpp"
using std::ifstream;
using std::ofstream;
using std::cout;

int main() {
    ifstream inStream;
    ofstream outStream;

    inStream.open("library_holdings.txt");
    if (inStream.fail()) {
        cout << "Input file opening failed.\n";
        exit(1);
    }
    outStream.open("computational_task_1.txt");
    if (outStream.fail()) {
        cout << "Output file opening failed.\n";
        exit(1);
    }

    outStream << Book.output();


    inStream.close();
    outStream.close();
    system("PAUSE");
    return 0;
}

This is my book.h
#ifndef _BOOK_H_
#define _BOOK_H_

class Book {
public:
    void output();
    string getCatalogue_Number();
    string getAuthor_Last_Name();
    string getAuthor_First_Name();
    string getBook_Title;
    string getGenre;
    string getAvailability;

private:
    string str = ("catalogue_number""author_last_name""author_first_name""book_title""genre""availabilty");
    string catalogue_number;
    string author_last_name;
    string author_first_name;
    string book_title;
    string genre;
    string availabilty;
};
#endif

This is my book.cpp :
#include <stdlib.h>
#include <string>
#include "book.h"

string Book::getCatalogue_Number() {
    return catalogue_number;
}

string Book::getAuthor_Last_Name() {
    return author_last_name;
}

string Book::getAuthor_First_Name() {
    return author_first_name;
}

string Book::getBook_Title() {
    return book_title;
}

string Book::getGenre() {
    return genre;
}

string Book::getAvailability() {
    return availability;
}

void Book::output() {
    cout << catalogue_number << author_last_name << author_first_name << book_title << genre << availabilty;
}
Last edited on
How??
This is my main.cpp:
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
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

#include "book.h"
#include "book.cpp"
using std::ifstream;
using std::ofstream;

int main()
{
    Book book;
    ifstream inStream;
    ofstream outStream;

    
    inStream.open("library_holdings.txt");
    if(inStream.fail())
    {
       cout <<"Input file opening failed.\n";
       exit(1);
    }
    outStream.open("computational_task_1.txt");
    if(outStream.fail())
    {
       cout <<"Output file opening failed.\n";
       exit(1);
    }
    
     outStream<<Book.output();
    inStream.close();
   outStream.close();
   system ("PAUSE");
   return 0;
}       

Last edited on
This is my book.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef _BOOK_H_
#define _BOOK_H_

class Book {
public:
    void output();
    string getCatalogue_Number();
    string getAuthor_Last_Name();
    string getAuthor_First_Name();
    string getBook_Title;
    string getGenre;
    string getAvailability;

private:
    string str = ("catalogue_number""author_last_name""author_first_name""book_title""genre""availabilty");
    string catalogue_number;
    string author_last_name;
    string author_first_name;
    string book_title;
    string genre;
    string availabilty;
};
#endif 
Last edited on
This is my book.cpp:
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
#include <stdlib.h>
#include <string>
#include "book.h"

string Book::getCatalogue_Number() {
    return catalogue_number;
}

string Book::getAuthor_Last_Name() {
    return author_last_name;
}

string Book::getAuthor_First_Name() {
    return author_first_name;
}

string Book::getBook_Title() {
    return book_title;
}

string Book::getGenre() {
    return genre;
}

string Book::getAvailability() {
    return availability;
}

void Book::output() {
    cout << catalogue_number << author_last_name << author_first_name << book_title << genre << availabilty;
}
I put the code clearer. Please Help!!!!
Error report? whats happening? you need to be clear.


From what i can see now, in main you never declare a book object

in book.h you are missing '()' on the bottom three of your functions
Last edited on
Okay I added Book book. But there are still errors.
In book.h:
'string' does not name a type
In book.cpp:
all the returns are undeclared
I think I need the output file to know through my own functions is what's in the input file, which a list of about fifty books. I have to store the list of books in an array. How do I do this?
> 'string' does not name a type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef _BOOK_H_
#define _BOOK_H_

#include <string> // **********

class Book {
public:
    void output();
    //string getCatalogue_Number();
    std::string getCatalogue_Number() const ; // ********
    
    // etc ....

private:
    // **** delete this
    //string str = ("catalogue_number""author_last_name""author_first_name""book_title""genre""availabilty");

    // string catalogue_number;
    std::string catalogue_number; // *********

    // ec ...
};


1
2
3
4
5
6
//string Book::getCatalogue_Number() {
std::string Book::getCatalogue_Number() const { // *****   
    return catalogue_number;
}

// etc ... 
Last edited on
It still doesn't work. How do I store the objects in an array?
1
2
3
4
Book Books[15]
Books[2].Name = "Harry Potter"
Books[3].Name = "Animal Kingdom"
etc... etc..
Isn't there are way I can use loops to do this??
ANYONE?????????????????????I can't put the name, then what's the point of the input file.
use for loops:

1
2
3
4
5
Book1[10] = {"Harry potter", "Lord of the rings".. etc.. etc..};
Book Books[15];
for(int i = 0; i <(ARRAYSIZE);i++){
    Books[i].SetName(Book1[i]);
    }
Topic archived. No new replies allowed.