Thread: homework help

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    homework help

    Hi folks...hope you guys can help me and fast....i'm working on a project for school. i'm using the Dev C++ complier...i'm at my wits ends on this project. i've attached it below along with the errors i keep getting and can't figure out. PLEASE SOMEONE HELP...MY PROJECT IS DUE BY 11:59 PM EASTER STANDARD TIME. i really apprectiate it. thnx.

    Code:
    #include <iostream.h> 
    #include <fstream> 
    #include <stdlib.h> 
    #include <string> 
    #include <ctime> 
    #include <iomanip> 
    
    const int max = 50; 
    
    //class for the input file 
    class product 
    { 
     public: 
             product();//constructor 
             //copy constructor 
             product(const product&); 
             //string get();//for print function to access the members 
             //float get(); 
             //char get(); 
             void get(float&, char&, string&); 
             void set(int, string, float, char); 
             friend bool operator==(product, product); //overloading operator == 
             int product::get(int, product); 
    
     private: 
             int product_num; 
             string name; 
             float price; 
             char tax; 
     }; 
    class sList 
    { 
     public: 
             void MakeEmpty (); 
             bool IsFull (); 
             bool IsEmpty (); 
             int LengthIs (); 
             bool IsThere (int, int& location) const; 
             void Insert (product); 
             void Delete (); 
             void ResetList (); 
             product get (int&); 
    private: 
             int length; 
             product info[max]; 
             int currentPos; 
             friend void BinSearch(/*in*/ int, /*out*/ bool&, /*out*/ int&); 
    }; 
    
    int main() 
    { 
     //declarations 
    
     ifstream in; 
     ofstream out; 
     int times, pnum;//times is the quantity and pnum holds product id from input file 
     int item; //holds product id from keyboard 
     float pr;// holds price from input file 
     string n;//holds name from input file 
     bool found; 
     int place;//holds index for where the product is 
     char ta; //holds tax from input file 
     sList list; //declares variable of class slist 
     product inventory;//declares variable of class product 
     time_t rawtime; 
     float subtotal = 0;//holds subtotal 
     float totTax = 0;//holds total tax value 
    
     //initializing list 
      list.MakeEmpty(); 
    
     //opening file 
     in.open("Invent.in"); 
     while(!in) 
     { 
      cout << "Inventory file did not open. Please try again."; 
      return 1; 
     } 
      //opening output file 
      out.open("Receipts.out"); 
    
    
    //priming reading 
    in >> pnum >> n >> pr >> ta; 
    while(!in.eof()) 
    
    { 
     inventory.set (pnum, n, pr, ta); 
     list.Insert(inventory); 
     in >> pnum >> n >> pr >> ta; 
    
    } 
    int cus_no = 0; 
    do 
    { 
     cus_no++; 
    cout << "Please start processing the order in the form of productNumber"; 
    cout << "and the number of times for each product and enter 0 at the end of the"; 
    cout << "order." << endl; 
    
    cin >> item >> times; 
    //check for improper times value 
    while((times > 100) || (times <= 0)) 
     cout << "Error, times is out of range.  Please enter a number between 1 and 100"; 
    
    do{ 
    if(item !=0) 
    
    { 
       product temp; //holds temp value for product class 
      BinSearch(item, found, place); 
      if(found == true) 
      { 
       temp = list.get(place);//places the whole product into temp 
       //float tprice = temp.getprice(); 
       //char t_tax = temp.get(tax); 
       //string tname = temp.get(name); 
       float price; 
       char tax; 
       string name; 
       temp.get(price, tax, name); 
       time(&rawtime);//gets time in seconds 
       out << ctime(&rawtime)<<endl; //converts seconds into a string 
       if(tax == 'T') 
       { 
        float tvalue = 0;//holds value for tax 
        tvalue = price * .075; 
        float actualPrice = 0; // price after tax is added 
        actualPrice = price + tvalue; 
        totTax +=tvalue; 
        
       out<< "Customer "<<cus_no<<endl; 
       out << name << "            " <<times<<" @ "<< price; 
       out << (price * times) <<tax<<"X" <<endl; 
    
       } 
       else 
       { 
        out<< "Customer "<<cus_no<<endl; 
         out << name << "           " <<times<<" @ "<< price; 
        out << (price * times) <<endl; 
        } 
       } 
       else 
        out <<"********"<<setw(5)<<setfill('o')<<item<<" not in inventory****"<<setfill(' '); 
    
      char repeat; 
      cout << "Is there another item to process? Enter the product id or 0 for the end of the order."; 
      cin >>item; 
       }while(item); 
     } 
     else 
     { 
      out << "Subtotal "<<"      " <<subtotal<<endl; 
      out <<"Tax"<<"          "<<totTax<<endl; 
      float total = 0; 
      total = subtotal + totTax; 
      out << "Total" <<"        "<<total<<endl; 
     } 
     } 
     char response; 
     cout <<"Is there another cusotmer to be processed? Enter Y for yes and N for no"<<endl; 
     cin >>response; 
     if(response == 'N') 
     cout << "Have a nice day!"<<endl; 
     }while(response == 'Y'); 
     } 
     return 0; 
     } 
    
    //******************************************************** 
    void sList::Insert(product inventory) 
    { 
    int index, product_num; 
      if(length < max && !IsThere(product_num, index)) 
      { 
    
        info[length] = inventory ; 
        length++ ; 
      } 
       else 
        cout<<endl<<"List is full or contains the product number-operation aborted"; 
        } 
    
    //*************************************************************** 
    sList::sList ( ) 
    { 
            length = 0; 
            currentPos = 0; 
    } 
    //*************************************************************** 
    void sList::MakeEmpty ( ) 
    { 
            length  =  0 ; 
            currentPos = 0; 
    } 
    //****************************************************************** 
    int sList::LengthIs ( ) 
    { 
     return  length ; 
    } 
    //***************************************************** 
    bool  sList::IsFull ( ) 
    { 
            return ( length == max ) ; 
    } 
    //****************************************************************** 
    bool sList::IsThere (int pro_id, int& location ) const 
    { 
      bool found; 
      //binary search is called 
    
      BinSearch(pro_id, found, location); 
    
     return found; 
    } 
    
    
    
    //******************************************************************** 
    /*void sList::Delete (  ) 
    { 
            int location; 
             if(IsThere(product_num, location)) 
            { 
            // move last element into position where item was located 
    
                info [location] = info [length - 1 ] ; 
                length-- ; 
            } 
    
    
    } */ 
    //************************************************************************** 
    bool sList::IsEmpty() 
    { 
       return (length == 0); 
    } 
    //**************************************************************************** 
    void sList::ResetList ( ) 
    { 
            currentPos  =  0; 
    } 
    //**************************************************************************** 
    product sList::get (int& location) 
    { 
           product temp; 
           temp=info[location]; 
           return temp; 
    } 
    //**************************************************************** 
    product::product(const product& copyInven) 
    {  product inventory; 
    product_num = inventory.product_num; 
       name = inventory.name; 
       price = inventory.price; 
       tax = inventory.tax; 
    } 
    //********************************************************************** 
    void product::set (int pid, string nam,  float cost, char t) 
    { 
     product_num = pid; 
     name = nam; 
     price = cost; 
     tax = t; 
    } 
    
    //********************************************************************** 
    bool operator==(product anotherItem, product inventory) 
    { 
     if(inventory.product_num == anotherItem.product_num) 
      return true; 
      else 
         return false; 
    } 
    //*************************************************************** 
    /*bool operator<(product anotherItem) 
    { 
     if(inventory.product_num < anotherItem.product_num) 
      return true; 
      else      
       return false; 
    } */ 
    //**************************************************************** 
    /*bool operator>(product anotherItem, product inventory) 
    { 
     if (inventory.product_num > anotherItem.product_num) 
     return true; 
     else 
      return false; 
    } */ 
    //***************************************************************** 
    void sList::BinSearch(/*in*/ int pro_id, /*out*/ bool& found, /*out*/ int& position) 
    { 
    int first = 0; //lower bound 
    int last = length -1; //upper bound 
    int mid; //middle index 
    sList list; 
    
    found = true; 
    product temp; //declares an object of class product for get functions 
    int t_pid, product_num;//holds temp value for product id for comparing purposes 
    while(last >= first && !found) 
    { 
     mid = (first + last) / 2; 
     temp = list.get(position); 
     t_pid =temp.get(product_num, temp); 
     if (t_pid < pro_id) 
       last = mid - 1; 
     else if(t_pid > pro_id) 
           first = mid + 1; 
     else 
      //Assert: t_pid == pro_id 
        found = false; 
    } 
    if (!found) 
       position = mid; 
    } 
    //*************************************************************************** 
    /*string product::get()*/ 
    /*{ 
     string n; 
       n = temp.name; 
       return n; 
    } 
    //************************************************************************** 
    float product::get() 
    { 
     float p; 
     p = temp.price; 
     return p; 
    } 
    //************************************************************************** 
    char product::get() 
    { 
     char t; 
     t=temp.tax; 
     return t; 
    }*/ 
    //******************************* 
    void product::get(float& price, char& tax, string& name) 
    {  product temp; 
     price = temp.price; 
     tax = temp.tax; 
     name = temp.name; 
    } 
    //************************************************************* 
    int product::get(int product_num, product temp) 
    { 
     int t_pid; 
     t_pid =temp.product_num; 
     return t_pid; 
    }
    Here are the errors i'm getting while compiling in Dev C++:

    154 parse error before `else'
    162 parse error before `}'
    164 syntax error before `<'
    165 syntax error before `>'
    189 definition of implicitly-declared `sList::sList()'
    189 redefinition of `sList::sList()'
    50 `sList::sList()' previously defined here
    296 no `void sList::BinSearch(int, bool &, int &)' member function declared in class `sList'

    SOMEBODY PLEASE HELP!!!

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    32
    I would love to help but a little bit busy.

    I used Microsoft Visual C++ 6 to compile your program & I received 20 errors.

    The compiler gives the following message:

    error C2061: syntax error indentifier 'string'

    pointing to your code

    Code:
     void get(float&, char&, string&);
    probably you can start from there to look for errors.
    [SIZE= 4]My favorite search engine is http://www.ultimasurf.com [/size]

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    None of your "do ... while();" constructs match up. Check the braces.

    gg

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    My first thought was, Wow, I can't believe some noobie titled his post "homework help." I tried to imagine what kind of person would think that it'd be perfectly all right to expect a bunch of people to do your homework for you. But then, I saw that you live in the Easter Time Zone. Now, I'm not really sure where that time zone is (perhaps near the Easter Islands), but I'm pretty sure it's far enough away for you to be out of touch with reality enough to think that you could get other people to do your homework for you.

    You have a debugger; use it. You need to learn debugging just as much as you need to learn programming.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Originally posted by Codeplug
    None of your "do ... while();" constructs match up. Check the braces.

    gg
    wow, I haven't seen you in a while, Codeplug.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > PLEASE SOMEONE HELP...MY PROJECT IS DUE BY 11:59 PM EASTER STANDARD TIME. i really apprectiate it. thnx.
    LMAO - you should have gone to www.homework-miracles.com instead.

    Next time, assuming you haven't given up for good / been kicked out, give people more chance to help you.

    > 154 parse error before `else'
    Perhaps if you had pressed compile after typing 5 lines, instead of typing 300 lines, the location and cause of the error would be more obvious!!!!

    Write 300 lines, press compile, post code and errors on a message board is NOT A DEBUG strategy!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    ^I bet he actually clicked the link after reading your reply...LMAO

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    3
    first and formost. I would like to thanks the two ppl who did try to help. As for all the others, i hate to say it but you guys really proved that some ppl can be simply cruel.
    At least i tried to do my work rather then asking somebody else to do it for me. I guess i was mistaking in assuming that this forum was up for ppl to get help. For future reference, i think you should think before posting a reply that won't really help the person. You can be sure that this forum isn't one that i will be recommending to friends to check out.
    Again, i want to thanks the two ppl who tried to help. Thanks. the rest of you, gosh i sure hope somebody knocks some manners into you!

  9. #9
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Originally posted by computerjunkie5
    first and formost. I would like to thanks the two ppl who did try to help. As for all the others, i hate to say it but you guys really proved that some ppl can be simply cruel.
    At least i tried to do my work rather then asking somebody else to do it for me. I guess i was mistaking in assuming that this forum was up for ppl to get help. For future reference, i think you should think before posting a reply that won't really help the person. You can be sure that this forum isn't one that i will be recommending to friends to check out.
    Again, i want to thanks the two ppl who tried to help. Thanks. the rest of you, gosh i sure hope somebody knocks some manners into you!
    well, if you would attend to this forum more often you would see that we get people like just like you daily. People who need their work done/fixed/debugged as fast as possible, as their deadline is approaching soon! Even though, I'm relatively new here, this buggs the hell out of me, so I can't imagine how it must be for people who have been here for years.

    Believe me, if you would phrase yourself differently and not procrastinated over the program, you would get many more responses and helpfull hints. As for how good this board is....it is simply amazing. I should hope you reconsider, but then again, if you don't no one will shed a tear. You will not find a better board on/of/about programming anywhere on the interent,

    axon

    EDIT:: now seriously, did you click on Salem's link?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    3
    1st, let me put your curiosity to rest: I DIDN'T CLICK ON THE LINK!! i prefer to do my own work thank you very much!

    now, you said if i phrased myself differently...excuse me? phrashed myself differently how? all i did was ask for help.
    and you said that there are ppl like me who post to get their work done for them and get it done quickly.... well, did you ever consider that maybe i didn't put off on the program? that i had been working on it and only when i REALLY needed the help that i posted? no ofcourse not. that would never occure to you would it?
    well let me tell you, the ONLY reason i would ask for help is when REALLY need it.
    maybe you should give ppl a chance. how about that? it's a new concept but give it a try....
    if i haven't made myself clear, i will do it now, for those of you who think that i was trying to get you to do my work for me, i wasn't. i had spent a considerate amount of time working out the kinks in the program and when i couldn't do the last ones, and had just about had it, that was when i posted. But other then the two who did help, you guys were a complete waste of time.
    and axon, about this board, i have already found one better. maybe you should fine tune your searching skills, i'm sure eventually, it will catch up with your terrible sense of humor and manners. good luck

  11. #11
    Registered User
    Join Date
    Oct 2003
    Posts
    24
    You are probably gone, but nonetheless I wanted to post this for others to future reference. When you are writing in C++, use the updated headers. The C headers may work, but they are outdated.

    Code:
    #include <iostream.h> 
    #include <fstream> 
    #include <stdlib.h> 
    #include <string> 
    #include <ctime> 
    #include <iomanip>
    into
    Code:
    #include <iostream> 
    #include <fstream> 
    #include <cstdlib> 
    #include <cstring> 
    #include <ctime> 
    #include <iomanip>
    -NIM

  12. #12
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Originally posted by NIM
    You are probably gone, but nonetheless I wanted to post this for others to future reference. When you are writing in C++, use the updated headers. The C headers may work, but they are outdated.
    Code:
    #include <string>
    into
    Code:
    #include <cstring>
    Note that the one above is incorrect. Those are two totally different libraries that are both new and standard. <string> holds the standard string class, while <cstring> is the standard C library that replaces the deprecated <string.h> and has C-style string manipulation functions like strcpy, strcat, etc.

  13. #13
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What's this "better board" you're talking about? I couldn't imagine such a thing.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    72
    I must concur with the general consensus on this one. This message board is awesome when it comes to providing help for other people. The people around here have helped me out many times in the past and I appreciate it greatly. Some have even gone as far as to recommend books that would further enhance my skills and knowledge. I'd strongly suggest reconsidering your opinion..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  2. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  3. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM