Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <fstream.h>
- int i=0;
- void add_data(string [], char [],float []); // prototype function
- void menu(string [],char [],float []);
- int main() //enter data type
- {
- const int SIZE = 100;
- string item_number[SIZE];
- char item_code[SIZE];
- float price[SIZE];
- {
- int pilihan;
- do{
- cout<< " ***My Happy Shop******** " << endl;
- cout<< " ***MAIN MENU******** " << endl;
- cout<< " ************** " << endl;
- cout<< " * add a record (1) ******* " << endl;
- cout<< " * display sales report for a category (2)* " << endl;
- cout<< " * display sales report for all category (3)* " << endl;
- cout<< " * exit (4) ********* " << endl;
- cin>>pilihan;
- if (pilihan == 1)
- add_data(item_number,item_code,price); // calling function
- else if (pilihan == 2)
- cout<<"1 kategori "<<endl;
- else if (pilihan == 3)
- cout<<"> kategori "<<endl;
- else if (pilihan == 4)
- exit(0);
- }
- while (pilihan == 1 || pilihan ==2 || pilihan == 3);
- }
- void readData(string matric[], int marks[])
- //open file and store data in the array
- fstream infile("input.txt", ios::in);
- while (!infile.eof()) // do until not end of file
- {
- infile >> matric[i]>>marks[i];
- i++; // number of element in the array
- }
- infile.close(); // close input file
- //open file and store data in the array
- fstream infile("sales.date", ios::in);
- while (!infile.eof()) // do until not end of file
- {
- cout<<"***************";
- infile >>item_number[i]>>item_code[i]>>price[i];
- i++; // number of element in the array
- }
- infile.close(); // close input file
- cout<<"*******************"<<price[0];
- add_data(item_number,item_code,price);
- return 0;
- }
- // function add_data to add new record
- void add_data(string item_number[], int item_code [], int price[])
- {
- char again='y';
- cout<<".............................";
- // add record to the array
- while (again == 'y')
- {
- cout<<"Enter item number, item code and price : ";
- cin>>item_number[i]>>item_code[i]>>price[i];
- cout<<"want to continue yes[y], no[n] : ";
- cin>>again;
- i++; // number of element in the array
- }
- // write contain of array to the input file
- fstream outfile("sales.date", ios::out);
- for (int j=0; j<i; j++)
- {
- outfile<<item_number[j]<<" "<<item_code[j]<<" "<<price[j];
- if (j!=i-1)
- outfile<<endl;
- }
- outfile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement