..C Programming Help..!! The question : A supermarket program With the use of file create a list of 20 products minimum available in your supermarket. The program must enable the cashier to check out a customer, verify if product is available and the total sales. While checking out a customer, you must be able to remove an item and print the receipt of the customer also.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

..C Programming Help..!! The question : A supermarket program With the use of file create a list of 20 products minimum available in your supermarket. The program must enable the cashier to check out a customer, verify if product is available and the total sales. While checking out a customer, you must be able to remove an item and print the receipt of the customer also.

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

My attempt: #include #include int main () { int Op1,Op2,productcode,i,j; int array1[i][2]; FILE *fp1; fp1=fopen("CodeProductPrice.txt","r"); printf("\tWelcome to the NMV Chocolate Shop\n"); printf("\n"); printf("Choose an option: \n 1.Checkout Customer\n 2.Search Products\n 3.Exit\n"); scanf("%d",&Op1); switch(Op1) { case 1:{ printf("Choose an option: \n 1.Enter Product Code\n 2.Remove Product\n 3.Print Receipt\n"); scanf("%d",&Op2); switch(Op2) { case 1:{ printf("Terminate by a '.'"); printf("\n"); do { printf("Enter product code: "); scanf("%d",&productcode); /*Here i just can't figure out how to get it to print the product name and price */ for(i=0;i>0;i++) { for(j=0;j<2;j++) { /* Place product name and price into array1[i][j] */ } } } while(productcode!='.') break; } case 2:{ /* The remove product also i have no idea how to do it*/ break; } case 3:{ printf("\t NMV CHOCOLATE SHOP\n"); printf("\t Candy Street\n"); printf("\t Sweets World\n"); for(i=0;i>0;i++) { for(j=0;j<2;j++) { printf("%d\t",array1[i][j]); printf("\n"); } printf("\n"); printf("Thank you for your visit\n Have a nice day !! \n Hope to see you soon !! \n ^_^\n"); } break; } default:{ printf("Error\n"); break; } } break; } case 2:{ /*That too I do not know ----> Searching of products*/ break; } case 3:{ break; } default:{ printf("Error\n"); break; } } system("pause"); return 0; }
Problems are encountered are found in between /* */..There are 4 in all..!! But if you found any other irregularities or improvments..Please do tell..!! I know I haven't yet included the total sales by cashier yet..And the total amount of money customer must pay..and also change to be handed back..^_^..!! I do theses afterwards when i finally be able to know how to get the price from the file..:)..!! File contents found in comment just below..!! Thank you..!!
File was done on Naotepad like that : 000-NMV_Kit_Kat_2_Fingers-12.00 001-NMV_Kit_Kat_4_Fingers-24.00 002-NMV_Kit_Kat_Chunky-24.50 003-NMV_Kit_Kat_4_Fingers_White_Chocolate-24.00 004-NMV_Kit_Kat_4_Fingers_Dark_Chocolate-24.00 005-NMV_Cadbury_Mini_Rolls_Blackcurrant_&_Vanilla-15.00 006-NMV_Cadbury_Mini_Rolls_Caramel-15.00 007-NMV_Cadbury_Mini_Rolls_Cherry_&_Vanilla-15.00 008-NMV_Cadbury_Mini_Rolls_Double_Choc-15.00 009-NMV_Cadbury_Mini_Rolls_Lemon-15.00 010-NMV_Cadbury_Mini_Rolls_Milk_Chocolate-15.00 011-NMV_Cadbury_Mini_Rolls_Strawberry-15.00 012-NMV_Cadbury_Mini_Rolls_Sweet_Cranberry_&_Vanilla-15.00 013-NMV_Dairy_Milk_Double_Choc-20.00 014-NMV_Dairy_Milk_Hazelnut-20.00 015-NMV_Dairy_Milk_Duo-20.00 016-NMV_Dairy_Milk_Peppermint-20.00 017-NMV_Dairy_Milk_Macadamia-20.00 018-NMV_Dairy_Milk_Fruit_&_Nut-20.00 019-NMV_Dairy_Milk_Mint_Chips-20.00

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

