Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <fstream.h>
  3. int i=0;
  4. void add_data(string [], char [],float []);  // prototype function
  5. void menu(string [],char [],float []);
  6.  
  7.  
  8. int main() //enter data type
  9. {
  10.    const int SIZE = 100;
  11.    string item_number[SIZE];
  12.    char item_code[SIZE];
  13.    float price[SIZE];
  14.    
  15. {
  16.   int pilihan;
  17.    do{
  18.       cout<< " ***My Happy Shop******** " << endl;
  19.       cout<< " ***MAIN MENU******** " << endl;
  20.       cout<< " ************** " << endl;
  21.       cout<< " * add a record (1) ******* " << endl;
  22.       cout<< " * display sales report for a category (2)* " << endl;
  23.       cout<< " * display sales report for all category (3)* " << endl;
  24.       cout<< " * exit (4) ********* " << endl;
  25.       cin>>pilihan;
  26.       if (pilihan == 1)
  27.          add_data(item_number,item_code,price);  // calling function
  28.       else if (pilihan == 2)
  29.          cout<<"1 kategori "<<endl;
  30.       else if (pilihan == 3)  
  31.          cout<<"> kategori "<<endl;      
  32.       else if (pilihan == 4)
  33.          exit(0);
  34.    }
  35.    while (pilihan == 1 || pilihan ==2 || pilihan == 3);
  36.  
  37. }
  38.  
  39. void readData(string matric[], int marks[])
  40.  
  41.    //open file and store data in the array
  42.    fstream infile("input.txt", ios::in);
  43.    while (!infile.eof())          // do until not end of file
  44.    {
  45.       infile >> matric[i]>>marks[i];
  46.       i++;    // number of element in the array
  47.    }
  48.    infile.close();      // close input file
  49.  
  50.  
  51.    
  52.    
  53.  
  54.    //open file and store data in the array
  55.    fstream infile("sales.date", ios::in);
  56.    while (!infile.eof())          // do until not end of file
  57.    {
  58.       cout<<"***************";
  59.  
  60.       infile >>item_number[i]>>item_code[i]>>price[i];
  61.       i++;    // number of element in the array
  62.    }
  63.    infile.close();      // close input file
  64.    
  65.    cout<<"*******************"<<price[0];
  66.    add_data(item_number,item_code,price);
  67.    return 0;
  68. }
  69.  
  70.  
  71. // function add_data to add new record
  72. void add_data(string item_number[], int item_code [], int price[])
  73. {
  74.    char again='y';
  75.    cout<<".............................";
  76.  
  77.  
  78.    // add record to the array
  79.    while (again == 'y')
  80.    {  
  81.          cout<<"Enter item number, item code and price : ";
  82.          cin>>item_number[i]>>item_code[i]>>price[i];
  83.          
  84.          cout<<"want to continue yes[y], no[n] : ";
  85.          cin>>again;
  86.          i++;     // number of element in the array
  87.    }
  88.    
  89.  
  90.    
  91.    // write contain of array to the input file
  92.    fstream outfile("sales.date", ios::out);
  93.    for (int j=0; j<i; j++)
  94.    {
  95.        outfile<<item_number[j]<<" "<<item_code[j]<<" "<<price[j];
  96.        if (j!=i-1)          
  97.          outfile<<endl;
  98.    }
  99.    outfile.close();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement