i have a training application which incorporates c/c++ and raima database(a database system written in c)
i was able to insert some data in it but i cant read from it. the files are as follows:
Books.cpp :
#include "Booksh.h"
#include <iostream>
#include <string>
using namespace std;
info bookrec;
Books::Books(void)
{
}
Books::~Books(void)
{
}
void Books::ListAllBooks()
{
int book_count = 0;
int status;
cout << "List of books in our library:" << endl;
for (status = d_keyfrst(INFO_TITLE);
S_OKAY == status;
status = d_keynext(INFO_TITLE))
{
d_recread(&bookrec);
++book_count;
//cout << bookrec.id_code << ": " << bookrec.info_title << endl;
}
cout << "End of list. Total: " << book_count << endl;
return;
}
void Books::BookByID()
{
cout<< "bookbyid" << endl;
}
void Books::UpdateBook()
{
cout<< "updatebook" << endl;
}
void Books::DeleteBook()
{
cout<< "deletebook" << endl;
}
int Books::InsertBook()
{
cout << "id_code :" << endl;
cin >> bookrec.id_code;
cout << "info_title :" << endl;
cin >> bookrec.info_title;
cout << "author :" << endl;
cin >> bookrec.author;
cout << "publisher :" << endl;
cin >> bookrec.publisher;
cout << "pubdate :" << endl;
cin >> bookrec.pub_date;
cout << "infotype :" << endl;
cin >> bookrec.info_type;
d_fillnew(INFO, &bookrec);
cout << "successful" << endl;
return 5;
}
start.cpp
#include "Booksh.h"
#include <iostream>
using namespace std;
void menu();
int main()
{
int task = 0;
d_open("books", "o");
Books Book;
while(task != -1)
{
menu();
cin>>task;
switch(task)
{
case 1:
Book.ListAllBooks();
break;
case 2:
Book.BookByID();
break;
case 3:
Book.UpdateBook();
break;
case 4:
Book.DeleteBook();
break;
case 5:
Book.InsertBook();
break;
case -1:
d_close();
exit(0);
break;
default:
cout<< "Not a valid command" << endl;
break;
}
}
return 0;
}
void menu()
{
cout << "please choose your task below" << endl;
cout << "type 1 to list all books" <<endl;
cout << "type 2 to find a book" <<endl;
cout << "type 3 to update a book" <<endl;
cout << "type 4 to delete a book" <<endl;
cout << "type 5 to add a book" <<endl;
cout << "type -1 to quit application" <<endl;
}
books.h :
/* db_VISTA Version: 3.64 */
/* database books record/key structure declarations */
#ifndef __books_H_INCLUDED__
#define __books_H_INCLUDED__
struct info {
char id_code[16];
char info_title[80];
char author[32];
char publisher[32];
char pub_date[12];
int info_type;
};
/* record, field and set table entry definitions */
/* File Id Constants */
/* Record Name Constants */
#define INFO 10000
/* Field Name Constants */
#define ID_CODE 0L
#define INFO_TITLE 1L
#define AUTHOR 2L
#define PUBLISHER 3L
#define PUB_DATE 4L
#define INFO_TYPE 5L
/* Set Name Constants */
#endif /* __books_H_INCLUDED__ */
and finally Booksh.h :
//#pragma once
extern "C"
{
#include <vista.h>
#include "books.h"
}
#include <string>
using namespace std;
class Books
{
public:
Books(void);
public:
~Books(void);
public:
void ListAllBooks();
public:
void BookByID();
public:
void UpdateBook();
public:
void DeleteBook();
public:
int InsertBook();
};
Do you have any idea about the problem?