Apr 17, 2012 at 12:19am UTC
Please help!!!! This is my program:
Last edited on Apr 17, 2012 at 12:57am UTC
Apr 17, 2012 at 12:22am UTC
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;
}
Apr 17, 2012 at 12:25am UTC
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.
Apr 17, 2012 at 12:51am UTC
Anyone?? I really need help.
Apr 17, 2012 at 1:09am UTC
I could post my program clearer, but I don't know how to.
Apr 17, 2012 at 1:58am UTC
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 Apr 17, 2012 at 2:00am UTC
Apr 17, 2012 at 2:03am UTC
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 Apr 17, 2012 at 2:32am UTC
Apr 17, 2012 at 2:05am UTC
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 Apr 17, 2012 at 2:06am UTC
Apr 17, 2012 at 2:12am UTC
I put the code clearer. Please Help!!!!
Apr 17, 2012 at 2:26am UTC
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 Apr 17, 2012 at 2:29am UTC
Apr 17, 2012 at 2:38am UTC
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
Apr 17, 2012 at 4:00am UTC
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?
Apr 17, 2012 at 5:45am UTC
> '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 Apr 17, 2012 at 5:47am UTC
Apr 17, 2012 at 4:42pm UTC
It still doesn't work. How do I store the objects in an array?
Apr 17, 2012 at 7:04pm UTC
Isn't there are way I can use loops to do this??
Apr 17, 2012 at 8:24pm UTC
ANYONE?????????????????????I can't put the name, then what's the point of the input file.