By the way..I'm a complete novice in files and arrays..^^'..!!
Not a C++ expert but a crash course: Setting a value in the array: array[elementnum] = somevariable Getting a value from the array: moarvar = array[elementnum] See http://www.cplusplus.com/doc/tutorial/arrays/ for more in-depth information.
Do you know how to use C structs? Ultimately the problem I find with your code is that your data is not organized very well. Never name something 'array'.
I'd love to help you out but seems you're not here.
@wio Try leaving your answer here. :) Also, it looks like the question asked him to use arrays so not sure if struct should be used here.
If you can't use structs, you want an array for each data point pertaining to a product. You can't use a multidimensional array here because you have different datatypes. You're also going to have to use dynamic memory, since there is no way to know how many products there are, and how long the names of each product will be.
You want to break up your program into functions as well. Don't tell me you can't use functions....
@wio & @tyteen4a03 ..I know how to use functions..^_^..!! I'll try breaking it into functions to make it Less bulky...However.. Arrays can be Okay..My real Problem is FILE I just can't understand a thing about it....How to use it and all..:/...!!
..If you have any E-books or website...Please give me the link..Thank you..^_^..!!
Ah I'm online
Well you start with opening file with fopen() obviously. Then you wanna use fgets() to get one line at a time from the file.
Do you understand malloc()?
are you allowed to use structs or is that just not going to happen?
..Hello..!! :)..!! Okay for my first problem.. Where i just can't figure out how to get it to print the product name and price.. In the file, it's like that : 015-NMV_Dairy_Milk_Duo-20.00 I type the product ..015..Then it should print out the name and price.. How can i achieve this..??
..I can use malloc..!! ^_^..!!
Okay, what you want to do is store the product names
And price..:P
..If fgets() will print the one line...So if i create anothe file with the names and price only... Entering 15..It will read line 15 of file and print it..Is that it..??
*another
fgets will fetch one line
then you sort of have to parse it.
@JadeEyes here's what I think you should do, try making a function which calls 'fgets()' and counts how many lines there is in the file.
then use that when you malloc() each array, so they'll be of the correct size.
..I'm kind of confused..o.O..!! You mean..Make a function which will count the number of times i used fgets..??
Basically.... call fgets() on the file until you reach end of file
then do something like: int product_count = count_lines();
char** product_names = malloc(sizeof(char *) * product_count)
float* prices = malloc(sizeof(float) * product_count)
these are arrays.
You could also have the first line in the be a number of how many products there are... then you wouldn't have to count lines.
If you want to use a static array, then there has there has to be a maximum number of products...
....The person can take only 1 or all 20 products...Use this functin { FILE *fp = fopen("c:\\product.txt","w"); if(fp){ fwrite(fp,"ProductName-Quantity Taken-Price\n"); fwrite(fp,"ProductName-Quantity Taken-price\n"); //...................continue for the rest fclose(fp); int product_count = count_lines(); char** product_names = malloc(sizeof(char *) * product_count); float* prices = malloc(sizeof(float) * product_count); } Kind of like that..??
okay, now you're confusing me
Before you even show the person a member, you should load all of the data about the products into an array.
show the person a menu
you're going to open a file regardless
You want to store the data in your arrays. You don't want to open/read/write to the file every time. That is too slow.
..Okay..!! So basically..I just have to place all the data in the arrays..using fgets and the functions you gave me..Right..?? Then..When the customer have made his choice and come up to the cashier to checkout... Using the first array done above..We can get access to both the name and price that We save his choice in another array..!! Right..??
*such that We can save his choice..
I didn't give you working code, the general idea.
once the program exits, you can write all the data back into the file.
...Okay..i fink I'll try it this way..^_^..!! Thank you..:)..!! Next how to remove a product from the customerchoice array... Here..I don't know how to proceed at all..!! I thought about using a pointer to get acess to the data then..delete it...But is there a delete option in C programming..??
Well, it depends on how you want it to be handled.
what is the customerchoice array for?
..customerchoice array is the one where the products the person chose will be stored
okay, so to remove an entry, just replace it with the entry that comes next and replace the next one with the one after it, and so on until you reach the end.
you're going to have to store the number of choices made, so you know when you reach the end.
...Hmmm...Okay..I'll try to do that way..If i encounter any problem..I'll get back to you again..^_^'...!! I guess that's it..Thank you for your help..^_^..!!
..I'll keep it open..!! ^_^
The question i mean..:)

Not the answer you are looking for?

Search for more explanations.

Ask your own question