473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problem with classes

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.

Expand|Select|Wrap|Line Numbers
  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.
Nov 20 '07 #1
1 978
AHMEDYO
112 100+
HI..

i will tell you about somethings that you can care about because i cant exactly understand all things from your code.

the command that the user will enter to search about customer is string?, and getname() function is string too? i mean it will return pointer to string?

if so you cant compare it like that, because you will compare pointers value not the string

Expand|Select|Wrap|Line Numbers
  1.  if (command == namevector[n].getname())
if this is the problem you can use strcmp(str,str) to compare two strings, it will return 0 if two strings is same

i hope this will help you!

Best Regards
Nov 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
4
by: Merlin | last post by:
Hi Imagine the following classes (A class diagram will help) BASE, A, B, C, D, E, F, G. A, B, C, D, G inherit from BASE. E, F inherit from D.
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
1
by: TheOne | last post by:
I have two classes: class OntologyParser { ... protected: virtual void startElement(void *userData, const char *name, const char **atts); virtual void endElement(void *userData, const char...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
6
by: Florian Lindner | last post by:
Hello, I have these class declarations class CBauteil { private: int m_iNumber; int m_iWeight; public: int getNumber(); void setNumber(int);
12
by: Nathan Sokalski | last post by:
I have several CustomControls that I have written for my project. However, when I try to compile I recieve the following warning & errors: Warning 32 Could not resolve this reference. Could not...
9
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.