|
You can do it a bit shorter:
right.ModifyStyle(LVS_TYPEMASK, LVS_REPORT, 0);
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
S 000-00-0001 C 20
B 000-00-0001 C 20
B 000-00-0002 CD 10
B 000-00-0002 JDSU 50
S 000-00-0002 CD 5
B 000-00-0010 TXN 30
B 000-00-0010 TYC 20
B 000-00-0009 WCOM 20
S 000-00-0009 WCOM 10
now i need to read the first letter of this input and test what is!
and based on that i need to take certain actions
here is what i have done but i'm not sure it is the right way
doesn't look like it's working!
Thanks
|
|
|
|
|
char ch;
do
{ cin>> ch;
switch (ch)
{
case 'C':
{
cin>>tempST>>tempIV;
tempStock->setStockTicker(tempST);
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
(*tempStock) = tempStocks->getStock(mid);
tempStock->setcurStockPrice(tempIV);
if (strcmp(tempStock->getStockTicker(),inputLine ) < 0)
low = mid + 1;
else if (strcmp(tempStock->getStockTicker(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
}break;
case 'B':
{
count = 0;
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempAccount;
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
Investor tempInvestor = (*tempInvestors).getInvestor(mid);
tempAccount = tempInvestor.getAccountBalance();
if (strcmp(tempInvestor.getSocialSecurity(),inputLine ) < 0)
low = mid + 1;
else if (strcmp(tempInvestor.getSocialSecurity(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
char tempTicker[30];
strcpy(tempTicker,inputLine);
int lo =0, mi, hi=14;
int tempStockPrice;
while (lo <= hi)
{
mi = (lo + hi)/2;
*tempStock = (*tempStocks).getStock(mi);
tempStockPrice = (*tempStock).getCurStockPrice();
if (strcmp((*tempStock).getStockTicker(),inputLine ) < 0)
lo = mi + 1;
else if (strcmp((*tempStock).getStockTicker(),inputLine ) > 0)
hi = mi - 1;
else
mi = mi;
}
while((c = cin.get()) != '\n ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempNumShares = atoi (inputLine);
if ( tempAccount >= (tempStockPrice * tempNumShares))
{
(*tempTickerShare).setNumOfShares(tempNumShares);
(*tempTickerShare).setTickerSymbol(tempTicker);
(*tempInvestor).addTickerShare(tempTickerShare);
}
}break;
case 'S':
{
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
Investor tempInvestor = (*tempInvestors).getInvestor(mid);
if (strcmp((tempInvestor).getSocialSecurity(),inputLine ) < 0)
low = mid + 1;
else if (strcmp((tempInvestor).getSocialSecurity(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
char tempTicker[30];
strcpy(tempTicker,inputLine);
int lo =0, mi, hi=14;
while (lo <= hi)
{
mi = (lo + hi)/2;
tempTickerShare = (*tempInvestor).getTickerShare(mi);
strcpy (tempTicker , (*tempTickerShare).getTickerSymbol());
if (strcmp(tempTicker,inputLine ) < 0)
lo = mi + 1;
else if (strcmp(tempTicker,inputLine ) > 0)
hi = mi - 1;
else
mi = mi;
}
while((c = cin.get()) != '\n')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempNumShares = atoi (inputLine);
if (tempNumShares <= (*tempTickerShare).getNumOfShares())
{
tempNumShares = (*tempTickerShare).getNumOfShares() - tempNumShares;
(*tempTickerShare).setNumOfShares(tempNumShares);
}
else
cout<< "Sorry don't have enough shares to sell"<<endl;
="" }break;
="" }
="" }
="" while="" (!cin.eof());
<\pre="">
|
|
|
|
|
Do you use the debugger to find out where the function fails?
With VC6 edit and continue functionality, it should be easy enough for you to step through the code and find out where the code is failing.
If you need help debugging let me know.
|
|
|
|
|
no i really don't know how to use the debugger!
this is my first time programming in C++ and I am using visual C++
and DEV-C++ to compile and run my program.
well if you want to tell me how you debug i'm ready to learn>
appreciate your help
|
|
|
|
|
Use F9 to set what's called a break point - you'll see a black dot appear by the line of code. Hit F5 to start debugging - the code will run to a breakpoint, and then stop. You can hit F10 to exectue a line of code at a time, and you also get a variable watch window, into which you can type variable names to see how their values change as each line is executed.
Make sure you're in debug mode You set that by clicking on Build | Set Active Configuration.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I would just like to add a little more detail to what Christian G (CG). said.
I assume that you are running your programs right now by clicking the icon with the !. This simply runs the app. like CG said, run your application by hitting the F5 key instead. You could also go to the Build menu, and select Start Debug. There are a lot of other useful commands on this menu.
When you know that you have a trouble area in your program, go to the line of code where you think that the problem is starting and hit the F9 key. Like CG said, this will set a breakpoint. A the program will halt its execution when it reaches this point.
At this point you can move your cursor over any variable to see what values they hold. There are a number of windows that you will want to open from the debug menu in order to get important information from the debugger.
The watch window will allow you to type in any of the variables that are in the current scope, or function, and you can see the values that they hold. If you have a class or a struct this is a really nice window because you can view all of the data member values of the object.
You can change the value of a variable in the right hand side of the watch window. This is very useful if you want to change the or set the value of a variable while debugging, with out writing code, or if you want to see how this new value will affect code execution.
The variables window will show all of the variables that are currently being used on the current line. Just like the watch window, you can change the value of the variables in the right hand side of the window.
You probably will not have to worry about the registers window for right now unless you learn more about x86 assembly. However the EAX register is the register where return values are always sent. So if you call an API function, but do not store the return value with a variable in your program, you can check this register.
The memory window is good for checking the memory at a particular address. So if you have a pointer and you want to see what memory it points to, type in the variable name in the address section, and dereference it ex. *lpString .
The call stack window is helpful to see what function calls have led upto the current function. You can also click on one of the previous lines in the call stack window to set the current debug context to one of those other functions. This will allow you to check variable values in a different function call that is on the stack. Some times you can uncover problems that happened in a previous function that caused problems later on.
Just like the registers window, you will not have to worry about the disassembly window until you learn more about x86 assembly.
A few more tips:
You can step to the next line of code with F10.
You can skip over a function call with F11.
If you want to stop execution of a program that is currently being debugged, hold Shift + F5.
You can set the current execution point by setting the caret to the line that you want to execute from and right click to get the context menu and select "Set Next Execution Point". This is very useful when you execute a statement with a wrong value and then you want to change the value in the watch window and re-execute a piece of code. Or if you want to skip over an entire section of code.
The most important thing of all, say you have a breakpoint set. The execution of your program has halted at that breakpoint, and you step through your program with F10. You finally find the problem, you can directly edit you code, make the one line fix or what ever the simple problem may be, hit F10, and Dev Studio will has if you want to edit and continue. If you choose yes, it will recompile your code, and you can continue executing the program from the same point without restarting the program. This works in most cases, but the compiler cannot recover after all of the changes that you make. SO you will want to limit this feature to small changes in your program.
I know there is alot of information here, and it may take you some time to get comfortable with all of the things that I have explained here, however these are the bare essentials to debugging in Dev Studio, and I stringly suggest you learn and use every one of these features. It will help you find problems quicker and you will learn your code faster as well.
I know there are a few other things that I left out so if anyone thinks that I left out anything important please add to this.
|
|
|
|
|
just wanted to say thank you before i go to sleep
|
|
|
|
|
I am new to template specialization and was trying to adapt the hash_map from Dinkumware to use keys of type string; by default, they accept only integer types.
This is the hash_compare class in header xhash
template<class _Kty,
class _Pr = less<_Kty> >
class hash_compare
{
public:
enum
{
bucket_size = 4,
min_buckets = 8};
hash_compare()
: comp()
{
}
hash_compare(_Pr _Pred)
: comp(_Pred)
{
}
size_t operator()(const _Kty& _Keyval) const
{
return (_Keyval);
}
bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const
{
return (comp(_Keyval1, _Keyval2));
}
private:
_Pr comp;
};
As far as I understood class template specialization, the following should work as a specialization for type string
#include <hash_map>
#include <string>
using namespace std;
namespace std
{
template<> class hash_compare <string, less<string> >
{
public:
enum
{
bucket_size = 4,
min_buckets = 8};
size_t operator()(const string& k)
{
long val = 0;
for (unsigned int i = 0; i < k.size(); ++i)
{
val += k.at(i);
}
return val;
}
bool operator()(const string& k1, const string& k2)
{
if (lstrcmp(k1.c_str(), k2.c_str()) <= 0) return false;
return true;
}
};
}
In the application, I test it with:
hash_map<string, string> maps;
maps["thomas"] = "george";
string val = maps["thomas"];
but the following compile errors occur
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
MainFrm.cpp
c:\sxl\include\xhash(475) : error C2663: '()' : 2 overloads have no legal conversion for 'this' pointer
c:\sxl\include\xhash(474) : while compiling class-template member function 'unsigned int __thiscall std::_Hash<class std::_Hmap_traits<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_s
tring<char,struct std::char_traits<char>,class std::allocator<char> >,class std::hash_compare<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allo
cator<char> > > >,0> >::_Hashval(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) const'
c:\sxl\include\xhash(475) : error C2064: term does not evaluate to a function
c:\sxl\include\xhash(474) : while compiling class-template member function 'unsigned int __thiscall std::_Hash<class std::_Hmap_traits<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_s
tring<char,struct std::char_traits<char>,class std::allocator<char> >,class std::hash_compare<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allo
cator<char> > > >,0> >::_Hashval(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) const'
Generating Code...
Skipping... (no relevant changes detected)
test.cpp
testDoc.cpp
testView.cpp
Error executing cl.exe.
test.exe - 2 error(s), 0 warning(s)
I appreciate any help on this
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
(A guess) Try making the two operator () methods const :
size_t operator()(const string& k) const
...
bool operator()(const string& k1, const string& k2) const
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, I just found that out ...
Also, is there any way to apply the concept of your block allocator to a vector? I am using the set_intersection algorithm to populate the vector.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Also, is there any way to apply the concept of your block allocator to a vector? I am using the set_intersection algorithm to populate the vector.
I've alredy answered that in my article's questions area (you might have not noticed, as email notifications to your address are being bounced back).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I found the problem. It was just a missing const keyword in the function declarations.
Don't bother about it...
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
everything is read but the third word???
aoltimewarnerinc AOL NASDAQ in 26 2674510
citigroupinc C NASDAQ ch 47 149881
cendantcorp CD DOW so 17 174795
ciscosystems CSCO NASDAQ ne 19 629955
generalelectric GE DOW te 37 31010800
intelcorp INTC NASDAQ ch 35 6303500
jdsuniphasecorp JDSU NASDAQ ne 7 281648
microsoftcorp MSFT DOW so 63 3478270
oraclecorp ORCL NASDAQ so 17 523466
qwestcommunicationsintlinc Q DOW te 10 170682
rationalsoftware RATL NASDAQ so 23 387952
sunmicrosystems SUNW NASDAQ so 10 399725
texasinstruments TXN NASDAQ ch 31 146157
tycointernational TYC DOW te 35 6496160
worldcominc-group WCOM NASDAQ ne 10 659215
Roger Daltry 000-00-0001 10000
Ron Howard 000-00-0002 12000
Pete Rozelle 000-00-0003 10500
Dr. Seuss 000-00-0004 10100
Mikhail Gorbachev 000-00-0005 15000
Jackie Joyner-Kersee 000-00-0006 17000
Paula Prentiss 000-00-0007 14000
Andy Gibbs 000-00-0008 18000
Shaquille O'Neal 000-00-0009 16000
Lynn Swann 000-00-0010 18500
S 000-00-0001 C 20
B 000-00-0001 C 20
B 000-00-0002 CD 10
B 000-00-0002 JDSU 50
S 000-00-0002 CD 5
B 000-00-0010 TXN 30
B 000-00-0010 TYC 20
B 000-00-0009 WCOM 20
S 000-00-0009 WCOM 10
|
|
|
|
|
char tempCN[30];
char tempST[30];
char tempMT[30];
char tempTM[2]; You're having a buffer overrun, because the type of manufacturer occupies two characters plus the terminating null character (which gets written on the next available position, namely tempMT[0] ). Reserve more space for tempTM (and as a general rule do not be so conservative when dimensioning things, or better yet, use std::string s).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I found the anwer like 2 minutes before reading your reply
i really appreciate your effort to solve my problem
THANK You so much
|
|
|
|
|
I had this code emailed to me last night and made several suggestions, std::string being one of them. I also pointed out that the NULL terminator takes a space in a char array.
I'm pleased he's changed his mind about posting his code, it will make it much easier to help him.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
i cannot use std::string
because my instructor told us not to.
but thanks though
|
|
|
|
|
It had just occured to me this would be the case. I'm at a loss why they make you learn to do things in a way you never will again, but I guess that just seems to be the way it is done. I learned from a book and learned the whole char* way, and I remember being amazed how much easier it was when I used the string class.
By the way, you need to tick 'display this message as is' when you post code, otherwise your #include statements don't get posted, because the < and > get interpreted as a HTML tag.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
probably making you understand that string is better than char*, obviously, when they discover that there is a string class and something called STL. There are many, many instructors who do not know a thing about STL.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thomas George wrote:
There are many, many instructors who do not know a thing about STL.
I am not surprised to hear that. Pathetic, isn't it ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
well
i don't think he doesn't know about STL
but he just like to makes our life harder
he thinks that if you want to use libraries, then go program with JAVA
|
|
|
|
|
Marwan wrote:
he thinks that if you want to use libraries, then go program with JAVA
IMO he is a professional idiot if he means not to use libraries for production code. Where would any science be if we were not allowed to benefit from the work done before us ?
I COULD spend my life writing containers and algorithms, but why would I want to ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
As a software engineer, of course I agree with the whole code reuse thing. STL is a spectacular tool that I can't live without.
However, given the type of questions posted here by Marwan, it looks like he/she needs a good solid understanding of the basics of the language before introducing them to the relatively complex ideas of templates. Don't you think?
J
|
|
|
|
|