Saturday, May 22, 2010

C++ Quick question?

OK i am doing a program for people that sell things on the Internet "note this is just for practice i very new to c++ this is not a pro program its for practice"


OK so i have it enter the price and i am trying to get it to so you can enter the item name but how do make it so it stores a name not just a variable/ number I dont know if its a char double float etc. please help if you know

C++ Quick question?
To store the itemname use char array as


char itemname[size];


give numeric value to size on your desire.


eg: char itemname[25];


and use float or double to store the cost of the product.





If you want to link an item with its rate use class or structure.


For each items use a unique object or structure variable.


Ok.
Reply:wtf..i dont get it...
Reply:The price is supposed to be a float. To store the name you need a char array. For example:





float Price = 0;


char Name[] = "ItemName";





The price is a float because prices have decimal parts and thus cannot be ints. ($25.55 for example)
Reply:one way of doing it is get all values in char den parsing it for char or integer or float value using various functions like isdigit etc
Reply:use char *item;





use (*) symbol with the name....it is more efficient than others....it allocates memory at the compile time, so by using this thing u save ur memory space.
Reply:Um. I'm a C programmer. I am weakest on C++ strings, HOWEVER, there are basically two types of strings. What is being described (too superficially) is the C string. The C string is an array of characters which always ends in a '\0' or NULL character. The C libraries cctype and cstring (or ctype.h and string.h in older compilers) contain routines for handling them. Printf also has a format character, "%s" which presents a bug -- it takes a pointer, and immediately starts printing out chars until it reaches a NULL character. If you didn't send it a valid array of printable chars ending in NULL your program can crash and your computer can possibly be harmed.





With the modern, STL-enabled syntax, there is this whole new class called string, which you can access after putting #include %26lt;string%26gt; in your header. NOTE THE DIFFERENCE. C or ASCIIZ strings, the old style, use %26lt;string.h%26gt; or %26lt;cstring%26gt;. String classes use %26lt;string%26gt;.





I'm including a link to tutorials on both types of strings -- at cplusplus.com, an excellent site for learning about the subject. Remember when using C strings: ALWAYS TERMINATE CHAR ARRAYS WITH A NULL. That way you can be reasonably sure any function you call will not process more data than you want it to.
Reply:An array of characters is also known as a string.





char name[]

our song

No comments:

Post a Comment