ignore- reposted with new program

I hAve asked this question for several days. I am struggling with this program. There is a input file which is of .txt. It contains list of about fifty books in the format: catalogue_number, author_last_name, author_first_name_, book_title, genre, availabilty.
**Catalogue number's are four characters like "A145"
The program needs to store the objects (class book catalogue_number, author_last_name, author_first_name_, book_title, genre, availabilty) in an array, sort author_last_name, and output as a .txt file.

I can't use vector, command line or anything like that. PLEASE!! PLEASE!! PLEASE!! I have been trying for days to make my program work the way it's supposed to work.
Last edited on
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
38
39
40
41
#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;
}
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
32
33
34
35
36
37
38
39
40
#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include "book.h"

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

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

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

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

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

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

void Book::output()
{
     for (int i = 0; i < numOfNames; i++) {
     for (int j = 1; j <= numOfNames; j++) {
          if (counter[j] < counter[j - 1])
               swap(counter[j], counter[j - 1]);
 }

 std ::cout<<catalogue_number<<author_last_name<<author_first_name<<book_title<<genre<<availability;
}
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
24
25
#ifndef _BOOK_H_
#define _BOOK_H_

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


private:
    std:: string catalogue_number;
    std:: string author_last_name;
    std:: string author_first_name;
    std:: string book_title;
    std:: string genre;
    std:: string availability;
};

#endif 
Last edited on
to sort your data see http://www.cplusplus.com/forum/general/64025/
to store your data in a array just use an aray of type book
for example

1
2
const int SIZE_LIMIT = 100;
Book books[ SIZE_LIMIT];
where do I put the array?
define the array Book books[SIZE_LIMIT] ; in your main and store the data in it within the loop where you read the data from the source file.
If you read the data using a function your function should take as a reference an array of type Book.
Last edited on
Topic archived. No new replies allowed.