Thread: problem with inventory program

  1. #1
    Registered User
    Join Date
    Oct 2005

    problem with inventory program

    this program uses fstream

    data file
    productid productname quantity purchasedate
     10212 Nescafe 20 10/12/05
    13114 Pepsi 11 10/27/05
    11234 Nescafe 14 11/01/05
    10212 Nescafe 30 11/05/05
    10212 Pepsi 32 11/15/05
    10212 Nescafe 45 11/21/05
    13114 Nescafe 26 12/01/05
    18456 Pepsi 23 12/20/05
    12223 Frito -2 09/14/05
    12223 Frito 20 9/14/05
    12223 Frito 20 13/21/05
    10212 Pepsi 32 01/15/06
    #include <iostream>
    #include <fstream>
    #include <string>
    #define SIZE 100
    using namespace std;
    class store
                 int custnum;
                 string product;
                 int quantity;
                 string month;
                 string day;
                 string year;
    store STORE1[SIZE];
    int num_lines(char name[]) // this function counts the number of lines in file
    char templine[100];
    int line=0;
        fstream in_file(name,ios::in);
          cout << "error opening file";
        while (!in_file.eof()){
                    return line;
    void period()
    void all()
         cout << "THIS IS A TEST TO SEE IF THE FUNCTION WORKS" << endl;
    void menu()
         int option,line,custnum,quantity,tmp,y=0;  
         string product;
         char month[80], day[80], year[80];
         char name[20];
         cout << "Enter name of file to load:";
         cin >> name;
         line = num_lines(name);
         fstream in_file(name,ios::in);
             cout << "error opening file";
         for(int x=0;x<line;x++)
                 in_file >> custnum;
                 in_file >> product;
                 in_file >> quantity;
                 in_file >> year;
                 tmp = atoi(month);
                 if(tmp > 12 || tmp < 1 || strlen(month) < 3 || quantity <0)
                          cout << "Line " << x << " has invalid format" << endl; 
                 else {
                      STORE1[y].custnum = custnum;
                      STORE1[y].product = product;
                      STORE1[y].quantity = quantity;
                      STORE1[y].month = month;
                      STORE1[y].day = day;
                      STORE1[y].year = year;
         cout << "The month is " << STORE1[0].month << endl;
         do {
         cout << "Please select a menu option:" << endl;
         cout << "1)Product sales in a given period" << endl;
         cout << "2)Information about all sales" << endl;
         cout << "3)Quit the program" << endl;
         cout << "Option (1,2,3):";
         cin >> option;
         switch(option) {
         case 1: 
         case 2:
         } while(option!=3);
    int main()
        return 0;   

    my plan for option one is for the user to enter the product name and specify a time period...
    for example:
    Please select a menu option: 
    1)Product sales in a given period
    2)Information about all sales
    3)Quit the program
    Option (1,2,3): 1
    Enter a product name: Nescafe
    Enter a starting date: 10/01/05
    Enter an ending date: 12/01/05
    it would show

    Product: Nescafe
    Total sales:	  135
    First time sales: 60
    Other sales:  75
    i have a problem finding which are the first time purchases within the user entered time period... how would i do this?
    Last edited by loso44x; 11-13-2005 at 08:57 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003

    i have a problem finding which are the first time purchases within the user entered time period... how would i do this?
    You need to compare all the date strings of the form 10/12/05. To compare dates, you first need to compare the year. If one is less than the other, then you know which date is earlier. If the years are the same, then you need to compare the months. If the months are the same then you need to compare the days.

    So, the first step is to separate the string into the three pieces. You can use <string> functions like substr() to do that. The 3 pieces will be strings themselves. You can actually just compare the string pieces without converting them to numbers. The <string> class has comparison operators, ==, <, and > that compare strings by looking at the ascii character codes of each character in a string. The codes for numerical characters are in the same order as the corresponding integers, so there is no need to convert the strings to numbers to compare them. For instance, the string "12" is greater than the string "07", just as the integer 12 is greater than the integer 7. The <string> comparison operators start at the first characters in the strings and compare them, if the first characters are equal, then the 2nd characters are compared, and so on.
    Last edited by 7stud; 11-14-2005 at 12:35 AM.

  3. #3
    Registered User
    Join Date
    Dec 2007


    How Can We Make A C++ Program That Uses Function That Will Help Cashier To Solve/compute Total Sales.
    You Will Use Code Instead Of Product Names.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  2. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  3. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  4. Some Problem With My Program
    By Americano in forum C Programming
    Replies: 5
    Last Post: 10-18-2003, 01:58 AM
  5. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM