The majority of forums are now only available as archives, which means posting/editing is disabled.
The Anything and Everything forum is still open.
The Anything and Everything forum is still open.
help me please!!
|
|||
|
Rank: Unregistered
|
this is for my assignment...this program is in C and must be use only Standard C library(stdio.h) and must be a simple program...actually i`ve tried to make this program but i`m stuck..!!and i got other assignment to be complete..i hope someone out there can help me..!!!please..!!!
Inventory System You are the owner of a hardware store and need to keep an inventory that can tell you what tools you have, how many you have and the cost of each one. Write a program that initializes the file " hardware. dat" to 100 empty records, lets you input the data concerning each tool, enables you to list all your tools, lets you delete a record for a tool that you no longer have and lets you update any information in the file. The tool identification number should be the record number. Use the following information to start your file: Record# Tool Name Quantity Cost 3 Electric sander 7 57.98 17 Hammer 76 11.99 24 Jig Saw 21 11.00 39 Lawn mower 3 79.50 56 Power Saw 18 99.99 68 Screwdriver 106 6.99 77 Sledge hammer 11 21.50 83 wrench 34 7.50 |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
well as a former tutor for programming classes my first questions are:
1. what do you have so far? 2. what exactly are you stuck on? but since those aren't answered and forums are a little different from sitting at a table together, here's some things you might want to consider: - having 100 empty records initially just screams array. you'll probably be defining something such as <<type>> inventory[100]. - each entry in the inventory has the same 4 pieces of information, with probably a total of 3 data types. you could set up a struct with each piece of information and then the type for your inventory array would be this struct. if you haven't dealt with structs, you could use parallel arrays, in which case you would not have inventory[] but would instead have toolname[], toolqty[], and toolcost[] (or something similar). - you would not likely need to store the record number as it could simply be the index to the array. - it looks like you're supposed to store this to a file, so when the program starts it should check for the file, and read it into your array(s). then when you quit, the array(s) should be written back to the file. that should be enough to get you started!
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (180)
Member #: 7065 |
I would recommend using a structure to store your records, and then write a function which will read/write that structure to and from a file.
The structure might go something like this: Code:
And then it's just a matter of using the formatted file input/output functions (fprintf, fscanf) to read and write the contents of that structure to and from your file. For example, to write to your file: Code:
I've got to go now, but you can write the rest... I probably shouldn't do your whole assignment for you Gian |
||
|
|||
|
|||
|
Rank: Unregistered
|
actually i`m really need help to make this program coz i dunno how to make arrays..but thanx for your help.!!
|
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
say you decalare something like this:
float price[100]; you now have basically declared 100 variables of type float: price[0], price[1], price[2], . . . , price[99]. it's important to remember that the valid index numbers are 0 through one less than what you used when you declared the array. you can also declare an int variable (we'll call it i) and access one of the prices in the array like this: price[i] of course you will have to make sure that you don't go beyond the upper limit (in this example, 99).
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (180)
Member #: 7065 |
Doing "float price[100]" actually declares 101 values, 0 - 100.
The 100 index is accessable (in GCC, at least). Gian |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
in ansi c, you shouldn't use price[100] -- i've never used gcc, but it's probably not a good idea there either. i think it will let you use 100, but this is actually going to point to the memory address that comes after price[99], which may be assigned to a different variable.
(skip the rest of this if you don't know much about pointers) basically an array is a constant pointer. when declaring float price [100], the value of price by itself is the memory adress where the data for price[0] is stored. now if i wanted to declare p as a pointer to float, it would be valid for me to say "p = price;" which would actually assign p the address of price[0]. i could then use p just like price, where p[0] through p[99] would map directly to price[0] through price[99]. c is not going to stop me from saying p[100] as there is really no end to a pointer. p[100] is the same as saying "p += 100;" and then using p[0]. since price is an array, it's really just a pointer to float that cannot be changed to point to a different memory address. the difference is that declaring it as an array with 100 elements, you are allocating that memory space so that nothing else can use it. with a pointer, you haven't allocated anything unless you do so specifically. i've never actually allocated memory but i believe the command is malloc(). basically what i'm saying is that c isn't going to stop you from letting a pointer fly off to space that isn't allocated for a variable. if you do it just "right," you can accidentally rewrite some of your code at runtime. arrays are constant pointers, and accessing beyond the end of their allocated space, while not quite as dangerous as a pointer can be, is still likely to give undesired results.
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (180)
Member #: 7065 |
Ah, right you are.
This is exactly why I love SML so much |
||
|
Please login or register to post a reply.
