problem with classes

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 12
Reputation: sarahger9 is an unknown quantity at this point 
Solved Threads: 0
sarahger9 sarahger9 is offline Offline
Newbie Poster

problem with classes

 
0
  #1
Nov 20th, 2007
I am working on a project that inputs stock information from files, then outputs the information when the customer is called upon. I am doing pretty good, but am stuck. This is what I have.

  1. for (int k = 0; k < namevector.size(); k++){ //namevector is a vector of type
  2. otherfile.close(); customer(defined as a class)
  3. otherfile.clear();
  4. otherfile.open(namevector[k].getname().c_str());
  5. if (!otherfile.is_open()){
  6. cout << "Can't open the customers stock file" << endl;
  7. }
  8. while(!otherfile.eof()){
  9. otherfile >> symbol >> numshare >> price;
  10. stocks.setsymbol(symbol);
  11. stocks.setnumshare(numshare);
  12. stocks.setprice(price);
  13. stockvector.push_back(stocks); //stockvector is vector of type stock
  14. which is defined as a class
  15. }
  16. }
  17. cout << "Enter customer name, or exit" << endl;
  18. cin >> command;
  19. for (int n = 0; n < 3; n++){
  20. if (command == namevector[n].getname()){
  21. cout << "found person" << endl;
  22. for(int m = 0; m < 3; m++){
  23. cout << namevector[n].getstock(m).getnumshare()<<
  24. namevector[n].getstock(m).getsymbol()<<
  25. namevector[n].getstock(m).getprice() <<
  26. namevector[n].getstock(m).getnumshare() * namevector[n].getstock(m).getprice() << endl;
  27. }

The problem (I believe) is that when I read the data in from the files (there is a seperate file for each customer) it puts all of it into the same stockvector, so that when I try to call for a specific customer, it doesn't match up with the stock for that customer. Can I create more than one stockvector, or is that impractical?
Please let me know if you need any more code, like my class functions, but I don't believe they are the problem, although I could be wrong.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,836
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 119
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: problem with classes

 
0
  #2
Nov 20th, 2007
  1. otherfile >> symbol >> numshare >> price;
Print what you are reading. That could help you detect the problem.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC