SlideShare a Scribd company logo
// Write the compiler used: Visual studio or gcc
// Reminder that your file name is incredibly important. Please do not change it.
// Reminder that we are compiling on Gradescope using GCC.
// READ BEFORE YOU START:
// You are given a partially completed program that creates a linked list of game
items like you'd see in a folder.
// Each item has this information: item name, game name, type of item, item ID.
// The struct 'itemRecord' holds the information of one item. Variety is an enum.
// A linked list of structs called 'list' is declared to hold the list of items.
// To begin, you should trace through the given code and understand how it works.
// Please read the instructions above each required function and follow the
directions carefully.
// You should not modify any of the given code, the return types, or the
parameters. Otherwise, you risk getting compilation errors.
// You are not allowed to modify main().
// You can use all string library functions.
// You will have to write your functions from scratch by looking at what is
expected to be passed into them in the pre-existing functions
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ITEMS 15
#define MAX_NAME_LENGTH 25
typedef enum { Health = 0, Equip, Etc } itemType; // enum type
struct itemRecord { // struct for item details
char itemName[MAX_NAME_LENGTH];
char gameName[MAX_NAME_LENGTH];
itemType variety;
unsigned int itemID;
struct itemRecord* next; // pointer to next node
};
struct itemRecord* list = NULL; // declare linked list
'list'
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already pre-implemented last homework
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation: add, sort, delete, load
// Implement your own headers.
int main()
{
char* fileName = "Item_List.txt";
load(fileName); // load list of items from file (if it exists).
Initially there will be no file.
char choice = 'i'; // initialized to a dummy value
do
{
printf("nEnter your selection:n");
printf("t a: add a new itemn");
printf("t d: display item listn");
printf("t r: remove a item from listn");
printf("t s: sort item list by IDn");
printf("t q: quitn");
choice = getchar();
flushStdIn();
executeAction(choice);
} while (choice != 'q');
save(fileName); // save list of items to file (overwrites file if it
exists)
return 0;
}
// flush out leftover 'n' characters
void flushStdIn()
{
char c;
do c = getchar();
while (c != 'n' && c != EOF);
}
// ask for details from user for the given selection and perform that action
void executeAction(char c)
{
char itemName_input[MAX_NAME_LENGTH], gameName_input[MAX_NAME_LENGTH];
unsigned int itemId_input, add_result = 0;
char itemtype_input[20];
switch (c)
{
case 'a':
// input item record from user
printf("nEnter item name: ");
fgets(itemName_input, sizeof(itemName_input), stdin);
itemName_input[strlen(itemName_input) - 1] = '0'; // discard the
trailing 'n' char
printf("Enter game name: ");
fgets(gameName_input, sizeof(gameName_input), stdin);
gameName_input[strlen(gameName_input) - 1] = '0'; // discard the
trailing 'n' char
printf("Enter item type (Health/Equip/Etc): ");
fgets(itemtype_input, sizeof(itemtype_input), stdin);
itemtype_input[strlen(itemtype_input) - 1] = '0'; // discard the
trailing 'n' char
printf("Please enter item ID number: ");
scanf("%d", &itemId_input);
flushStdIn();
// add the item to the list
add_result = add(itemName_input, gameName_input, itemtype_input,
itemId_input);
if (add_result == 0)
printf("nItem is already on the list! nn");
else if (add_result == 1)
printf("nItem successfully added to the list! nn");
else
printf("nUnable to add the item. the Item list is full! nn");
break;
case 'r':
printf("Please enter ID number of item to be deleted: ");
scanf("%d", &itemId_input);
flushStdIn();
int delete_result = delete(itemId_input);
if (delete_result == 0)
printf("nItem not found in the list! nn");
else
printf("nItem deleted successfully! nn");
break;
case 'd':
display();
break;
case 's':
sort();
break;
case 'q':
break;
default: printf("%c is invalid input!n", c);
}
}
// This function displays the item list with the details (struct elements) of each
item.
// Display all items.
void display()
{
struct itemRecord* tempList = list; // work on a copy of
'list'
char* itemTypeString = "NoType"; // dummy init
while (tempList != NULL) { // traverse all items in
the list
printf("nItem Name: %s", tempList->itemName); // display the
item name
printf("nGame name: %s", tempList->gameName); // display the
game name
if (tempList->variety == Health) // find what to display
for item type
itemTypeString = "Health";
else if(tempList->variety == Equip)
itemTypeString = "Equip";
else
itemTypeString = "Etc";
printf("nItem Type: %s", itemTypeString); // display item
type
printf("nItem ID: %d", tempList->itemID); // display item id
printf("n");
tempList = tempList->next;
}
}
// save() is called at the end of main()
// This function saves the linked list of structures to file.
// save() is called at end of main() to save the item list to a file.
// The file is saved at the same place as your C file. For VS, the default
directory looks like this:
// C:Users<username>DocumentsVisual Studio 20XXProjectsProject1Project1
// You can simply delete the file to 'reset the list' or to avoid loading from it.
void save(char* fileName)
{
struct itemRecord* tempList = list; // work on a copy of 'list'
FILE* file;
int itemTypeValue = 0;
file = fopen(fileName, "wb"); // open file for writing
fwrite(&count, sizeof(count), 1, file); // First, store the number of
items in the list
// Parse the list and write item records to the file
while (tempList != NULL) {
fwrite(tempList->itemName, sizeof(tempList->itemName), 1, file);
fwrite(tempList->gameName, sizeof(tempList->gameName), 1, file);
// convert enum to a number for storing
if (tempList->variety == Health)
itemTypeValue = 0; // 0 for Health
else if(tempList->variety == Equip)
itemTypeValue = 1; // 1 for Equip
else
itemTypeValue = 2; // 2 for Etc
fwrite(&itemTypeValue, sizeof(itemTypeValue), 1, file);
fwrite(&tempList->itemID, sizeof(tempList->itemID), 1, file);
tempList = tempList->next;
}
fclose(file); // close the file after writing
}
// Q1 : add (10 points)
// This function is used to add an item into the list. You can simply add the new
item to the end of list (linked list of structs).
// Do not allow the item to be added to the list if it already exists in the list.
You can do that by checking the item IDs already in the list.
// If the item already exists then return 0 without adding it to the list. If the
item does not exist in the list, then add the item at the end of the list and
return 1.
// If item list is full, then do not add new item to the list and return 2.
// NOTE: Notice how return type of add() is checked in case 'a' of executeAction()
// NOTE: You will likely pass the variety attribute as a string. This must be
converted to an enum type because itemType has enum type.
// The list should be case sensitive. For instance, 'Poprocks' and 'popRocks'
should be considered two different names.
// Hint: 'count' holds the number of items currently in the list
// Q2 : sort (10 points)
// This function is used to sort the list (linked list of structs) numerically by
item ID.
// Parse the list and compare the item IDs to check which one should appear before
the other in the list.
// Sorting should happen within the list. That is, you should not create a new node
of structs having sorted items.
// Please use this print statement to print after successfully sorting the list:
// printf("nItem list sorted! Use display option 'd' to view sorted list.n");
// Q3 : delete (10 points)
// This function is used to delete an item by ID.
// Parse the list and compare the item IDs to check which one should be deleted.
// Return 0 if the specified ID was not found. Return 1 upon successful removal of
a record.
// Q4: load (10 points)
// This function is called in the beginning of main().
// This function reads the item list from the saved file and builds the linked list
of structures 'list'.
// In the first run of the program, there will be no saved file because save() is
called at the end of program.
// So, at the begining of this function, write code to open the file and check if
it exists. If file does not exist, then return from the function.
// (See the expected output of add() in homework the question file. It displays
"Item_List.txt not found" because the file did not exist initially.)
// If the file exists, then parse the item list to read the item details from the
file.
// Use the save function given above as an example of how to write this function.
Notice the order in which the struct elements are saved in save()
// You need to use the same order to read the list back.
// NOTE: The saved file is not exactly readable because all elements of the struct
are not string or char type.
// So you need to implement load() similar to how save() is implemented. Only then
the 'list' will be loaded correctly.
// You can simply delete the file to 'reset the list' or to avoid loading from it.
// You'll need to use the following two print statements in your code:
// printf("Item record loaded from %s.n", fileName);
// printf("%s not found.n", fileName);

More Related Content

Similar to -- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf

#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
ajoy21
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdf
info334223
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
rajkumarm401
 
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfAll code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
akashenterprises93
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
mayorothenguyenhob69
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
ssuserc77a341
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
shahidqamar17
 
C++ detyrat postim_slideshare
C++ detyrat postim_slideshareC++ detyrat postim_slideshare
C++ detyrat postim_slideshare
tctal
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
udit652068
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdf
fantoosh1
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
fms12345
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docx
Komlin1
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
ajoy21
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
aminbijal86
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdf
anilgoelslg
 

Similar to -- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf (20)

#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdf
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
 
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfAll code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
C++ detyrat postim_slideshare
C++ detyrat postim_slideshareC++ detyrat postim_slideshare
C++ detyrat postim_slideshare
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdf
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docx
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
강의자료6
강의자료6강의자료6
강의자료6
 
강의자료7
강의자료7강의자료7
강의자료7
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdf
 

More from ganisyedtrd

--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
ganisyedtrd
 
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
ganisyedtrd
 
--kindly help with the correct answer --must show diagram Explain what.pdf
--kindly help with the correct answer --must show diagram Explain what.pdf--kindly help with the correct answer --must show diagram Explain what.pdf
--kindly help with the correct answer --must show diagram Explain what.pdf
ganisyedtrd
 
--- If you were start a business- what are the advantages in using equ.pdf
--- If you were start a business- what are the advantages in using equ.pdf--- If you were start a business- what are the advantages in using equ.pdf
--- If you were start a business- what are the advantages in using equ.pdf
ganisyedtrd
 
--- Interpret the figure below given what you know about wood frogs---.pdf
--- Interpret the figure below given what you know about wood frogs---.pdf--- Interpret the figure below given what you know about wood frogs---.pdf
--- Interpret the figure below given what you know about wood frogs---.pdf
ganisyedtrd
 
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
ganisyedtrd
 
--- Which of the following influences the instantaneous rate of change.pdf
--- Which of the following influences the instantaneous rate of change.pdf--- Which of the following influences the instantaneous rate of change.pdf
--- Which of the following influences the instantaneous rate of change.pdf
ganisyedtrd
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
ganisyedtrd
 
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
ganisyedtrd
 
- TIF B cells and T cells are able to alter their genome- What kind of.pdf
- TIF B cells and T cells are able to alter their genome- What kind of.pdf- TIF B cells and T cells are able to alter their genome- What kind of.pdf
- TIF B cells and T cells are able to alter their genome- What kind of.pdf
ganisyedtrd
 
- The array data of integers is sorted in an increaning order- - The i.pdf
- The array data of integers is sorted in an increaning order- - The i.pdf- The array data of integers is sorted in an increaning order- - The i.pdf
- The array data of integers is sorted in an increaning order- - The i.pdf
ganisyedtrd
 
- Quantitative (record completenessdocuments are present- forms authen.pdf
- Quantitative (record completenessdocuments are present- forms authen.pdf- Quantitative (record completenessdocuments are present- forms authen.pdf
- Quantitative (record completenessdocuments are present- forms authen.pdf
ganisyedtrd
 
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
ganisyedtrd
 
- In 150-250 words- respond to all questions- This is your initial dis.pdf
- In 150-250 words- respond to all questions- This is your initial dis.pdf- In 150-250 words- respond to all questions- This is your initial dis.pdf
- In 150-250 words- respond to all questions- This is your initial dis.pdf
ganisyedtrd
 
- Insert the following number into this tree 20 - Show all the steps o.pdf
- Insert the following number into this tree 20 - Show all the steps o.pdf- Insert the following number into this tree 20 - Show all the steps o.pdf
- Insert the following number into this tree 20 - Show all the steps o.pdf
ganisyedtrd
 
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
ganisyedtrd
 
- If your class investigated two different types of tissues (plants)-.pdf
- If your class investigated two different types of tissues (plants)-.pdf- If your class investigated two different types of tissues (plants)-.pdf
- If your class investigated two different types of tissues (plants)-.pdf
ganisyedtrd
 
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
ganisyedtrd
 
- Drag the labels of Group 1 to their respective targets to identify p.pdf
- Drag the labels of Group 1 to their respective targets to identify p.pdf- Drag the labels of Group 1 to their respective targets to identify p.pdf
- Drag the labels of Group 1 to their respective targets to identify p.pdf
ganisyedtrd
 
- Each student must post ane (1) substantial intid post as a response.pdf
- Each student must post ane (1) substantial intid post as a response.pdf- Each student must post ane (1) substantial intid post as a response.pdf
- Each student must post ane (1) substantial intid post as a response.pdf
ganisyedtrd
 

More from ganisyedtrd (20)

--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdf
 
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
--import statemnts for Random- Scanner and IO import java-util-Random-.pdf
 
--kindly help with the correct answer --must show diagram Explain what.pdf
--kindly help with the correct answer --must show diagram Explain what.pdf--kindly help with the correct answer --must show diagram Explain what.pdf
--kindly help with the correct answer --must show diagram Explain what.pdf
 
--- If you were start a business- what are the advantages in using equ.pdf
--- If you were start a business- what are the advantages in using equ.pdf--- If you were start a business- what are the advantages in using equ.pdf
--- If you were start a business- what are the advantages in using equ.pdf
 
--- Interpret the figure below given what you know about wood frogs---.pdf
--- Interpret the figure below given what you know about wood frogs---.pdf--- Interpret the figure below given what you know about wood frogs---.pdf
--- Interpret the figure below given what you know about wood frogs---.pdf
 
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
--------- Lala--- the noll (fnrmad plement) indicated by letter A is a.pdf
 
--- Which of the following influences the instantaneous rate of change.pdf
--- Which of the following influences the instantaneous rate of change.pdf--- Which of the following influences the instantaneous rate of change.pdf
--- Which of the following influences the instantaneous rate of change.pdf
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
 
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
- There are 50 fish in a pond in January- The fish grow at a rate of 6.pdf
 
- TIF B cells and T cells are able to alter their genome- What kind of.pdf
- TIF B cells and T cells are able to alter their genome- What kind of.pdf- TIF B cells and T cells are able to alter their genome- What kind of.pdf
- TIF B cells and T cells are able to alter their genome- What kind of.pdf
 
- The array data of integers is sorted in an increaning order- - The i.pdf
- The array data of integers is sorted in an increaning order- - The i.pdf- The array data of integers is sorted in an increaning order- - The i.pdf
- The array data of integers is sorted in an increaning order- - The i.pdf
 
- Quantitative (record completenessdocuments are present- forms authen.pdf
- Quantitative (record completenessdocuments are present- forms authen.pdf- Quantitative (record completenessdocuments are present- forms authen.pdf
- Quantitative (record completenessdocuments are present- forms authen.pdf
 
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
- Lab T Reriow Hemneork + Oun on March 10- 2023 2 anantwred Table 72 P.pdf
 
- In 150-250 words- respond to all questions- This is your initial dis.pdf
- In 150-250 words- respond to all questions- This is your initial dis.pdf- In 150-250 words- respond to all questions- This is your initial dis.pdf
- In 150-250 words- respond to all questions- This is your initial dis.pdf
 
- Insert the following number into this tree 20 - Show all the steps o.pdf
- Insert the following number into this tree 20 - Show all the steps o.pdf- Insert the following number into this tree 20 - Show all the steps o.pdf
- Insert the following number into this tree 20 - Show all the steps o.pdf
 
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdf
 
- If your class investigated two different types of tissues (plants)-.pdf
- If your class investigated two different types of tissues (plants)-.pdf- If your class investigated two different types of tissues (plants)-.pdf
- If your class investigated two different types of tissues (plants)-.pdf
 
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdf
 
- Drag the labels of Group 1 to their respective targets to identify p.pdf
- Drag the labels of Group 1 to their respective targets to identify p.pdf- Drag the labels of Group 1 to their respective targets to identify p.pdf
- Drag the labels of Group 1 to their respective targets to identify p.pdf
 
- Each student must post ane (1) substantial intid post as a response.pdf
- Each student must post ane (1) substantial intid post as a response.pdf- Each student must post ane (1) substantial intid post as a response.pdf
- Each student must post ane (1) substantial intid post as a response.pdf
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf

  • 1. // Write the compiler used: Visual studio or gcc // Reminder that your file name is incredibly important. Please do not change it. // Reminder that we are compiling on Gradescope using GCC. // READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of game items like you'd see in a folder. // Each item has this information: item name, game name, type of item, item ID. // The struct 'itemRecord' holds the information of one item. Variety is an enum. // A linked list of structs called 'list' is declared to hold the list of items. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // You should not modify any of the given code, the return types, or the parameters. Otherwise, you risk getting compilation errors. // You are not allowed to modify main(). // You can use all string library functions. // You will have to write your functions from scratch by looking at what is expected to be passed into them in the pre-existing functions // WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_ITEMS 15 #define MAX_NAME_LENGTH 25 typedef enum { Health = 0, Equip, Etc } itemType; // enum type struct itemRecord { // struct for item details char itemName[MAX_NAME_LENGTH]; char gameName[MAX_NAME_LENGTH]; itemType variety; unsigned int itemID; struct itemRecord* next; // pointer to next node }; struct itemRecord* list = NULL; // declare linked list 'list' int count = 0; // the number of items currently stored in the list (initialized to 0) // functions already pre-implemented last homework void flushStdIn(); void executeAction(char); void save(char* fileName); void display(); // functions that need implementation: add, sort, delete, load // Implement your own headers. int main() {
  • 2. char* fileName = "Item_List.txt"; load(fileName); // load list of items from file (if it exists). Initially there will be no file. char choice = 'i'; // initialized to a dummy value do { printf("nEnter your selection:n"); printf("t a: add a new itemn"); printf("t d: display item listn"); printf("t r: remove a item from listn"); printf("t s: sort item list by IDn"); printf("t q: quitn"); choice = getchar(); flushStdIn(); executeAction(choice); } while (choice != 'q'); save(fileName); // save list of items to file (overwrites file if it exists) return 0; } // flush out leftover 'n' characters void flushStdIn() { char c; do c = getchar(); while (c != 'n' && c != EOF); } // ask for details from user for the given selection and perform that action void executeAction(char c) { char itemName_input[MAX_NAME_LENGTH], gameName_input[MAX_NAME_LENGTH]; unsigned int itemId_input, add_result = 0; char itemtype_input[20]; switch (c) { case 'a': // input item record from user printf("nEnter item name: "); fgets(itemName_input, sizeof(itemName_input), stdin); itemName_input[strlen(itemName_input) - 1] = '0'; // discard the trailing 'n' char printf("Enter game name: "); fgets(gameName_input, sizeof(gameName_input), stdin); gameName_input[strlen(gameName_input) - 1] = '0'; // discard the trailing 'n' char printf("Enter item type (Health/Equip/Etc): ");
  • 3. fgets(itemtype_input, sizeof(itemtype_input), stdin); itemtype_input[strlen(itemtype_input) - 1] = '0'; // discard the trailing 'n' char printf("Please enter item ID number: "); scanf("%d", &itemId_input); flushStdIn(); // add the item to the list add_result = add(itemName_input, gameName_input, itemtype_input, itemId_input); if (add_result == 0) printf("nItem is already on the list! nn"); else if (add_result == 1) printf("nItem successfully added to the list! nn"); else printf("nUnable to add the item. the Item list is full! nn"); break; case 'r': printf("Please enter ID number of item to be deleted: "); scanf("%d", &itemId_input); flushStdIn(); int delete_result = delete(itemId_input); if (delete_result == 0) printf("nItem not found in the list! nn"); else printf("nItem deleted successfully! nn"); break; case 'd': display(); break; case 's': sort(); break; case 'q': break; default: printf("%c is invalid input!n", c); } } // This function displays the item list with the details (struct elements) of each item. // Display all items. void display() { struct itemRecord* tempList = list; // work on a copy of 'list' char* itemTypeString = "NoType"; // dummy init
  • 4. while (tempList != NULL) { // traverse all items in the list printf("nItem Name: %s", tempList->itemName); // display the item name printf("nGame name: %s", tempList->gameName); // display the game name if (tempList->variety == Health) // find what to display for item type itemTypeString = "Health"; else if(tempList->variety == Equip) itemTypeString = "Equip"; else itemTypeString = "Etc"; printf("nItem Type: %s", itemTypeString); // display item type printf("nItem ID: %d", tempList->itemID); // display item id printf("n"); tempList = tempList->next; } } // save() is called at the end of main() // This function saves the linked list of structures to file. // save() is called at end of main() to save the item list to a file. // The file is saved at the same place as your C file. For VS, the default directory looks like this: // C:Users<username>DocumentsVisual Studio 20XXProjectsProject1Project1 // You can simply delete the file to 'reset the list' or to avoid loading from it. void save(char* fileName) { struct itemRecord* tempList = list; // work on a copy of 'list' FILE* file; int itemTypeValue = 0; file = fopen(fileName, "wb"); // open file for writing fwrite(&count, sizeof(count), 1, file); // First, store the number of items in the list // Parse the list and write item records to the file while (tempList != NULL) { fwrite(tempList->itemName, sizeof(tempList->itemName), 1, file); fwrite(tempList->gameName, sizeof(tempList->gameName), 1, file); // convert enum to a number for storing if (tempList->variety == Health) itemTypeValue = 0; // 0 for Health else if(tempList->variety == Equip) itemTypeValue = 1; // 1 for Equip else
  • 5. itemTypeValue = 2; // 2 for Etc fwrite(&itemTypeValue, sizeof(itemTypeValue), 1, file); fwrite(&tempList->itemID, sizeof(tempList->itemID), 1, file); tempList = tempList->next; } fclose(file); // close the file after writing } // Q1 : add (10 points) // This function is used to add an item into the list. You can simply add the new item to the end of list (linked list of structs). // Do not allow the item to be added to the list if it already exists in the list. You can do that by checking the item IDs already in the list. // If the item already exists then return 0 without adding it to the list. If the item does not exist in the list, then add the item at the end of the list and return 1. // If item list is full, then do not add new item to the list and return 2. // NOTE: Notice how return type of add() is checked in case 'a' of executeAction() // NOTE: You will likely pass the variety attribute as a string. This must be converted to an enum type because itemType has enum type. // The list should be case sensitive. For instance, 'Poprocks' and 'popRocks' should be considered two different names. // Hint: 'count' holds the number of items currently in the list // Q2 : sort (10 points) // This function is used to sort the list (linked list of structs) numerically by item ID. // Parse the list and compare the item IDs to check which one should appear before the other in the list. // Sorting should happen within the list. That is, you should not create a new node of structs having sorted items. // Please use this print statement to print after successfully sorting the list: // printf("nItem list sorted! Use display option 'd' to view sorted list.n"); // Q3 : delete (10 points) // This function is used to delete an item by ID. // Parse the list and compare the item IDs to check which one should be deleted. // Return 0 if the specified ID was not found. Return 1 upon successful removal of a record. // Q4: load (10 points) // This function is called in the beginning of main(). // This function reads the item list from the saved file and builds the linked list of structures 'list'. // In the first run of the program, there will be no saved file because save() is called at the end of program. // So, at the begining of this function, write code to open the file and check if it exists. If file does not exist, then return from the function. // (See the expected output of add() in homework the question file. It displays
  • 6. "Item_List.txt not found" because the file did not exist initially.) // If the file exists, then parse the item list to read the item details from the file. // Use the save function given above as an example of how to write this function. Notice the order in which the struct elements are saved in save() // You need to use the same order to read the list back. // NOTE: The saved file is not exactly readable because all elements of the struct are not string or char type. // So you need to implement load() similar to how save() is implemented. Only then the 'list' will be loaded correctly. // You can simply delete the file to 'reset the list' or to avoid loading from it. // You'll need to use the following two print statements in your code: // printf("Item record loaded from %s.n", fileName); // printf("%s not found.n", fileName);