SlideShare a Scribd company logo
1 of 8
Download to read offline
I'm posting this again because the answer wasn't correct.
**Please read this carefully and the prompt carefully**
Hello All, I need help with Operations 4, 5, and 7. Make sure it's in C programming language.
Operations needed:
Operation 4 is Delete the entire list: When 4 is pressed, the program should delete each products
information by removing all the nodes in the Linked List, including the head node that was
created when you pressed 1.
Operation 5 is Search a product: When 5 is pressed, the program should take the users keyboard
input for the products name, search this product in the Linked List, and return the search result
(Found, or Not Found).
and Operation 7 is Purchase a product: When 7 is pressed, the program should take users
keyboard input for the products name, and increase this products quantity by 1.
I provided a code for what I have so far.
Code
#include
#include
#include
// define a product struct
typedef struct Product {
char name[20];
int price;
int quantity;
struct Product* next;
} Product;
// declare global variables
Product* head = NULL; // start of the linked list
Product* tail = NULL; // end of the linked list
// function prototypes
void createList();
void insertProduct();
void removeProduct();
void deleteList();
void searchProduct();
void displayProduct();
void purchaseProduct();
void sellProduct();
void saveToFile();
int main() {
char choice;
do {
printf("nnPlease choose an option:n");
printf("1. Create a new listn");
printf("2. Create a new productn");
printf("3. Remove a productn");
printf("4. Delete a listn");
printf("5. Search a productn");
printf("6. Display a productn");
printf("7. Purchase a productn");
printf("8. Sell a productn");
printf("9. Save products to filen");
printf("0. Exitn");
printf("Enter your choice: ");
scanf(" %c", &choice);
switch (choice) {
case '1':
createList();
break;
case '2':
insertProduct();
break;
case '3':
removeProduct();
break;
case '4':
deleteList();
break;
case '5':
searchProduct();
break;
case '6':
displayProduct();
break;
case '7':
purchaseProduct();
break;
case '8':
sellProduct();
break;
case '9':
saveToFile();
break;
case '0':
printf("Exiting program.n");
break;
default:
printf("Invalid choice. Please try again.n");
break;
}
} while (choice != '0');
return 0;
}
// function to insert a new product into the linked list
void insertProduct() {
Product* newProduct = (Product*) malloc(sizeof(Product));
printf("Enter the name of the product: ");
scanf("%s", newProduct->name);
printf("Enter the price of the product: ");
scanf("%d", &newProduct->price);
printf("Enter the quantity of the product: ");
scanf("%d", &newProduct->quantity);
if (newProduct->price <= 0 || newProduct->quantity <= 0) {
printf("Price and quantity must be positive integers. Product not added.n");
free(newProduct);
return;
}
newProduct->next = NULL;
// check if the product already exists in the linked list
Product* current = head;
while (current != NULL) {
if (strcmp(current->name, newProduct->name) == 0) {
printf("Product already exists. Product not added.n");
free(newProduct);
return;
}
current = current->next;
}
// add the new product to the end of the linked list
if (head == NULL) {
head = newProduct;
tail = newProduct;
} else {
tail->next = newProduct;
tail = newProduct;
}
printf("Product added.n");
}
// function to remove a product from the linked list
void removeProduct() {
if (head == NULL) {
printf("No products in the list.n");
return;
}
char name[20];
printf("Enter the name of the product to remove: ");
scanf("%s", name);
Product* current = head;
Product* previous = NULL;
while (current != NULL) {
if (strcmp(current->name, name) == 0) {
if (current == head) {
head = current->next;
} else if (current == tail) {
previous->next = NULL;
tail = previous;
} else {
previous->next = current->next;
}
free(current);
// return after removing the product
printf("Product removed.n");
return;
}
previous = current;
current = current->next;
}
printf("Product not found.n");
}
// function to sell a product from the linked list
void sellProduct() {
if (head == NULL) {
printf("No products in the list.n");
return;
}
char name[20];
printf("Enter the name of the product to sell: ");
scanf("%s", name);
Product* current = head;
while (current != NULL) {
if (strcmp(current->name, name) == 0) {
if (current->quantity == 0) {
printf("Product is out of stock.n");
}
else {
current->quantity--;
printf("Product sold. %d remaining.n", current->quantity);
}
return;
}
current = current->next;
}
printf("Product not found.n");
}
// function to save the products in the linked list to a file
void saveToFile() {
if (head == NULL) {
printf("No products in the list.n");
return;
}
char filename[20];
printf("Enter the filename to save to: ");
scanf("%s", filename);
FILE* file = fopen(filename, "w");
if (file == NULL) {
printf("Error opening file.n");
return;
}
Product* current = head;
while (current != NULL) {
fprintf(file, "%s %d %dn", current->name, current->price, current->quantity);
current = current->next;
}
fclose(file);
printf("Products saved to file.n");
}
void createList() {
// delete the current linked list, if it exists
deleteList();
printf("New list created.n");
}
void displayProduct() {
if (head == NULL) {
printf("No products in the list.n");
return;
}
printf("Product NametPricetQuantityn");
Product* current = head;
while (current != NULL) {
printf("%stt%dt%dn", current->name, current->price, current->quantity);
current = current->next;
}
}
void searchProduct() {
//**Please enter here**//
}
void purchaseProduct() {
//**Please enter here**//
}
void deleteList() {
//**Please enter here**//
} In this project, you will simulate a simple product management system using Linked Lists in
C. You need to create and maintain a Linked List that manages the current products' information.
Each product's information is stored as a node in this Linked List, including product's name, unit,
price and quantity. Product's name: The name of a product (e.g., water, milk, beef). It is a string.
Product's unit: The unit of a product (e.g., bottle, gallon, pound). It is a string. Product's price:
The price of a product (e.g., 3). It is of type int. Product's quantity: The quantity of a product
(e.g., 100). It is of type int. First, your program should have a menu for choices as follows. Also,
it should support the following operations. - Create an empty list: When ' 1 ' is pressed, an empty
list will be created. (For the implementation, you can create a Linked List with only one node as
the head.) This is the starting point of the program, before operations 29 can be executed. - Insert
a product: When ' 2 ' is pressed, the system should take user's keyboard input for a new product's
information (e.g., name, unit, price, quantity), create a new node, and add it into the Linked List.
- Delete a product: When ' 3 ' is pressed, the program should take user's keyboard input for the
product's name, and delete this product (the node) from the Linked List. - Delete the entire list:
When ' 4 ' is pressed, the program should delete each product's information by removing all the
nodes in the Linked List, including the head node that was created when you pressed ' 1 '. -
Search a product: When ' 5 ' is pressed, the program should take user's keyboard input for the
product's name, search this product in the Linked List, and return the search result (Found, or
Not Found). - Display products in the list: When ' 6 ' is pressed, every product in the Linked List
will be displayed in the screen, including its name, unit, price and quantity. - Purchase a product:
When ' 7 ' is pressed, the program should take user's keyboard input for the product's name, and
increase this product's quantity by 1.
- Sell a product: When ' 8 ' is pressed, the program should take user's keyboard input for the
product's name, and decrease this product's quantity by 1 . If this product's quantity becomes 0 ,
this product should be removed from the Linked List. - Save to File: When ' 9 ' is pressed, the
current products' information should be written to a file. Each product's information takes one
line in the file. - Exit: When ' 0 ' is pressed, the program exits. Assumptions: To simplify the
problem, we can have the following assumptions. - Product's name and unit are of types "string".
We can assume there are no blank spaces in these strings, e.g., a product's name cannot be "wa
ter". - Product's price and quantity are of types "int". We can assume the inputs from the user for
these two variables are integers, rather than other data types. - If "Save to File" is executed
multiple times, the latest information of products will be saved to a file (i.e., File overwrite
happens). - Product's name is the only identifier of a product and it is case-sensitive. In other
words, we simply assume "Water" and "water" are two different products. Robustness and Error
handling: The program must have the following considerations. - Operations 2 9 cannot be
executed if an empty list has not been created (i.e., Operation 1 should be started first). - For
"Insert a product" (when ' 2 ' is pressed), when a product's name is provided, the program should
search it among the existing products in the Linked List. If the product already exists in the
Linked List, then it cannot be inserted into the system. (A message should be printed instead.) -
For operations 3,7 and 8 , the program also needs to first search the product by its name. If the
product does not exist in the Linked List, these operations cannot proceed. (Some proper
messages should be printed instead.) - The program should keep running until ' 0 ' is pressed, if
the user provides the correct input. - For "Insert a product", the program should not allow
negative numbers or zeros for a product's price and quantity. (A message should be printed if the
user does provide negative numbers and zeros.) - For "Sell a product", if a product's quantity
becomes 0 after it is decreased by 1 , this product should be removed from the Linked List.

More Related Content

Similar to Im posting this again because the answer wasnt correct.Please .pdf

-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdfganisyedtrd
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
 
ObjectivesUse inheritance to create base and child classes.docx
ObjectivesUse inheritance to create base and child classes.docxObjectivesUse inheritance to create base and child classes.docx
ObjectivesUse inheritance to create base and child classes.docxmccormicknadine86
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codepradesigali1
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxBlake0FxCampbelld
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformMateusz Zalewski
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfsravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfsravi07
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfsravi07
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docxAdamq0DJonese
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testingMateusz Zalewski
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docxhoney690131
 
Using splunk6.2 labs
Using splunk6.2 labsUsing splunk6.2 labs
Using splunk6.2 labsJagadish a
 
Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.netGirija Muscut
 
Step by step abap_input help or lov
Step by step abap_input help or lovStep by step abap_input help or lov
Step by step abap_input help or lovMilind Patil
 
Cordova training : Day 6 - UI development using Framework7
Cordova training : Day 6 - UI development using Framework7Cordova training : Day 6 - UI development using Framework7
Cordova training : Day 6 - UI development using Framework7Binu Paul
 
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docx
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docxAssignment6~$signment6.docxAssignment6Assignment6.docxAs.docx
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docxssuser562afc1
 

Similar to Im posting this again because the answer wasnt correct.Please .pdf (20)

-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
ObjectivesUse inheritance to create base and child classes.docx
ObjectivesUse inheritance to create base and child classes.docxObjectivesUse inheritance to create base and child classes.docx
ObjectivesUse inheritance to create base and child classes.docx
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source code
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx
 
Using splunk6.2 labs
Using splunk6.2 labsUsing splunk6.2 labs
Using splunk6.2 labs
 
Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.net
 
Step by step abap_input help or lov
Step by step abap_input help or lovStep by step abap_input help or lov
Step by step abap_input help or lov
 
Cordova training : Day 6 - UI development using Framework7
Cordova training : Day 6 - UI development using Framework7Cordova training : Day 6 - UI development using Framework7
Cordova training : Day 6 - UI development using Framework7
 
Introducing Scratch
Introducing ScratchIntroducing Scratch
Introducing Scratch
 
Sap enhanced functions
Sap enhanced functionsSap enhanced functions
Sap enhanced functions
 
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docx
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docxAssignment6~$signment6.docxAssignment6Assignment6.docxAs.docx
Assignment6~$signment6.docxAssignment6Assignment6.docxAs.docx
 

More from maheshkumar12354

In a single strand of DNA, the individual nucleotides are covalenty .pdf
In a single strand of DNA, the individual nucleotides are covalenty .pdfIn a single strand of DNA, the individual nucleotides are covalenty .pdf
In a single strand of DNA, the individual nucleotides are covalenty .pdfmaheshkumar12354
 
In a recent survey conducted, a random sample of adults 18 years of .pdf
In a recent survey conducted, a random sample of adults 18 years of .pdfIn a recent survey conducted, a random sample of adults 18 years of .pdf
In a recent survey conducted, a random sample of adults 18 years of .pdfmaheshkumar12354
 
In a recent survey conducted a random sample of adults 18 years of a.pdf
In a recent survey conducted a random sample of adults 18 years of a.pdfIn a recent survey conducted a random sample of adults 18 years of a.pdf
In a recent survey conducted a random sample of adults 18 years of a.pdfmaheshkumar12354
 
In a hypothetical study, a researcher finds that police officers are.pdf
In a hypothetical study, a researcher finds that police officers are.pdfIn a hypothetical study, a researcher finds that police officers are.pdf
In a hypothetical study, a researcher finds that police officers are.pdfmaheshkumar12354
 
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdfIn a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdfmaheshkumar12354
 
In 2017, President Donald Trump was considering a major increase in .pdf
In 2017, President Donald Trump was considering a major increase in .pdfIn 2017, President Donald Trump was considering a major increase in .pdf
In 2017, President Donald Trump was considering a major increase in .pdfmaheshkumar12354
 
In 2021, Lee Jones put the final touches on a product she had worked.pdf
In 2021, Lee Jones put the final touches on a product she had worked.pdfIn 2021, Lee Jones put the final touches on a product she had worked.pdf
In 2021, Lee Jones put the final touches on a product she had worked.pdfmaheshkumar12354
 
In 2000 the Vermont state legislature approved a bill authorizing �c.pdf
In 2000 the Vermont state legislature approved a bill authorizing �c.pdfIn 2000 the Vermont state legislature approved a bill authorizing �c.pdf
In 2000 the Vermont state legislature approved a bill authorizing �c.pdfmaheshkumar12354
 
Implement the class Linked List to create a list of integers. You ne.pdf
Implement the class Linked List to create a list of integers. You ne.pdfImplement the class Linked List to create a list of integers. You ne.pdf
Implement the class Linked List to create a list of integers. You ne.pdfmaheshkumar12354
 
Implement a program in C++ a by creating a list ADT using the Object.pdf
Implement a program in C++ a by creating a list ADT using the Object.pdfImplement a program in C++ a by creating a list ADT using the Object.pdf
Implement a program in C++ a by creating a list ADT using the Object.pdfmaheshkumar12354
 
Implement a singly linked list as a functional data structure in Kot.pdf
Implement a singly linked list as a functional data structure in Kot.pdfImplement a singly linked list as a functional data structure in Kot.pdf
Implement a singly linked list as a functional data structure in Kot.pdfmaheshkumar12354
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
import java.awt.Color; import java.awt.Dimension; import.pdf
import java.awt.Color; import java.awt.Dimension; import.pdfimport java.awt.Color; import java.awt.Dimension; import.pdf
import java.awt.Color; import java.awt.Dimension; import.pdfmaheshkumar12354
 
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdf
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdfImplement two project schedules.BENCHMARKSImplement mechanisms t.pdf
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdfmaheshkumar12354
 
If you were to write an application program that needs to maintain s.pdf
If you were to write an application program that needs to maintain s.pdfIf you were to write an application program that needs to maintain s.pdf
If you were to write an application program that needs to maintain s.pdfmaheshkumar12354
 
Imagine that you are using a learning management system (such as Bla.pdf
Imagine that you are using a learning management system (such as Bla.pdfImagine that you are using a learning management system (such as Bla.pdf
Imagine that you are using a learning management system (such as Bla.pdfmaheshkumar12354
 
Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdfmaheshkumar12354
 
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdf
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdfIgnacio enters into a game of chance. A bag of money has twelve $1 b.pdf
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdfmaheshkumar12354
 
imagine a protein that has been engineered to contain a nuclear loca.pdf
imagine a protein that has been engineered to contain a nuclear loca.pdfimagine a protein that has been engineered to contain a nuclear loca.pdf
imagine a protein that has been engineered to contain a nuclear loca.pdfmaheshkumar12354
 
Im not trying to be rude, but I have had multiple of you experts .pdf
Im not trying to be rude, but I have had multiple of you experts .pdfIm not trying to be rude, but I have had multiple of you experts .pdf
Im not trying to be rude, but I have had multiple of you experts .pdfmaheshkumar12354
 

More from maheshkumar12354 (20)

In a single strand of DNA, the individual nucleotides are covalenty .pdf
In a single strand of DNA, the individual nucleotides are covalenty .pdfIn a single strand of DNA, the individual nucleotides are covalenty .pdf
In a single strand of DNA, the individual nucleotides are covalenty .pdf
 
In a recent survey conducted, a random sample of adults 18 years of .pdf
In a recent survey conducted, a random sample of adults 18 years of .pdfIn a recent survey conducted, a random sample of adults 18 years of .pdf
In a recent survey conducted, a random sample of adults 18 years of .pdf
 
In a recent survey conducted a random sample of adults 18 years of a.pdf
In a recent survey conducted a random sample of adults 18 years of a.pdfIn a recent survey conducted a random sample of adults 18 years of a.pdf
In a recent survey conducted a random sample of adults 18 years of a.pdf
 
In a hypothetical study, a researcher finds that police officers are.pdf
In a hypothetical study, a researcher finds that police officers are.pdfIn a hypothetical study, a researcher finds that police officers are.pdf
In a hypothetical study, a researcher finds that police officers are.pdf
 
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdfIn a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
 
In 2017, President Donald Trump was considering a major increase in .pdf
In 2017, President Donald Trump was considering a major increase in .pdfIn 2017, President Donald Trump was considering a major increase in .pdf
In 2017, President Donald Trump was considering a major increase in .pdf
 
In 2021, Lee Jones put the final touches on a product she had worked.pdf
In 2021, Lee Jones put the final touches on a product she had worked.pdfIn 2021, Lee Jones put the final touches on a product she had worked.pdf
In 2021, Lee Jones put the final touches on a product she had worked.pdf
 
In 2000 the Vermont state legislature approved a bill authorizing �c.pdf
In 2000 the Vermont state legislature approved a bill authorizing �c.pdfIn 2000 the Vermont state legislature approved a bill authorizing �c.pdf
In 2000 the Vermont state legislature approved a bill authorizing �c.pdf
 
Implement the class Linked List to create a list of integers. You ne.pdf
Implement the class Linked List to create a list of integers. You ne.pdfImplement the class Linked List to create a list of integers. You ne.pdf
Implement the class Linked List to create a list of integers. You ne.pdf
 
Implement a program in C++ a by creating a list ADT using the Object.pdf
Implement a program in C++ a by creating a list ADT using the Object.pdfImplement a program in C++ a by creating a list ADT using the Object.pdf
Implement a program in C++ a by creating a list ADT using the Object.pdf
 
Implement a singly linked list as a functional data structure in Kot.pdf
Implement a singly linked list as a functional data structure in Kot.pdfImplement a singly linked list as a functional data structure in Kot.pdf
Implement a singly linked list as a functional data structure in Kot.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
import java.awt.Color; import java.awt.Dimension; import.pdf
import java.awt.Color; import java.awt.Dimension; import.pdfimport java.awt.Color; import java.awt.Dimension; import.pdf
import java.awt.Color; import java.awt.Dimension; import.pdf
 
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdf
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdfImplement two project schedules.BENCHMARKSImplement mechanisms t.pdf
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdf
 
If you were to write an application program that needs to maintain s.pdf
If you were to write an application program that needs to maintain s.pdfIf you were to write an application program that needs to maintain s.pdf
If you were to write an application program that needs to maintain s.pdf
 
Imagine that you are using a learning management system (such as Bla.pdf
Imagine that you are using a learning management system (such as Bla.pdfImagine that you are using a learning management system (such as Bla.pdf
Imagine that you are using a learning management system (such as Bla.pdf
 
Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdf
 
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdf
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdfIgnacio enters into a game of chance. A bag of money has twelve $1 b.pdf
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdf
 
imagine a protein that has been engineered to contain a nuclear loca.pdf
imagine a protein that has been engineered to contain a nuclear loca.pdfimagine a protein that has been engineered to contain a nuclear loca.pdf
imagine a protein that has been engineered to contain a nuclear loca.pdf
 
Im not trying to be rude, but I have had multiple of you experts .pdf
Im not trying to be rude, but I have had multiple of you experts .pdfIm not trying to be rude, but I have had multiple of you experts .pdf
Im not trying to be rude, but I have had multiple of you experts .pdf
 

Recently uploaded

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Recently uploaded (20)

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 

Im posting this again because the answer wasnt correct.Please .pdf

  • 1. I'm posting this again because the answer wasn't correct. **Please read this carefully and the prompt carefully** Hello All, I need help with Operations 4, 5, and 7. Make sure it's in C programming language. Operations needed: Operation 4 is Delete the entire list: When 4 is pressed, the program should delete each products information by removing all the nodes in the Linked List, including the head node that was created when you pressed 1. Operation 5 is Search a product: When 5 is pressed, the program should take the users keyboard input for the products name, search this product in the Linked List, and return the search result (Found, or Not Found). and Operation 7 is Purchase a product: When 7 is pressed, the program should take users keyboard input for the products name, and increase this products quantity by 1. I provided a code for what I have so far. Code #include #include #include // define a product struct typedef struct Product { char name[20]; int price; int quantity; struct Product* next; } Product; // declare global variables Product* head = NULL; // start of the linked list Product* tail = NULL; // end of the linked list // function prototypes void createList(); void insertProduct(); void removeProduct(); void deleteList(); void searchProduct(); void displayProduct(); void purchaseProduct();
  • 2. void sellProduct(); void saveToFile(); int main() { char choice; do { printf("nnPlease choose an option:n"); printf("1. Create a new listn"); printf("2. Create a new productn"); printf("3. Remove a productn"); printf("4. Delete a listn"); printf("5. Search a productn"); printf("6. Display a productn"); printf("7. Purchase a productn"); printf("8. Sell a productn"); printf("9. Save products to filen"); printf("0. Exitn"); printf("Enter your choice: "); scanf(" %c", &choice); switch (choice) { case '1': createList(); break; case '2': insertProduct(); break; case '3': removeProduct(); break; case '4': deleteList(); break; case '5': searchProduct(); break; case '6': displayProduct();
  • 3. break; case '7': purchaseProduct(); break; case '8': sellProduct(); break; case '9': saveToFile(); break; case '0': printf("Exiting program.n"); break; default: printf("Invalid choice. Please try again.n"); break; } } while (choice != '0'); return 0; } // function to insert a new product into the linked list void insertProduct() { Product* newProduct = (Product*) malloc(sizeof(Product)); printf("Enter the name of the product: "); scanf("%s", newProduct->name); printf("Enter the price of the product: "); scanf("%d", &newProduct->price); printf("Enter the quantity of the product: "); scanf("%d", &newProduct->quantity); if (newProduct->price <= 0 || newProduct->quantity <= 0) { printf("Price and quantity must be positive integers. Product not added.n"); free(newProduct); return; } newProduct->next = NULL; // check if the product already exists in the linked list
  • 4. Product* current = head; while (current != NULL) { if (strcmp(current->name, newProduct->name) == 0) { printf("Product already exists. Product not added.n"); free(newProduct); return; } current = current->next; } // add the new product to the end of the linked list if (head == NULL) { head = newProduct; tail = newProduct; } else { tail->next = newProduct; tail = newProduct; } printf("Product added.n"); } // function to remove a product from the linked list void removeProduct() { if (head == NULL) { printf("No products in the list.n"); return; } char name[20]; printf("Enter the name of the product to remove: "); scanf("%s", name); Product* current = head; Product* previous = NULL; while (current != NULL) { if (strcmp(current->name, name) == 0) { if (current == head) { head = current->next; } else if (current == tail) { previous->next = NULL;
  • 5. tail = previous; } else { previous->next = current->next; } free(current); // return after removing the product printf("Product removed.n"); return; } previous = current; current = current->next; } printf("Product not found.n"); } // function to sell a product from the linked list void sellProduct() { if (head == NULL) { printf("No products in the list.n"); return; } char name[20]; printf("Enter the name of the product to sell: "); scanf("%s", name); Product* current = head; while (current != NULL) { if (strcmp(current->name, name) == 0) { if (current->quantity == 0) { printf("Product is out of stock.n"); } else { current->quantity--; printf("Product sold. %d remaining.n", current->quantity); } return; }
  • 6. current = current->next; } printf("Product not found.n"); } // function to save the products in the linked list to a file void saveToFile() { if (head == NULL) { printf("No products in the list.n"); return; } char filename[20]; printf("Enter the filename to save to: "); scanf("%s", filename); FILE* file = fopen(filename, "w"); if (file == NULL) { printf("Error opening file.n"); return; } Product* current = head; while (current != NULL) { fprintf(file, "%s %d %dn", current->name, current->price, current->quantity); current = current->next; } fclose(file); printf("Products saved to file.n"); } void createList() { // delete the current linked list, if it exists deleteList(); printf("New list created.n"); } void displayProduct() { if (head == NULL) { printf("No products in the list.n"); return; }
  • 7. printf("Product NametPricetQuantityn"); Product* current = head; while (current != NULL) { printf("%stt%dt%dn", current->name, current->price, current->quantity); current = current->next; } } void searchProduct() { //**Please enter here**// } void purchaseProduct() { //**Please enter here**// } void deleteList() { //**Please enter here**// } In this project, you will simulate a simple product management system using Linked Lists in C. You need to create and maintain a Linked List that manages the current products' information. Each product's information is stored as a node in this Linked List, including product's name, unit, price and quantity. Product's name: The name of a product (e.g., water, milk, beef). It is a string. Product's unit: The unit of a product (e.g., bottle, gallon, pound). It is a string. Product's price: The price of a product (e.g., 3). It is of type int. Product's quantity: The quantity of a product (e.g., 100). It is of type int. First, your program should have a menu for choices as follows. Also, it should support the following operations. - Create an empty list: When ' 1 ' is pressed, an empty list will be created. (For the implementation, you can create a Linked List with only one node as the head.) This is the starting point of the program, before operations 29 can be executed. - Insert a product: When ' 2 ' is pressed, the system should take user's keyboard input for a new product's information (e.g., name, unit, price, quantity), create a new node, and add it into the Linked List. - Delete a product: When ' 3 ' is pressed, the program should take user's keyboard input for the product's name, and delete this product (the node) from the Linked List. - Delete the entire list: When ' 4 ' is pressed, the program should delete each product's information by removing all the nodes in the Linked List, including the head node that was created when you pressed ' 1 '. - Search a product: When ' 5 ' is pressed, the program should take user's keyboard input for the product's name, search this product in the Linked List, and return the search result (Found, or Not Found). - Display products in the list: When ' 6 ' is pressed, every product in the Linked List will be displayed in the screen, including its name, unit, price and quantity. - Purchase a product: When ' 7 ' is pressed, the program should take user's keyboard input for the product's name, and
  • 8. increase this product's quantity by 1. - Sell a product: When ' 8 ' is pressed, the program should take user's keyboard input for the product's name, and decrease this product's quantity by 1 . If this product's quantity becomes 0 , this product should be removed from the Linked List. - Save to File: When ' 9 ' is pressed, the current products' information should be written to a file. Each product's information takes one line in the file. - Exit: When ' 0 ' is pressed, the program exits. Assumptions: To simplify the problem, we can have the following assumptions. - Product's name and unit are of types "string". We can assume there are no blank spaces in these strings, e.g., a product's name cannot be "wa ter". - Product's price and quantity are of types "int". We can assume the inputs from the user for these two variables are integers, rather than other data types. - If "Save to File" is executed multiple times, the latest information of products will be saved to a file (i.e., File overwrite happens). - Product's name is the only identifier of a product and it is case-sensitive. In other words, we simply assume "Water" and "water" are two different products. Robustness and Error handling: The program must have the following considerations. - Operations 2 9 cannot be executed if an empty list has not been created (i.e., Operation 1 should be started first). - For "Insert a product" (when ' 2 ' is pressed), when a product's name is provided, the program should search it among the existing products in the Linked List. If the product already exists in the Linked List, then it cannot be inserted into the system. (A message should be printed instead.) - For operations 3,7 and 8 , the program also needs to first search the product by its name. If the product does not exist in the Linked List, these operations cannot proceed. (Some proper messages should be printed instead.) - The program should keep running until ' 0 ' is pressed, if the user provides the correct input. - For "Insert a product", the program should not allow negative numbers or zeros for a product's price and quantity. (A message should be printed if the user does provide negative numbers and zeros.) - For "Sell a product", if a product's quantity becomes 0 after it is decreased by 1 , this product should be removed from the Linked List.