Libary book store program with fstream

hi

I need to make a book store libary for my dad because he said he wanted one for his small schoollibary (where he works) and I am on informatics school so I should made it. But I have a real problem with reading from files and writing to it.

This is what i want it to do:

1
2
3
4
5
6
7
8
9
10
11
12
cout<<"type the number for the action "<<endl;
	cout<<"1.    add book "<<endl;
	cout<<"2.    search book by name "<<endl;
	cout<<"3.    search book by bookcode "<<endl;
	cout<<"4.    search book by author "<<endl;
	cout<<"5.    search book by editor "<<endl;
	cout<<"6.    search book by date "<<endl;
	cout<<"7.    check registrations "<<endl;    //if the book is taken or not
	cout<<"8.    make registrations "<<endl;    //if the book is taken or not
	cout<<"9.    save data "<<endl;
	cout<<"0.    quit program with storing data "<<endl;
	cout<<"10.  quit without storing data "<<endl;


After that there is a simple switch to choose.

I am using this structurefor the seperate books
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct libary{
	
char name[100];
char author[50];
char editor [30];
int code;
bool regis;   //if it is taken or not
	
struct date{
	
	int day;
	int month;
	int year;
	}date;
	
};


But how do i write this to a .txt file so I can make it search for the books the next time after he opens the program. can anyone help me whth this. the structure is made in a array in which every single book has his own spot.

thanks for reading

a librerian and an informatics student

edit: here is as far as i got with the code without using files:
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <fstream>
using namespace std;
int menu();
void add(char &book.name[], char &book.author[], char &book.editor[], int &book.code, int &book.date.day, int &book.date.month, int &book.date.year);
void safe(char &book.name[], char &book.author[], char &book.editor[], int &book.code, bool &book.regis, int &book.date.day, int &book.date.month, int &book.date.year);
void seekmode_1(char book.name[]);
void seekmode_2(int book.code);
void seekmode_3(char book.author[]);
void seekmode_4(char book.editor[]);
void seekmode_5(char book.name[]);
void registercheck(char book.name[]);
void registermake(char book.name[]);
 
struct libary{
	
char name[100];
char author[50];
char editor [30];
int code;
bool regis;
	
struct date{
	
	int day;
	int month;
	int year;
	}date;
	
};
int main (){
	libary book[250];
	fstream data;
	data.open("datafile.txt", ios::out | ios::in);   //i got all the file things from internet, i don't have a clue what they do. 
	bool exit=false;
	while (exit!=true)
		exit=menu();
	data.close();
	return 0;
}
int menu(){
	int choise;
	bool exit=false;
	cout<<"type the number for the action "<<endl;
	cout<<"1.    add book "<<endl;
	cout<<"2.    search book by name "<<endl;
	cout<<"3.    search book by bookcode "<<endl;
	cout<<"4.    search book by author "<<endl;
	cout<<"5.    search book by editor "<<endl;
	cout<<"6.    search book by date "<<endl;
	cout<<"7.    check registrations "<<endl;
	cout<<"8.    make registrations "<<endl;
	cout<<"9.    save data "<<endl;
	cout<<"0.    quit program with storing data "<<endl;
	cout<<"10.  quit without storing data "<<endl;
	cout<<" "<<endl;
	cin>>choise;
	switch choise{
		case 1:
				add(book.name, book.author, book.editor, book.code, book.regis, book.date.day, book.date.month, book.date.year);
			break;
		case 2:
				seekmode_1(book.name);
			break;
		case 3:
				seekmode_2(book.code);
			break;
		case 4:
				seekmode_3(book.author);
			break;
		case 5:
				seekmode_4(book.editor);
			break;
		case 6:
				seekmode_5(book.name);
			break;
		case 7:
				registercheck(book.name);
			break;
		case 8:
				registermake(book.name);
			break;
		case 9:
				save(book.name, book.author, book.editor, book.code, book.regis, book.date.day, book.date.month, book.date.year);
			break;
		case 0:
				save(book.name, book.author, book.editor, book.code, book.regis, book.date.day, book.date.month, book.date.year);
			cout<<"program will exit"<<endl;
			exit=true;
			break;
		case 10:
				cout<<"program will exit"<<endl;
			exit=true;
			break;
	}
	return exit;
}
void add(char &book.name[], char &book.author[], char &book.editor[], int &book.code, int &book.date.day, int &book.date.month, int &book.date.year){
	cout<<"please fill in all the information asked for. leaving blank some info will crash the program"<<endl;
	cout<<"enter the name of the book: ";
	cin>>book.name;
	cout<<"enter the name of the author: ";
	cin>>book.author;
	cout<<"enter the editor of the book: ";
	cin>>book.editor;
	cout<<"enter the code of the book: ";
	cin>>book.code;
	cout<<"now fill in the date in the next 3 steps"<<endl;
	cout<<"enter the day of release of the book: ";
	cin>>book.date.day;
	cout<<"enter the month of release of the book: ";
	cin>>book.date.month;
	cout<<"enter the year of release of the book: ";
	cin>>book.date.year;
}


sory for the fact that it is so wide
Last edited on
I have seen a reply by mail but i can't see it here so it might look wierd for some people but
first off all thank you for the tips. the program is not on a server. i will change it to a string as you told me to. the date thing in the structure is cool, i've done it like that before. i thing nothing but the "regis" variable should be able to be edited after. but there will not be a way to edit the others after it.
Topic archived. No new replies allowed.