-
Notifications
You must be signed in to change notification settings - Fork 2
/
Billing.cpp
198 lines (186 loc) · 3.69 KB
/
Billing.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* Computer project on retail Billing
made by : rakesh kumar
Last compiled on : 23-10-2018
*/
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string.h>
#include<conio.h>
using namespace std;
void line(int n=120, char ch='-'){
for(int i=0;i<n;i++)
cout<<ch;
}
class item{
private:
int item_no;
char item_name[30];
float item_price;
public:
void read_data();
void show_data();
void add_item();
void edit_item();
void delete_item();
void report();
void main_menu();
int item_price(int tempNumber);
char* item_name(int tempNumber);
};
class Billing:public item{
private:
int invoice_no;
char customer_name[30];
char phone_no[20];
float amount;
public:
void input_data();
void save_info();
void report();
};
void Billing::input_data(){
int titem_no;
float amount=0;
cout<<"Invoice No:";
cin>>invoice_no;
cout<<"Customer Name :";
fflush(stdin);
cin.getline(customer_name,30);
cout<<"Phone No:";
fflush(stdin);
cin.getline(phone_no);
do{
cout<<"Item No:";
cin>>titem_no;
name = item_name(titem_no);
cout<<"Name :"<<name;
price = item_price(item_no);
cout<<"Price :"<<name;
cout<<Price;
cout<<"Qty :";
cin>>qty;
amount += price*qty;
cout<<"Total Payable amount :"<<amount;
}while(titem_no!=0);
return;
}
void item::read_data(){
cout<<"Item No :";
cin>>item_no;
cout<<"Item Name :";
fflush(stdin);
cin.getline(item_name,30);
cout<<"Item Price :";
fflush(stdin);
cin>>item_price;
}
void item::show_data(){
cout<<"Item No :"<<item_no;
cout<<"item Name :"<<item_name;
cout<<"item Price :"<<item_price;
}
void item::add_item(){
ofstream fout;
fout.open("item.dat",ios::app|ios::binary);
read_data();
fout.write((char*)this,sizeof(item));
fout.close();
}
void item::delete_item(){
int titem_no;
ifstream fin;
ofstream fout;
system("cls");
cout<<"\n\t\t Delete Item Screen\n";
cout<<"Item No :";
cin>>titem_no;
fin.open("item.dat",ios::in|ios::binary);
fout.open("temp.dat",ios::out|ios::binary);
while(fin.read((char*)this,sizeof(item)))
{
if(item_no!=titem_no)
fout.write((char*)this,sizeof(item));
}
fin.close();
fout.close();
remove("item.dat");
rename("temp.dat","item.dat");
}
void item::edit_item(){
int titem_no;
ifstream fin;
ofstream fout;
system("cls");
cout<<"\n\t\t Edit Item Screen\n";
cout<<"Item No :";
cin>>titem_no;
fin.open("item.dat",ios::in|ios::binary);
fout.open("temp.dat",ios::out|ios::binary);
while(fin.read((char*)this,sizeof(item)))
{
if(item_no==titem_no)
read_data();
fout.write((char*)this,sizeof(item));
}
fin.close();
fout.close();
remove("item.dat");
rename("temp.dat","item.dat");
}
void item::report(){
ifstream fin;
fin.open("item.dat",ios::in|ios::binary);
system("cls");
cout<<"\n\t\t\t\t\t\t List of Items\n\n";
line();
cout<<"S.NO\t\t\tItem No\t\t\t Item Name \t\t\t Price\n";
line();
int i=1;
while(fin.read((char*)this,sizeof(item)))
{
cout<<i++<<"\t\t\t"<<item_no<<"\t\t\t"<<item_name<<"\t\t\t\t "<<item_price<<endl;
}
line();
fin.close();
getch();
}
void item::main_menu(){
int choice;
do{
system("cls");
cout<<"\n\t\t\t ITEM MENU";
cout<<"\n\t\t\t\t1. Add Item";
cout<<"\n\t\t\t\t2. Delete Item";
cout<<"\n\t\t\t\t3. Edit Item";
cout<<"\n\t\t\t\t4. Report";
cout<<"\n\t\t\t\t5. Exit";
cout<<"\n\t\t\t\t Enter your choice(1..5) :";
cin>>choice;
switch(choice)
{
case 1:
add_item();
break;
case 2:
delete_item();
break;
case 3:
edit_item();
break;
case 4:
report();
break;
case 5:
break;
default:
cout<<"\n\n Wrong choice...Try again";
getch();
}
}while(choice!=5);
}
int main(){
item A;
A.main_menu();
return 0;
}