// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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), s.
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
please follow all instructions and answer the inbedded questions, and written in C pls
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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'.
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 show the output. Thank
you!
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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.
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfsravi07
Written in C, requires linked lists. Please answer the 4 questions and show the output. Thank
you!
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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.
written in c- please answer the 4 questions and write the functions ba.pdfsravi07
written in c, please answer the 4 questions and write the functions based on the given code.
Thank you
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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];
switc.
-- Reminder that your file name is incredibly important- Please do not.docxAdamq0DJonese
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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 idNumber_input, add_result = 0;
char variety_input[20];
switch (c)
{
case 'a':
// input item record from user
printf("\nEnter item name: ").
In C pls -- Write your name here -- Write the compiler used- Visual st.docxBlake0FxCampbelld
In C pls
// Write your name here
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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 idNumber_input, add_result = 0;
char variety_input[20];
swi.
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
Please answer the 4 questions using C. The expected output is shown below. Thank you!
---------------------------------------------------------------------------------------------------
// Write your name here
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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
.
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
Using the C++ programming language
1. Implement the UnsortedList class to store a list of numbers that are input into the list from
data.txt.
- create a main.cpp file that gets the numbers from the file
- insert the number 7 into the list
- insert another number 300 into the list
- delete the number 6 from the list
- print out the following:
--the entire list
- the greatest
- the least
2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file two called
outfile2.txt
Use the files below:
// listDriver.cpp
// Test driver
#include
#include
#include
#include
#include
#include \"unsorted.h\"
using namespace std;
void PrintList(ofstream& outFile, UnsortedType& list);
int main()
{
ifstream inFile; // file containing operations
ofstream outFile; // file containing output
string inFileName; // input file external name
string outFileName; // output file external name
string outputLabel;
string command; // operation to be executed
int number;
ItemType item;
UnsortedType list;
bool found;
int numCommands;
// Prompt for file names, read file names, and prepare files
cout << \"Enter name of input command file; press return.\" << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << \"Enter name of output file; press return.\" << endl;
cin >> outFileName;
outFile.open(outFileName.c_str());
cout << \"Enter name of test run; press return.\" << endl;
cin >> outputLabel;
outFile << outputLabel << endl;
if (!inFile)
{
cout << \"file not found\" << endl;
exit(2)
}
inFile >> command;
numCommands = 0;
while (command != \"Quit\")
{
if (command == \"PutItem\")
{
inFile >> number;
item.Initialize(number);
list.PutItem(item);
item.Print(outFile);
outFile << \" is in list\" << endl;
}
else if (command == \"DeleteItem\")
{
inFile >> number;
item.Initialize(number);
list.DeleteItem(item);
item.Print(outFile);
outFile << \" is deleted\" << endl;
}
else if (command == \"GetItem\")
{
inFile >> number;
item.Initialize(number);
item = list.GetItem(item, found);
item.Print(outFile);
if (found)
outFile << \" found in list.\" << endl;
else outFile << \" not in list.\" << endl;
}
else if (command == \"GetLength\")
outFile << \"Length is \" << list.GetLength() << endl;
else if (command == \"IsFull\")
if (list.IsFull())
outFile << \"List is full.\" << endl;
else outFile << \"List is not full.\" << endl;
else if (command == \"MakeEmpty\")
list.MakeEmpty();
else if (command == \"PrintList\")
PrintList(outFile, list);
else
cout << command << \" is not a valid command.\" << endl;
numCommands++;
cout << \" Command number \" << numCommands << \" completed.\"
<< endl;
inFile >> command;
};
cout << \"Testing completed.\" << endl;
inFile.close();
outFile.close();
return 0;
}
void PrintList(ofstream& dataFile, UnsortedType& list)
// Pre: list has been initialized.
// dataFile is open for writing.
// Post: Each component in list has been written to dataFile.
// dataFile is still open.
{
int length;
ItemType item;
list.ResetList();
length = list.GetLength();
for .
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
please follow all instructions and answer the inbedded questions, and written in C pls
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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'.
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 show the output. Thank
you!
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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.
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfsravi07
Written in C, requires linked lists. Please answer the 4 questions and show the output. Thank
you!
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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.
written in c- please answer the 4 questions and write the functions ba.pdfsravi07
written in c, please answer the 4 questions and write the functions based on the given code.
Thank you
// Write your name here
// 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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove a item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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];
switc.
-- Reminder that your file name is incredibly important- Please do not.docxAdamq0DJonese
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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 idNumber_input, add_result = 0;
char variety_input[20];
switch (c)
{
case 'a':
// input item record from user
printf("\nEnter item name: ").
In C pls -- Write your name here -- Write the compiler used- Visual st.docxBlake0FxCampbelld
In C pls
// Write your name here
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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 idNumber_input, add_result = 0;
char variety_input[20];
swi.
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
Please answer the 4 questions using C. The expected output is shown below. Thank you!
---------------------------------------------------------------------------------------------------
// Write your name here
// 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 list of game items
like you'd see in a folder.
// Each item has this information: item's name, game's name, type of item, item ID.
// The struct 'itemRecord' holds information of one item. Variety is an enum.
// An array of structs called 'list' is made 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 string library functions.
// WRITE COMMENTS FOR IMPORANT STEPS IN YOUR CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996) // for Visual Studio
Only
#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 list[MAX_ITEMS]; // declare list of items
int count = 0; // the number of items
currently stored in the list (initialized to 0)
// functions already implmented
void flushStdIn();
void executeAction(char);
void save(char* fileName);
void display();
// functions that need implementation:
int add(char* itemName_input,
char* gameName_input,
char* variety_input,
unsigned int idNumber_input); // 10 points
void sort(); // 10 points
int delete(unsigned int idNumber_input); // 10 points
void load(char* fileName); // 10 points
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 item\n");
printf("\t d: display item list\n");
printf("\t r: remove an item from list\n");
printf("\t s: sort item list by ID\n");
printf("\t q: quit\n");
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
.
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
Using the C++ programming language
1. Implement the UnsortedList class to store a list of numbers that are input into the list from
data.txt.
- create a main.cpp file that gets the numbers from the file
- insert the number 7 into the list
- insert another number 300 into the list
- delete the number 6 from the list
- print out the following:
--the entire list
- the greatest
- the least
2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file two called
outfile2.txt
Use the files below:
// listDriver.cpp
// Test driver
#include
#include
#include
#include
#include
#include \"unsorted.h\"
using namespace std;
void PrintList(ofstream& outFile, UnsortedType& list);
int main()
{
ifstream inFile; // file containing operations
ofstream outFile; // file containing output
string inFileName; // input file external name
string outFileName; // output file external name
string outputLabel;
string command; // operation to be executed
int number;
ItemType item;
UnsortedType list;
bool found;
int numCommands;
// Prompt for file names, read file names, and prepare files
cout << \"Enter name of input command file; press return.\" << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << \"Enter name of output file; press return.\" << endl;
cin >> outFileName;
outFile.open(outFileName.c_str());
cout << \"Enter name of test run; press return.\" << endl;
cin >> outputLabel;
outFile << outputLabel << endl;
if (!inFile)
{
cout << \"file not found\" << endl;
exit(2)
}
inFile >> command;
numCommands = 0;
while (command != \"Quit\")
{
if (command == \"PutItem\")
{
inFile >> number;
item.Initialize(number);
list.PutItem(item);
item.Print(outFile);
outFile << \" is in list\" << endl;
}
else if (command == \"DeleteItem\")
{
inFile >> number;
item.Initialize(number);
list.DeleteItem(item);
item.Print(outFile);
outFile << \" is deleted\" << endl;
}
else if (command == \"GetItem\")
{
inFile >> number;
item.Initialize(number);
item = list.GetItem(item, found);
item.Print(outFile);
if (found)
outFile << \" found in list.\" << endl;
else outFile << \" not in list.\" << endl;
}
else if (command == \"GetLength\")
outFile << \"Length is \" << list.GetLength() << endl;
else if (command == \"IsFull\")
if (list.IsFull())
outFile << \"List is full.\" << endl;
else outFile << \"List is not full.\" << endl;
else if (command == \"MakeEmpty\")
list.MakeEmpty();
else if (command == \"PrintList\")
PrintList(outFile, list);
else
cout << command << \" is not a valid command.\" << endl;
numCommands++;
cout << \" Command number \" << numCommands << \" completed.\"
<< endl;
inFile >> command;
};
cout << \"Testing completed.\" << endl;
inFile.close();
outFile.close();
return 0;
}
void PrintList(ofstream& dataFile, UnsortedType& list)
// Pre: list has been initialized.
// dataFile is open for writing.
// Post: Each component in list has been written to dataFile.
// dataFile is still open.
{
int length;
ItemType item;
list.ResetList();
length = list.GetLength();
for .
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfrajkumarm401
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header
file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list
functionality. The functions header file is also given. Complete the functions of the header file
linked_list.h below.
=========================================================
// listmain.cpp
#include \"Linked_List.h\"
int main(int argc, char **argv)
{
float f;
Linked_List *theList;
cout << \"Simple List Demonstration\ \";
cout << \"(List implemented as an Array - Do not try this at home)\ \ \";
cout << \"Create a list and add a few tasks to the list\";
theList = new Linked_List(); // Instantiate a list object
theList->Insert(5, 3.1f); // Note: The argument to the funtion should be a float
theList->Insert(1, 5.6f); // A constant real number like 3.1 is interpreted as
theList->Insert(3, 8.3f); // a double unless it is explicitly defined as a float
theList->Insert(2, 7.4f); // by adding an \'f\' to the end of the number.
theList->Insert(4, 2.5f);
// Show what is in the list
theList->PrintList();
// Test the list length function
cout << \"\ List now contains \" << theList->ListLength() << \"items.\ \ \";
// Test delete function
cout << \"Testing delete of last item in list.\ \";
theList->Delete(4);
theList->PrintList();
// Test delete function
cout << \"Testing delete of first item in list.\ \";
theList->Delete(5);
theList->PrintList();
// Test delete function
cout << \"Testing delete of a middle item in list.\ \";
theList->Delete(3);
theList->PrintList();
// Test delete function with a known failure argument
cout << \"Testing failure in delete function.\ \";
if(theList->Delete(4))
cout << \"Oops! Should not have been able to delete.\ \";
else
cout << \"Unable to locate item to delete.\ \";
// Test search (known failure)
cout << \"Testing Search function. Search for key 3\ \";
if(theList->Search(3, &f))
cout << \"Search result: theData = %f\ \", f;
else
cout << \"Search result: Unable to locate item in list\ \";
// Test search (known success)
cout << \"Testing Search function. Search for key 2\ \";
if(theList->Search(2, &f))
cout << \"Search result: theData = \" << f << \"\ \";
else
cout << \"Search result: Unable to locate item in list\ \";
cout << \"\ \ End list demonstration...\";
return 0;
}
=====================================================================
===================
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
ListItem *head; // Pointer to head of the list
public:
Linked_List(); // Class constructor
~Linked_List(); // Class destuctor
void ClearList(); // Remove all items from the list
bool Insert(int key, float f);// Add an item to the list
bool Delete(int key); // Delete an item from the list
bool Search(int key, float *retVal); // Search for an item in the list
int ListLength(); // Return numb.
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfakashenterprises93
All code should be in C++
Using the UnsortedList class (UnsortedList.h file below) write a function sublist which extracts
elements that are smaller than a given item from the given list and forms a new list. The
precondition of the function is: the list has been initialized and is not empty. The postconditions
are: newList contains all the items of the list whose values are less than the given item.
Implement the sublist function as a friend function of the UnsortedList class whose declaration
is:
friend void sublist(const UnsortedList& list,
const ItemType& item,
UnsortedList& newList);
(Hint: The UnsortedList class has private members
ItemType list[MAX_LENGTH];
int length;
and the member functions getLength, resetList, insert, remove, etc.)
//**********************************************************
// SPECIFICATION FILE (UnsortedList.h)
// This file gives the specification of a basic class
// template for unsorted array-based lists.
// The list components are not assumed to be in order by
// value.
//**********************************************************
#ifndef UNSORTEDLIST_H
#define UNSORTEDLIST_H
#include
#include // Needed for the exit function
using namespace std;
const int MAX_LENGTH = 100; // Maximum number of components
template // You may also choose to use
// typedef statement
class UnsortedList
{
public:
// Constructor
UnsortedList();
// Post: Empty list has been created. length has been set to zero.
// Knowledge responsibilities
int getLength() const;
// Post: Returns the length of the list
bool isEmpty() const;
// Post: Returns true if list is empty; false otherwise
bool isFull() const;
// Post: Returns true if list is full; false otherwise
bool isInList(const ItemType& item) const;
// Post: Returns true if item is int the list; false otherwise
int seqSearch(const ItemType& item) const;
// Function to search the list for a given item.
// Post: If item is found, returns the index in the array where
// item is found; otherwise, return -1.
// Action Responsibilities
void resetList();
// Post: The list becomes empty. length has been set to zero.
void insert(const ItemType& item);
// Function to insert item to the end of the list. However, first
// the list is searched to see whether the item to be inserted is
// already in the list.
// Post: list[length] = item and length++. If item is already in
// the list or the list is already full, an appropriate message is
// displayed.
void remove(const ItemType& item);
// Function to remove item from the list.
// Post: If item is found in the list, it is removed from the list
// and length is decremented by one.
// Overloaded [] operator declaration.
// This function returns a reference to the element in the
// array indexed by index.
ItemType& operator[](const int& index);
// Additional operations
void sort();
// Post: list items have been put into ascending order by selection sort
void selectionSort();
// Function to sort the items in the list.
// Post: list items have been put int.
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
C++ problem
Part 1: Recursive Print (40 pts)
Please write the recursive List reverse print function, whose iterative version we wrote in class.
Below are the function signatures for the functions you are going to need:
public:
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
private:
void reverse(Nodeptr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
Why do we need the private helper function here?
Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass
a one node at a time to our reverse function.
However, since our nodes are private, we cannot access them if we call the function inside of
main.
Add these function signatures to your List.h file along with your other function prototypes inside
the class definition.
Make sure that you place the reverse function inside the private portion of your List class
definition and the print_reverse function prototype to the public portion of your List class
definition.
Now, implement these two functions inside of List.h, under your section for additional
operations.
Important: Test each function carefully inside of your ListTest.cpp to make sure that it is
working properly.
Part 2: Adding an Index to Your List Nodes (20 pts)
Next, you will add the following functions to your List.h
/**Accessor Functions*/
int get_index();
//Indicates the index of the Node where the iterator is currently pointing
//Nodes are numbered from 1 to length of the list
//Pre: length != 0
//Pre: !off_end()
...
int List::get_index()
{
//Implement the function here
}
/**Manipulation Procedures*/
void scroll_to_index(int index);
//Moves the iterator to the node whose index is specified by the user
//Pre: length != 0
...
void scroll_to_index(int index)
{
//Implement function here
}
Part 3: Implementing Search as Part of Your List (40 pts)
Now, we are going to add two search functions to our List so that we can search for elements in
our List.
The first of these functions is going to be a simple linear search function.
You will need to add the following function prototype and function definition to your List.h:
/**Additional Operations*/
int linear_search(listitem item);
//Searchs the list, element by element, from the start of the List to the end of the List
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
...
int List::linear_search(listitem item)
{
//Implement the function here
}
You are also going to add a function to perform recursive binary search on your List.
You will need to add the following function prototype and function definition to your List.h:
int binary_search(int low, int high, listitem item);
//Recursively searchs the list by dividing the search space in half
//Returns the index of the element, if it is fo.
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
Background:
In many applications, the composition of a collection of data items changes over time. Not only
are new data items added and existing ones removed, but data items may be duplicated. A list
data structure is a member of the general category of abstract data types called containers, whose
purpose is to hold other objects. In C++, lists are provided in the Standard Template Library.
However, for this assignment you will design and write your own linked list implementation to
support the ADT operations specified below.
Objective:
Design and implement the specifications for a List Abstract Data Type where the items in the list
are unsorted.
Requirements:
Define a list and develop a set of operations for creating and manipulating a list that satisfies the
list ADT specification.
List ADT Specification
Structure: The list elements are of ItemType. The list has a property called the current position
which designates the position of the last element accessed by GetNextItem during an iteration
through the list. Only ResetList and GetNextItem alter the current position.
Definitions (provided by the user):
MAX_ITEMS: A constant specifying the maximum capacity of items allowed on the list
Item Type: Class encapsulating the type of items in the list
RelationType: An enumeration type that consists of LESS, GREATER, EQUAL
Member function of ItemType that must be included:
RelationType ComparedTo(ItemType Item)
Function: Determines the ordering of two ItemType objects based on their keys
Precondition: Self and item have their key members initialized
Postcondition:
Function value = LESS if the key of self is less than the key of item
= GREATER if the key of self is greater than the key of item
= EQUAL if the keys are equal
Operations (provided by Unsorted List ADT)
Make Empty
Function: Initializes list to empty state
Preconditions: None
Postcondition: List is empty
Boolean IsFull
Function: Determines whether list is full
Preconditions: List has been initialized
Postcondition: Function value = (list is full)
int GetLength
Function: Determines the number of elements in list
Preconditions: List has been initialized
Postcondition: Function value = number of elements in list
ItemType GetItem(Item Typeitem, Boolean& found)
Function: Get list element whose key matches item’s key (if present)
Preconditions: List has been initialized
Key member of item is initialized
Postcondition: If there is an element someItem whose keymatches item’s key, then found =
true and copy of someItemis returned; otherwise found = false and item is returned
List is unchanged
PutItem(ItemType item)
Function: Puts item into list
Preconditions: List has been initialized
List is not full
Item is not in list
Postcondition: Item is in the list
DeleteItem(ItemType item)
Function: Deletes the element whose key matches item’s key
Preconditions: List has been initialized
Postcondition: One and only one element in list has a key matching item’s key
ResetList
Function: Initializes current p.
a) Complete both insert and delete methods. If it works correctly 10.pdfMAYANKBANSAL1981
a) Complete both insert and delete methods. If it works correctly 100 points each.
b) Do not call the search method in delete method.
c) Make sure to write your name in main method.
d) DO NOT MODIFY PROCESS METHOD.
3- Create a proper input file with respect to process method to test all cases in both
insert and delete methods.
4- Compile and execute your program at the command prompt. Check your output, if it
is correct
//xxxxxH5.java is linked list implementation of lstinterface.
//Eliminate count form both insert and delete methods
// If works correctly, 200 points
import java.util.*;
import java.io.*;
//lstinterface is an interface
public class xxxxxH5 implements lstinterface {
// xxxxxH5 class variables
//head is a pointer to beginning of linked list
private node head = null;
//use prt for System.out to save typing
PrintStream prt = System.out;
// class node
private class node{
// class node variables
int data;
node rlink; //right link
// class node constructor
node(int x){
data = x;
rlink = null;
} // end class node constructor
}// class node
// insert x at position p,
// if successful return 1 otherwise return 0
public int insert(int x, int p){
prt.printf("\n\t\tInsert %5d at position %2d:", x, p);
// complete this method
return 0; // successful insertion
} // end insert
// delete x at position p
// if successful return 1 otherwise return 0
public int delete(int p){
prt.printf("\n\t\tDelete element at position %2d:", p);
// complete this method
return 0; // successful insertion
} // end delete
// sequential serach for x in the list
// if successful return its position otherwise return 0;
public int search(int x){
// Local variables
node cur;
prt.printf("\n\t\tSearch for %5d:", x);
// Complete the rest of the method
int pos = 0;
for (cur = head; cur != null ; cur = cur.rlink){
pos ++;
if (cur.data == x){
prt.printf(" Found at position %2d, ", pos);
return pos;
} // end if
} // end for
prt.printf(" Not Found.");
return 0; // x is not found.
} // end search
// print list elements formatted
public void printlst() {
// Local variables
node cur;
prt.printf("\n\tList contents: ");
for (cur = head; cur != null ; cur = cur.rlink)
prt.printf("%5d,", cur.data);
// end for
} // end printlst
// insert delete and search in the list
private void process(String fn){
// Local variables
int j, ins, del, srch, k, p;
int x;
prt.printf("\tLinked List implementation of int list without"+
//\n\tusing count, gets input file name from method argument, then
reads:"+
"\n\tinteger No. of elements to insert(ins)"+
" followed by elements to insert and their positions,"+
"\n\tinteger No. of elements to search(srch) followed by element to
search"+
"\n\tinteger No. of elements to delete(del) followed by position of"+
"elements to delete" +
"\n\t\tTo compile: javac xxxxxH5.java" +
"\n\t\tTo execute: java xxxxxH5 inputfilename");
try{
// open input file
Scanner inf = new Scanner(new File(fn));
//read no. of elements to insert
ins = inf.nextInt();
prt.printf("\n\tInsert %.
(Unordered Sets) As explained in this chapter, a set is a collection.pdfssuserc77a341
(Unordered Sets) As explained in this chapter, a set is a collection of distinct elements of the
same type. Design the class unorderedSetType, derived from the class unorderedArrayListType,
to manipulate sets. Note that you need to redefine only the functions insertAt, insertEnd, and
replaceAt. If the item to be inserted is already in the list, the functions insertAt and insertEnd
output an appropriate message. Similarly, if the item to be replaced is already in the list, the
function replaceAt outputs an appropriate message.Include the set operations of union and
intersection in your class. Also write a program to test your class. (C++)
#ifndef UNORDEREDARRAYLISTTYPE_H
#define UNORDEREDARRAYLISTTYPE_H
#include \"arrayListType.h\"
class unorderedArrayListType : public arrayListType {
public:
void insertAt(int location, int insertItem);
// Function to insert an item at a particular location
// Postcondition: The item has been added to the list and the length has
// been increased by 1.
void insertEnd(int insertItem);
// Function to insert an item at the end of the list
// Postcondition: The item has been added at the end of the list and the
// length has been increased by 1.
void replaceAt(int location, int repItem);
// Function to replace an item in the list.
// Postcondition: repItem overrwrites the item at the specified location
// in the list. The length of the list is unchanged.
int seqSearch(int searchItem) const;
// Function to search the list for searchItem. Note that this is an
// abstract function.
//Postcondition: If the item is found, returns the location in the array
// where the item is found; otherwise, returns -1.
void remove(int removeItem);
// Function to remove an item from the list
// Postcondition: If the item is found in the list, it is removed and the
// length of the list is decreased by 1; if the item is not in the list
// an appropriate message is displayed.
void removeAll(int removeItem);
// Function to remove all occurrences of an item from the list
// Postcondition: If the item is found in the the list, all occurrences are
// removed and the length of the list is decreased accordingly. If the
// item is not in the list an appropriate message is displayed.
unorderedArrayListType(int size = 100);
//Constructor.
};
#endif // UNORDEREDARRAYLISTTYPE_H
#include \"UnorderedArrayListType.h\"
#include
using namespace std;
void unorderedArrayListType::insertAt(int location,
int insertItem) {
if (location < 0 || location >= maxSize)
cout<<\"The position of the item to be inserted is out of range.\"<= maxSize) //list is full
cout << \"Cannot insert in a full list\" << endl;
else {
for (int i = length; i > location; i--)
list[i] = list[i - 1]; //move the elements down
list[location] = insertItem; //insert the item at the specified position
length++; //increment the length
}
} //end insertAt
void unorderedArrayListType::insertEnd(int insertItem) {
if (length >= maxSize) //the list is full
cout << \"Cannot insert in a full list.\.
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
Complete a C++ class implementation for a linked-list of sorted (ascending) positive integers.
The class name for this class is LLSortedPosInt and its specification is outlined in the file
LLSortedPosInt.h. The specification is accompained by two other files: (1) a partial
implementation of the class in the file LLSortedPosInt.cpp and (2) a test program called
testLL.cpp. You are to complete the partial implementation of the class by writing code for the
stubbed member functions. You may NOT make any changes to the specification file. You may
develop and test your class implementation either under Visual Studio or linux; however, your
program must be executable under linux, because that is where it will be tested.
Details: Linked lists are useful data structures for storing data records, particularly in situations
where the items are to be kept sorted, the number of records are dynamic (i.e., changing during
the course of the program’s execution) and the maximum number is arbitrary. In this exercise,
you’ll get a chance to complete the implementation of a linked-list specification. In doing so,
you’ll learn not only how to manipulate pointer objects, but also begin to learn how to create a
new and useful data type.
To get started, I have written a simple linked list definition within the header file called
LLSortedPosInt.h. My definition is, of course, not the only way to define a linked list, but it is
suitable for our simple project. Accompanying the definition is a partial implementation in the
source file LLSortedPosInt.cpp. You are to edit this file using the comments in the file and the
instructions below. Altogether, this assignment asks you to implement 13 functions.
To help with testing your functions implementations, I have provided a main program. This main
program is in the source file testLL.cpp. One quick way to repeatedly exercise your function
tests is to write a test file (I called mine testCases.txt) and use input re-direction.
The 13 functions you must add to complete the implementation are as follows:
a. Constructors (4): Classes must have constructors to initialize instances of the objects. The
constructors you will implement for this project are
i. A default constructor
ii. A constructor taking a single int parameter
iii. A constructor which builds a list from an array of integers
iv. A copy constructor
b. Destructor (1): Because the class specification includes a pointer among the attributes, you
will need to implement a destructor to delete (i.e., free or release) any storage allocated in the
constructors or other member functions.
c. Boolean Functions (2): You are to implement two Boolean functions
i. A function isEmpty() which returns true if the associated list contains no data elements,
and returns false otherwise.
ii. A function containsElement(key) which returns true is key is an element in the list and
returns false otherwise.
d. Member Operator Functions (3): When a class has a pointer among its attributes, as
.
Implement the following specification of UnsortedType using circular.pdfudit652068
Implement the following specification of UnsortedType using circular linked list as the
implementation structure.
*** I have seen this question answered here before but it is not a good answer. Can someone
please give me a original answer.***
// Deliverables:
// - A listing of the specification and implementation files for UnsortedType
// - A listing of the driver program for your test plan
// - A listing of the test plan as input to the driver.
// - A listing of the output from the driver.
template
struct NodeType;
/* Assumption: ItemType is a type for which the operators
\"<\" and \"==\" are defined-either an appropriate built-in type or a
class that overloads these operators. */
template
class UnsortedType
{
public:
// Class constructor, destructor, and copy constructor
UnsortedType();
~UnsortedType();
UnsortedType(const UnsortedType&);
void operator=(UnsortedType);
bool IsFull() const;
// Determines whether list is full.
//Post: Function value = (list is full)
int GetLength() const;
// Determines the number of elements in list.
// Post: Function value = number of elements in list.
void RetrieveItem(ItemType& item, bool& found);
// Retrieves list element whose key matches item\'s key
// (if present).
// Pre: Key member of item is initialized.
// Post: If there is an element someItem whose key matches
// item\'s key, then found = true and item is a copy of
// someItem; otherwise found = false and item is unchanged.
// List is unchanged.
void InsertItem(ItemType item);
// Adds item to list.
// Pre: List is not full.
// Item is not in list.
// Post: item is in list.
void DeleteItem(ItemType item);
// Deletes the element whose key matches item\'s key
// Pre: Key member of item is initialized.
// One and only one element in list has a key matching
// item\'s key.
// Post: No element in list has a key matching item\'s key.
void ResetList();
// Initializes current position for an iteration through the list.
// Post: Current position is prior to list.
void GetNextItem(ItemType&);
// Gets the next element in list.
// Pre: Current position is defined.
// Element at current position is not last in list.
// Post: Current position is updated to next position.
// item is a copy of element at current position.
private:
NodeType* listData;
int length;
NodeType* currentPos;
};
Solution
#include
#include
/* structure for a node */
struct node
{
int data;
struct node *next;
};
/* function to insert a new_node in a list in sorted way.
Note that this function expects a pointer to head node
as this can modify the head of the input linked list */
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current = *head_ref;
// Case 1 of the above algo
if (current == NULL)
{
new_node->next = new_node;
*head_ref = new_node;
}
// Case 2 of the above algo
else if (current->data >= new_node->data)
{
/* If value is smaller than head\'s value then
we need to change next of last node */
while(current->next != *head_ref)
current = current->next;
cur.
In C++Add the function min as an abstract function to the classar.pdffantoosh1
In C++:
Add the function min as an abstract function to the classarrayListTypeto return the smallest
element of the list.
Also, write the definition of the function min in the classunorderedArrayListTypeand write a
program to test this function.
arrayListType.h
#ifndef H_arrayListType
#define H_arrayListType
class arrayListType
{
public:
bool isEmpty() const;
//Function to determine whether the list is empty
//Postcondition: Returns true if the list is empty;
// otherwise, returns false.
bool isFull() const;
//Function to determine whether the list is full
//Postcondition: Returns true if the list is full;
// otherwise, returns false.
int listSize() const;
//Function to determine the number of elements in
//the list.
//Postcondition: Returns the value of length.
int maxListSize() const;
//Function to determine the maximum size of the list
//Postcondition: Returns the value of maxSize.
void print() const;
//Function to output the elements of the list
//Postcondition: Elements of the list are output on the
// standard output device.
bool isItemAtEqual(int location, int item) const;
//Function to determine whether item is the same as
//the item in the list at the position specified
//by location.
//Postcondition: Returns true if list[location]
// is the same as item; otherwise,
// returns false.
// If location is out of range, an
// appropriate message is displayed.
virtual void insertAt(int location, int insertItem) = 0;
//Function to insert insertItem in the list at the
//position specified by location.
//Note that this is an abstract function.
//Postcondition: Starting at location, the elements of
// the list are shifted down,
// list[location] = insertItem; length++;
// If the list is full or location is out of
// range, an appropriate message is displayed.
virtual void insertEnd(int insertItem) = 0;
//Function to insert insertItem at the end of
//the list. Note that this is an abstract function.
//Postcondition: list[length] = insertItem; and length++;
// If the list is full, an appropriate
// message is displayed.
void removeAt(int location);
//Function to remove the item from the list at the
//position specified by location
//Postcondition: The list element at list[location] is
// removed and length is decremented by 1.
// If location is out of range, an
// appropriate message is displayed.
void retrieveAt(int location, int& retItem) const;
//Function to retrieve the element from the list at the
//position specified by location
//Postcondition: retItem = list[location]
// If location is out of range, an
// appropriate message is displayed.
virtual void replaceAt(int location, int repItem) = 0;
//Function to replace the elements in the list
//at the position specified by location.
//Note that this is an abstract function.
//Postcondition: list[location] = repItem
// If location is out of range, an
// appropriate message is displayed.
void clearList();
//Function to remove all the elements from the list
//After this operation, the size of t.
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
Use the graph of the function f below to find the following. All local minimum values of f All
values at which f has a local minimum If there is more than one answer, separate them with
commas. All local minimum values of f All values at which f has a local minimum:
Solution
Dear student
Thank you for using Chegg
As per the given curve it is clear that the local minimum values of f are -3 & 0
Values of x when curve attain minimum values are x = -2,3.
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
please i need help I\'m writing a program to test the merge sort algorithm for linked lists.
I need to Print the list before being sorted and the list after sorting the elements
here is my code only help in test program the four classes are ok except the test program.
TEST PROGRAM
import java.io.*;
import java.util.*;
public class Ch9_ProgExercise7 {
Scanner input = new Scanner(System.in);
public static void main(String[] args) throws IOException {
OrderedLinkedList list
= new OrderedLinkedList(); //Line 1
IntElement num = new IntElement(); //Line 2
// Prompt the user to enter some integers
System.out.println(\"Enter integers numbers \");
String temp = input.hasnextLine();
String[] split = temp.split(\" \");
for (int i = 0; i < split.length; i++) {
Integer a = Integer.parseInt(split[i]);
// insert the intgers into the list you created above
num.setNum(a);
list.insertNode(num);
}
System.out.println();
// Print the list before being sorted
// call the mergesort method
System.out.println();
// print the list after sorting the elements
}
}
ORDEREDLICKEDLIST CLASS
public class OrderedLinkedList extends LinkedListClass
{
//default constructor
public OrderedLinkedList()
{
super();
}
//copy constructor
public OrderedLinkedList(OrderedLinkedList otherList)
{
super(otherList);
}
public void linkedInsertionSort()
{
LinkedListNode lastInOrder;
LinkedListNode firstOutOfOrder;
LinkedListNode current;
LinkedListNode trailCurrent;
lastInOrder = first;
if(first == null)
System.out.println(\"Cannot sort an empty list\");
else
if(first.link == null)
System.out.println(\"The list is of length 1. \"
+ \"Already in order\");
else
while(lastInOrder.link != null)
{
firstOutOfOrder = lastInOrder.link;
if(firstOutOfOrder.info.compareTo(first.info) < 0)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = first;
first = firstOutOfOrder;
}
else
{
trailCurrent = first;
current = first.link;
while(current.info.compareTo(firstOutOfOrder.info) < 0)
{
trailCurrent = current;
current = current.link;
}
if(current != firstOutOfOrder)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = current;
trailCurrent.link = firstOutOfOrder;
}
else
lastInOrder = lastInOrder.link;
}
}
}//end linkedInsertionSort
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; otherwise, it returns
// false.
public boolean search(DataElement searchItem)
{
LinkedListNode current; //variable to traverse the list
boolean found;
current = first; //set current to point to the first
//node in the list
found = false; //set found to false
while(current != null && !found ) //search the list
if(current.info.compareTo(searchItem) >= 0)
found = true;
else
current = current.link; //make current point to
//the next node
if(found)
found = current.info.equals(searchItem);
return found;
}
//Method to insert insertItem in the list
//Postcondition: first points to the new list,
// newItem is inserted at the proper place
//.
please help me in C++Objective Create a singly linked list of num.pdfaminbijal86
please help me in C++
Objective: Create a singly linked list of numbers based upon user input.
Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat
until they enter -1 for the number. .
Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10
Solution
#include
#include
using namespace std;
// It contains the value and the pointer to the next element in the list.
struct element {
int value;
struct element *next;
};
struct element *head = NULL;
// The list is stored in the object of this class.
class linkedlist {
public:
// To display list, we first see if head is NULL,
// If head is NULL it means the list is empty.
// Then we traverse along the list and display each item, until the next pointer is NULL.
void display() {
if(head == NULL){
cout << \"The list is empty\ \";
} else {
struct element *temp;
temp = head;
while(temp != NULL){
cout << temp->value << \" \" ;
temp = temp->next;
}
cout << \"\ \";
}
}
// To add an element to the list,create a newElement and store the value.
// If head is NULL, add the newElement to the head.
// To add an element at the starting of the list.
// The next pointer of the newElement must point to the old head.
// The new head must be pointed to the newElement.
void add(int a){
struct element *newElement;
newElement = (struct element *)malloc(sizeof(struct element));
newElement->value = a;
newElement->next = NULL;
if(head == NULL) {
head = newElement;
} else {
newElement->next = head;
head = newElement;
}
}
};
int main()
{
// Create an object of the class linkedlist.
linkedlist l = linkedlist();
int a;
do {
cout << \"Enter a number : \";
cin >> a;
if(a!=-1) { // If the number is -1 do not add it to the list.
l.add(a); // Add the number to the list.
}
l.display(); // Display the list.
} while(a!=-1); // Keep asking for a number until -1 is pressed.
return 0;
}.
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdfganisyedtrd
[-12 Points] DEVORESTATS 2.5.074 . Suppose thut the proportions of blood phenotypes in a
panticular poputation are as follows: What in the ponshability that the phenotypes of two
randomiy silected individgals matoh? (Enter your antwer to four secimal places.).
--import statemnts for Random- Scanner and IO import java-util-Random-.pdfganisyedtrd
//import statemnts for Random, Scanner and IO
import java.util.Random;
import java.util.Scanner;
import java.io.*;
public class Hobbits
{
public static void main(String[] args) throws IOException
{
final int NUM_HOBBITS = 5;
final int NUM_COLUMNS = 2;
String fileName = "hobbits.csv";
//call populateHobbits( ) to create the two dimensional array
double[][] hobbits = populateHobbits(NUM_HOBBITS, NUM_COLUMNS);
//display the number of hobbits
System.out.println(hobbits.length + " hobbits accepted Gandalf's invitation to lunch\n");
//calculate the means of the columns
double[] hobbitMeans = getColMeans(hobbits);
//write hobbits array to file
writeHobbits(hobbits, fileName);
//read and display the file that has been read
readHobbitses(fileName);
//call displayColMeans to display hobbit means
displayColMeans(hobbitMeans);
}
//method to populate hobbits array with random double values
public static double[][] populateHobbits(int numHobbits, int numCols)
{
final double HT_MULTIPLIER = 10.0; //multiplier for the hobbit height
final double WT_MULTIPLIER = 250.0; //multiplier for the hobbit weight
//instantiate Random object
Random rand = new Random();
//declare two dim array with numHobbits rows numCols columns
double[][] hobbitArray = new double[numHobbits][numCols];
//assign random double values to all elements
for (int i = 0; i < numHobbits; i++) //outer loop is for rows
{
for (int j = 0; j < numCols; j++) //inner loop is for columns
{
//get a random double value in range [0.2, 0.4]
double randDouble = getRandDouble(rand);
//assign this double to the current array element
hobbitArray[i][j] = randDouble;
//determine which multiplier to use
if (j == 0) //this is column for height
hobbitArray[i][j] *= HI_MULTIPLIER;
else //this is column for weight
hobbitArray[i][j] *= WT_MULTIPLIER;
}
}
return hobbitArray; //return the two dimensional array
}
//method to write hobbits array to file
public static void writeHobbits(double[][] ar, String fileName) throws IOException
{
//open the file to write
PrintWriter outFile = new PrintWriter(fileName);
//print columen heading of the array of stats
outFile.println("HEIGHT,WEIGHT");
for (int i = 0; i < ar.length; i++)
{
for (int j = 0; j < ar[i].length; j++)
{
outFile.print(ar[i][j]);
//if at end of a row, add newline char
if (j == ar[i].length - 1)
outFile.print("\n");
else //add the "," delimiter
outFile.print(",");
} //end of inner loop
} //end of outer loop
outFile.close(); //close outfile
System.out.println("The file was successfully written\n");
} //end of method
//method to read the hobbits file
public static void readHobbitses(String fileName) throws IOException {
//open the file to read
File dataFile = new File(fileName);
Scanner inFile = new Scanner(dataFile);
//variable to contain the substrings of one line of file
String[] oneLine = new String[2];
int counter = 0; //keep track of line numbers
System.out.println("Data read from the " + fileName + " file:");
//read file, one line at a time
while (inFile.hasNe.
More Related Content
Similar to -- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfrajkumarm401
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header
file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list
functionality. The functions header file is also given. Complete the functions of the header file
linked_list.h below.
=========================================================
// listmain.cpp
#include \"Linked_List.h\"
int main(int argc, char **argv)
{
float f;
Linked_List *theList;
cout << \"Simple List Demonstration\ \";
cout << \"(List implemented as an Array - Do not try this at home)\ \ \";
cout << \"Create a list and add a few tasks to the list\";
theList = new Linked_List(); // Instantiate a list object
theList->Insert(5, 3.1f); // Note: The argument to the funtion should be a float
theList->Insert(1, 5.6f); // A constant real number like 3.1 is interpreted as
theList->Insert(3, 8.3f); // a double unless it is explicitly defined as a float
theList->Insert(2, 7.4f); // by adding an \'f\' to the end of the number.
theList->Insert(4, 2.5f);
// Show what is in the list
theList->PrintList();
// Test the list length function
cout << \"\ List now contains \" << theList->ListLength() << \"items.\ \ \";
// Test delete function
cout << \"Testing delete of last item in list.\ \";
theList->Delete(4);
theList->PrintList();
// Test delete function
cout << \"Testing delete of first item in list.\ \";
theList->Delete(5);
theList->PrintList();
// Test delete function
cout << \"Testing delete of a middle item in list.\ \";
theList->Delete(3);
theList->PrintList();
// Test delete function with a known failure argument
cout << \"Testing failure in delete function.\ \";
if(theList->Delete(4))
cout << \"Oops! Should not have been able to delete.\ \";
else
cout << \"Unable to locate item to delete.\ \";
// Test search (known failure)
cout << \"Testing Search function. Search for key 3\ \";
if(theList->Search(3, &f))
cout << \"Search result: theData = %f\ \", f;
else
cout << \"Search result: Unable to locate item in list\ \";
// Test search (known success)
cout << \"Testing Search function. Search for key 2\ \";
if(theList->Search(2, &f))
cout << \"Search result: theData = \" << f << \"\ \";
else
cout << \"Search result: Unable to locate item in list\ \";
cout << \"\ \ End list demonstration...\";
return 0;
}
=====================================================================
===================
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
ListItem *head; // Pointer to head of the list
public:
Linked_List(); // Class constructor
~Linked_List(); // Class destuctor
void ClearList(); // Remove all items from the list
bool Insert(int key, float f);// Add an item to the list
bool Delete(int key); // Delete an item from the list
bool Search(int key, float *retVal); // Search for an item in the list
int ListLength(); // Return numb.
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfakashenterprises93
All code should be in C++
Using the UnsortedList class (UnsortedList.h file below) write a function sublist which extracts
elements that are smaller than a given item from the given list and forms a new list. The
precondition of the function is: the list has been initialized and is not empty. The postconditions
are: newList contains all the items of the list whose values are less than the given item.
Implement the sublist function as a friend function of the UnsortedList class whose declaration
is:
friend void sublist(const UnsortedList& list,
const ItemType& item,
UnsortedList& newList);
(Hint: The UnsortedList class has private members
ItemType list[MAX_LENGTH];
int length;
and the member functions getLength, resetList, insert, remove, etc.)
//**********************************************************
// SPECIFICATION FILE (UnsortedList.h)
// This file gives the specification of a basic class
// template for unsorted array-based lists.
// The list components are not assumed to be in order by
// value.
//**********************************************************
#ifndef UNSORTEDLIST_H
#define UNSORTEDLIST_H
#include
#include // Needed for the exit function
using namespace std;
const int MAX_LENGTH = 100; // Maximum number of components
template // You may also choose to use
// typedef statement
class UnsortedList
{
public:
// Constructor
UnsortedList();
// Post: Empty list has been created. length has been set to zero.
// Knowledge responsibilities
int getLength() const;
// Post: Returns the length of the list
bool isEmpty() const;
// Post: Returns true if list is empty; false otherwise
bool isFull() const;
// Post: Returns true if list is full; false otherwise
bool isInList(const ItemType& item) const;
// Post: Returns true if item is int the list; false otherwise
int seqSearch(const ItemType& item) const;
// Function to search the list for a given item.
// Post: If item is found, returns the index in the array where
// item is found; otherwise, return -1.
// Action Responsibilities
void resetList();
// Post: The list becomes empty. length has been set to zero.
void insert(const ItemType& item);
// Function to insert item to the end of the list. However, first
// the list is searched to see whether the item to be inserted is
// already in the list.
// Post: list[length] = item and length++. If item is already in
// the list or the list is already full, an appropriate message is
// displayed.
void remove(const ItemType& item);
// Function to remove item from the list.
// Post: If item is found in the list, it is removed from the list
// and length is decremented by one.
// Overloaded [] operator declaration.
// This function returns a reference to the element in the
// array indexed by index.
ItemType& operator[](const int& index);
// Additional operations
void sort();
// Post: list items have been put into ascending order by selection sort
void selectionSort();
// Function to sort the items in the list.
// Post: list items have been put int.
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
C++ problem
Part 1: Recursive Print (40 pts)
Please write the recursive List reverse print function, whose iterative version we wrote in class.
Below are the function signatures for the functions you are going to need:
public:
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
private:
void reverse(Nodeptr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
Why do we need the private helper function here?
Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass
a one node at a time to our reverse function.
However, since our nodes are private, we cannot access them if we call the function inside of
main.
Add these function signatures to your List.h file along with your other function prototypes inside
the class definition.
Make sure that you place the reverse function inside the private portion of your List class
definition and the print_reverse function prototype to the public portion of your List class
definition.
Now, implement these two functions inside of List.h, under your section for additional
operations.
Important: Test each function carefully inside of your ListTest.cpp to make sure that it is
working properly.
Part 2: Adding an Index to Your List Nodes (20 pts)
Next, you will add the following functions to your List.h
/**Accessor Functions*/
int get_index();
//Indicates the index of the Node where the iterator is currently pointing
//Nodes are numbered from 1 to length of the list
//Pre: length != 0
//Pre: !off_end()
...
int List::get_index()
{
//Implement the function here
}
/**Manipulation Procedures*/
void scroll_to_index(int index);
//Moves the iterator to the node whose index is specified by the user
//Pre: length != 0
...
void scroll_to_index(int index)
{
//Implement function here
}
Part 3: Implementing Search as Part of Your List (40 pts)
Now, we are going to add two search functions to our List so that we can search for elements in
our List.
The first of these functions is going to be a simple linear search function.
You will need to add the following function prototype and function definition to your List.h:
/**Additional Operations*/
int linear_search(listitem item);
//Searchs the list, element by element, from the start of the List to the end of the List
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
...
int List::linear_search(listitem item)
{
//Implement the function here
}
You are also going to add a function to perform recursive binary search on your List.
You will need to add the following function prototype and function definition to your List.h:
int binary_search(int low, int high, listitem item);
//Recursively searchs the list by dividing the search space in half
//Returns the index of the element, if it is fo.
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
Background:
In many applications, the composition of a collection of data items changes over time. Not only
are new data items added and existing ones removed, but data items may be duplicated. A list
data structure is a member of the general category of abstract data types called containers, whose
purpose is to hold other objects. In C++, lists are provided in the Standard Template Library.
However, for this assignment you will design and write your own linked list implementation to
support the ADT operations specified below.
Objective:
Design and implement the specifications for a List Abstract Data Type where the items in the list
are unsorted.
Requirements:
Define a list and develop a set of operations for creating and manipulating a list that satisfies the
list ADT specification.
List ADT Specification
Structure: The list elements are of ItemType. The list has a property called the current position
which designates the position of the last element accessed by GetNextItem during an iteration
through the list. Only ResetList and GetNextItem alter the current position.
Definitions (provided by the user):
MAX_ITEMS: A constant specifying the maximum capacity of items allowed on the list
Item Type: Class encapsulating the type of items in the list
RelationType: An enumeration type that consists of LESS, GREATER, EQUAL
Member function of ItemType that must be included:
RelationType ComparedTo(ItemType Item)
Function: Determines the ordering of two ItemType objects based on their keys
Precondition: Self and item have their key members initialized
Postcondition:
Function value = LESS if the key of self is less than the key of item
= GREATER if the key of self is greater than the key of item
= EQUAL if the keys are equal
Operations (provided by Unsorted List ADT)
Make Empty
Function: Initializes list to empty state
Preconditions: None
Postcondition: List is empty
Boolean IsFull
Function: Determines whether list is full
Preconditions: List has been initialized
Postcondition: Function value = (list is full)
int GetLength
Function: Determines the number of elements in list
Preconditions: List has been initialized
Postcondition: Function value = number of elements in list
ItemType GetItem(Item Typeitem, Boolean& found)
Function: Get list element whose key matches item’s key (if present)
Preconditions: List has been initialized
Key member of item is initialized
Postcondition: If there is an element someItem whose keymatches item’s key, then found =
true and copy of someItemis returned; otherwise found = false and item is returned
List is unchanged
PutItem(ItemType item)
Function: Puts item into list
Preconditions: List has been initialized
List is not full
Item is not in list
Postcondition: Item is in the list
DeleteItem(ItemType item)
Function: Deletes the element whose key matches item’s key
Preconditions: List has been initialized
Postcondition: One and only one element in list has a key matching item’s key
ResetList
Function: Initializes current p.
a) Complete both insert and delete methods. If it works correctly 10.pdfMAYANKBANSAL1981
a) Complete both insert and delete methods. If it works correctly 100 points each.
b) Do not call the search method in delete method.
c) Make sure to write your name in main method.
d) DO NOT MODIFY PROCESS METHOD.
3- Create a proper input file with respect to process method to test all cases in both
insert and delete methods.
4- Compile and execute your program at the command prompt. Check your output, if it
is correct
//xxxxxH5.java is linked list implementation of lstinterface.
//Eliminate count form both insert and delete methods
// If works correctly, 200 points
import java.util.*;
import java.io.*;
//lstinterface is an interface
public class xxxxxH5 implements lstinterface {
// xxxxxH5 class variables
//head is a pointer to beginning of linked list
private node head = null;
//use prt for System.out to save typing
PrintStream prt = System.out;
// class node
private class node{
// class node variables
int data;
node rlink; //right link
// class node constructor
node(int x){
data = x;
rlink = null;
} // end class node constructor
}// class node
// insert x at position p,
// if successful return 1 otherwise return 0
public int insert(int x, int p){
prt.printf("\n\t\tInsert %5d at position %2d:", x, p);
// complete this method
return 0; // successful insertion
} // end insert
// delete x at position p
// if successful return 1 otherwise return 0
public int delete(int p){
prt.printf("\n\t\tDelete element at position %2d:", p);
// complete this method
return 0; // successful insertion
} // end delete
// sequential serach for x in the list
// if successful return its position otherwise return 0;
public int search(int x){
// Local variables
node cur;
prt.printf("\n\t\tSearch for %5d:", x);
// Complete the rest of the method
int pos = 0;
for (cur = head; cur != null ; cur = cur.rlink){
pos ++;
if (cur.data == x){
prt.printf(" Found at position %2d, ", pos);
return pos;
} // end if
} // end for
prt.printf(" Not Found.");
return 0; // x is not found.
} // end search
// print list elements formatted
public void printlst() {
// Local variables
node cur;
prt.printf("\n\tList contents: ");
for (cur = head; cur != null ; cur = cur.rlink)
prt.printf("%5d,", cur.data);
// end for
} // end printlst
// insert delete and search in the list
private void process(String fn){
// Local variables
int j, ins, del, srch, k, p;
int x;
prt.printf("\tLinked List implementation of int list without"+
//\n\tusing count, gets input file name from method argument, then
reads:"+
"\n\tinteger No. of elements to insert(ins)"+
" followed by elements to insert and their positions,"+
"\n\tinteger No. of elements to search(srch) followed by element to
search"+
"\n\tinteger No. of elements to delete(del) followed by position of"+
"elements to delete" +
"\n\t\tTo compile: javac xxxxxH5.java" +
"\n\t\tTo execute: java xxxxxH5 inputfilename");
try{
// open input file
Scanner inf = new Scanner(new File(fn));
//read no. of elements to insert
ins = inf.nextInt();
prt.printf("\n\tInsert %.
(Unordered Sets) As explained in this chapter, a set is a collection.pdfssuserc77a341
(Unordered Sets) As explained in this chapter, a set is a collection of distinct elements of the
same type. Design the class unorderedSetType, derived from the class unorderedArrayListType,
to manipulate sets. Note that you need to redefine only the functions insertAt, insertEnd, and
replaceAt. If the item to be inserted is already in the list, the functions insertAt and insertEnd
output an appropriate message. Similarly, if the item to be replaced is already in the list, the
function replaceAt outputs an appropriate message.Include the set operations of union and
intersection in your class. Also write a program to test your class. (C++)
#ifndef UNORDEREDARRAYLISTTYPE_H
#define UNORDEREDARRAYLISTTYPE_H
#include \"arrayListType.h\"
class unorderedArrayListType : public arrayListType {
public:
void insertAt(int location, int insertItem);
// Function to insert an item at a particular location
// Postcondition: The item has been added to the list and the length has
// been increased by 1.
void insertEnd(int insertItem);
// Function to insert an item at the end of the list
// Postcondition: The item has been added at the end of the list and the
// length has been increased by 1.
void replaceAt(int location, int repItem);
// Function to replace an item in the list.
// Postcondition: repItem overrwrites the item at the specified location
// in the list. The length of the list is unchanged.
int seqSearch(int searchItem) const;
// Function to search the list for searchItem. Note that this is an
// abstract function.
//Postcondition: If the item is found, returns the location in the array
// where the item is found; otherwise, returns -1.
void remove(int removeItem);
// Function to remove an item from the list
// Postcondition: If the item is found in the list, it is removed and the
// length of the list is decreased by 1; if the item is not in the list
// an appropriate message is displayed.
void removeAll(int removeItem);
// Function to remove all occurrences of an item from the list
// Postcondition: If the item is found in the the list, all occurrences are
// removed and the length of the list is decreased accordingly. If the
// item is not in the list an appropriate message is displayed.
unorderedArrayListType(int size = 100);
//Constructor.
};
#endif // UNORDEREDARRAYLISTTYPE_H
#include \"UnorderedArrayListType.h\"
#include
using namespace std;
void unorderedArrayListType::insertAt(int location,
int insertItem) {
if (location < 0 || location >= maxSize)
cout<<\"The position of the item to be inserted is out of range.\"<= maxSize) //list is full
cout << \"Cannot insert in a full list\" << endl;
else {
for (int i = length; i > location; i--)
list[i] = list[i - 1]; //move the elements down
list[location] = insertItem; //insert the item at the specified position
length++; //increment the length
}
} //end insertAt
void unorderedArrayListType::insertEnd(int insertItem) {
if (length >= maxSize) //the list is full
cout << \"Cannot insert in a full list.\.
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
Complete a C++ class implementation for a linked-list of sorted (ascending) positive integers.
The class name for this class is LLSortedPosInt and its specification is outlined in the file
LLSortedPosInt.h. The specification is accompained by two other files: (1) a partial
implementation of the class in the file LLSortedPosInt.cpp and (2) a test program called
testLL.cpp. You are to complete the partial implementation of the class by writing code for the
stubbed member functions. You may NOT make any changes to the specification file. You may
develop and test your class implementation either under Visual Studio or linux; however, your
program must be executable under linux, because that is where it will be tested.
Details: Linked lists are useful data structures for storing data records, particularly in situations
where the items are to be kept sorted, the number of records are dynamic (i.e., changing during
the course of the program’s execution) and the maximum number is arbitrary. In this exercise,
you’ll get a chance to complete the implementation of a linked-list specification. In doing so,
you’ll learn not only how to manipulate pointer objects, but also begin to learn how to create a
new and useful data type.
To get started, I have written a simple linked list definition within the header file called
LLSortedPosInt.h. My definition is, of course, not the only way to define a linked list, but it is
suitable for our simple project. Accompanying the definition is a partial implementation in the
source file LLSortedPosInt.cpp. You are to edit this file using the comments in the file and the
instructions below. Altogether, this assignment asks you to implement 13 functions.
To help with testing your functions implementations, I have provided a main program. This main
program is in the source file testLL.cpp. One quick way to repeatedly exercise your function
tests is to write a test file (I called mine testCases.txt) and use input re-direction.
The 13 functions you must add to complete the implementation are as follows:
a. Constructors (4): Classes must have constructors to initialize instances of the objects. The
constructors you will implement for this project are
i. A default constructor
ii. A constructor taking a single int parameter
iii. A constructor which builds a list from an array of integers
iv. A copy constructor
b. Destructor (1): Because the class specification includes a pointer among the attributes, you
will need to implement a destructor to delete (i.e., free or release) any storage allocated in the
constructors or other member functions.
c. Boolean Functions (2): You are to implement two Boolean functions
i. A function isEmpty() which returns true if the associated list contains no data elements,
and returns false otherwise.
ii. A function containsElement(key) which returns true is key is an element in the list and
returns false otherwise.
d. Member Operator Functions (3): When a class has a pointer among its attributes, as
.
Implement the following specification of UnsortedType using circular.pdfudit652068
Implement the following specification of UnsortedType using circular linked list as the
implementation structure.
*** I have seen this question answered here before but it is not a good answer. Can someone
please give me a original answer.***
// Deliverables:
// - A listing of the specification and implementation files for UnsortedType
// - A listing of the driver program for your test plan
// - A listing of the test plan as input to the driver.
// - A listing of the output from the driver.
template
struct NodeType;
/* Assumption: ItemType is a type for which the operators
\"<\" and \"==\" are defined-either an appropriate built-in type or a
class that overloads these operators. */
template
class UnsortedType
{
public:
// Class constructor, destructor, and copy constructor
UnsortedType();
~UnsortedType();
UnsortedType(const UnsortedType&);
void operator=(UnsortedType);
bool IsFull() const;
// Determines whether list is full.
//Post: Function value = (list is full)
int GetLength() const;
// Determines the number of elements in list.
// Post: Function value = number of elements in list.
void RetrieveItem(ItemType& item, bool& found);
// Retrieves list element whose key matches item\'s key
// (if present).
// Pre: Key member of item is initialized.
// Post: If there is an element someItem whose key matches
// item\'s key, then found = true and item is a copy of
// someItem; otherwise found = false and item is unchanged.
// List is unchanged.
void InsertItem(ItemType item);
// Adds item to list.
// Pre: List is not full.
// Item is not in list.
// Post: item is in list.
void DeleteItem(ItemType item);
// Deletes the element whose key matches item\'s key
// Pre: Key member of item is initialized.
// One and only one element in list has a key matching
// item\'s key.
// Post: No element in list has a key matching item\'s key.
void ResetList();
// Initializes current position for an iteration through the list.
// Post: Current position is prior to list.
void GetNextItem(ItemType&);
// Gets the next element in list.
// Pre: Current position is defined.
// Element at current position is not last in list.
// Post: Current position is updated to next position.
// item is a copy of element at current position.
private:
NodeType* listData;
int length;
NodeType* currentPos;
};
Solution
#include
#include
/* structure for a node */
struct node
{
int data;
struct node *next;
};
/* function to insert a new_node in a list in sorted way.
Note that this function expects a pointer to head node
as this can modify the head of the input linked list */
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current = *head_ref;
// Case 1 of the above algo
if (current == NULL)
{
new_node->next = new_node;
*head_ref = new_node;
}
// Case 2 of the above algo
else if (current->data >= new_node->data)
{
/* If value is smaller than head\'s value then
we need to change next of last node */
while(current->next != *head_ref)
current = current->next;
cur.
In C++Add the function min as an abstract function to the classar.pdffantoosh1
In C++:
Add the function min as an abstract function to the classarrayListTypeto return the smallest
element of the list.
Also, write the definition of the function min in the classunorderedArrayListTypeand write a
program to test this function.
arrayListType.h
#ifndef H_arrayListType
#define H_arrayListType
class arrayListType
{
public:
bool isEmpty() const;
//Function to determine whether the list is empty
//Postcondition: Returns true if the list is empty;
// otherwise, returns false.
bool isFull() const;
//Function to determine whether the list is full
//Postcondition: Returns true if the list is full;
// otherwise, returns false.
int listSize() const;
//Function to determine the number of elements in
//the list.
//Postcondition: Returns the value of length.
int maxListSize() const;
//Function to determine the maximum size of the list
//Postcondition: Returns the value of maxSize.
void print() const;
//Function to output the elements of the list
//Postcondition: Elements of the list are output on the
// standard output device.
bool isItemAtEqual(int location, int item) const;
//Function to determine whether item is the same as
//the item in the list at the position specified
//by location.
//Postcondition: Returns true if list[location]
// is the same as item; otherwise,
// returns false.
// If location is out of range, an
// appropriate message is displayed.
virtual void insertAt(int location, int insertItem) = 0;
//Function to insert insertItem in the list at the
//position specified by location.
//Note that this is an abstract function.
//Postcondition: Starting at location, the elements of
// the list are shifted down,
// list[location] = insertItem; length++;
// If the list is full or location is out of
// range, an appropriate message is displayed.
virtual void insertEnd(int insertItem) = 0;
//Function to insert insertItem at the end of
//the list. Note that this is an abstract function.
//Postcondition: list[length] = insertItem; and length++;
// If the list is full, an appropriate
// message is displayed.
void removeAt(int location);
//Function to remove the item from the list at the
//position specified by location
//Postcondition: The list element at list[location] is
// removed and length is decremented by 1.
// If location is out of range, an
// appropriate message is displayed.
void retrieveAt(int location, int& retItem) const;
//Function to retrieve the element from the list at the
//position specified by location
//Postcondition: retItem = list[location]
// If location is out of range, an
// appropriate message is displayed.
virtual void replaceAt(int location, int repItem) = 0;
//Function to replace the elements in the list
//at the position specified by location.
//Note that this is an abstract function.
//Postcondition: list[location] = repItem
// If location is out of range, an
// appropriate message is displayed.
void clearList();
//Function to remove all the elements from the list
//After this operation, the size of t.
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
Use the graph of the function f below to find the following. All local minimum values of f All
values at which f has a local minimum If there is more than one answer, separate them with
commas. All local minimum values of f All values at which f has a local minimum:
Solution
Dear student
Thank you for using Chegg
As per the given curve it is clear that the local minimum values of f are -3 & 0
Values of x when curve attain minimum values are x = -2,3.
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
please i need help I\'m writing a program to test the merge sort algorithm for linked lists.
I need to Print the list before being sorted and the list after sorting the elements
here is my code only help in test program the four classes are ok except the test program.
TEST PROGRAM
import java.io.*;
import java.util.*;
public class Ch9_ProgExercise7 {
Scanner input = new Scanner(System.in);
public static void main(String[] args) throws IOException {
OrderedLinkedList list
= new OrderedLinkedList(); //Line 1
IntElement num = new IntElement(); //Line 2
// Prompt the user to enter some integers
System.out.println(\"Enter integers numbers \");
String temp = input.hasnextLine();
String[] split = temp.split(\" \");
for (int i = 0; i < split.length; i++) {
Integer a = Integer.parseInt(split[i]);
// insert the intgers into the list you created above
num.setNum(a);
list.insertNode(num);
}
System.out.println();
// Print the list before being sorted
// call the mergesort method
System.out.println();
// print the list after sorting the elements
}
}
ORDEREDLICKEDLIST CLASS
public class OrderedLinkedList extends LinkedListClass
{
//default constructor
public OrderedLinkedList()
{
super();
}
//copy constructor
public OrderedLinkedList(OrderedLinkedList otherList)
{
super(otherList);
}
public void linkedInsertionSort()
{
LinkedListNode lastInOrder;
LinkedListNode firstOutOfOrder;
LinkedListNode current;
LinkedListNode trailCurrent;
lastInOrder = first;
if(first == null)
System.out.println(\"Cannot sort an empty list\");
else
if(first.link == null)
System.out.println(\"The list is of length 1. \"
+ \"Already in order\");
else
while(lastInOrder.link != null)
{
firstOutOfOrder = lastInOrder.link;
if(firstOutOfOrder.info.compareTo(first.info) < 0)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = first;
first = firstOutOfOrder;
}
else
{
trailCurrent = first;
current = first.link;
while(current.info.compareTo(firstOutOfOrder.info) < 0)
{
trailCurrent = current;
current = current.link;
}
if(current != firstOutOfOrder)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = current;
trailCurrent.link = firstOutOfOrder;
}
else
lastInOrder = lastInOrder.link;
}
}
}//end linkedInsertionSort
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; otherwise, it returns
// false.
public boolean search(DataElement searchItem)
{
LinkedListNode current; //variable to traverse the list
boolean found;
current = first; //set current to point to the first
//node in the list
found = false; //set found to false
while(current != null && !found ) //search the list
if(current.info.compareTo(searchItem) >= 0)
found = true;
else
current = current.link; //make current point to
//the next node
if(found)
found = current.info.equals(searchItem);
return found;
}
//Method to insert insertItem in the list
//Postcondition: first points to the new list,
// newItem is inserted at the proper place
//.
please help me in C++Objective Create a singly linked list of num.pdfaminbijal86
please help me in C++
Objective: Create a singly linked list of numbers based upon user input.
Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat
until they enter -1 for the number. .
Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10
Solution
#include
#include
using namespace std;
// It contains the value and the pointer to the next element in the list.
struct element {
int value;
struct element *next;
};
struct element *head = NULL;
// The list is stored in the object of this class.
class linkedlist {
public:
// To display list, we first see if head is NULL,
// If head is NULL it means the list is empty.
// Then we traverse along the list and display each item, until the next pointer is NULL.
void display() {
if(head == NULL){
cout << \"The list is empty\ \";
} else {
struct element *temp;
temp = head;
while(temp != NULL){
cout << temp->value << \" \" ;
temp = temp->next;
}
cout << \"\ \";
}
}
// To add an element to the list,create a newElement and store the value.
// If head is NULL, add the newElement to the head.
// To add an element at the starting of the list.
// The next pointer of the newElement must point to the old head.
// The new head must be pointed to the newElement.
void add(int a){
struct element *newElement;
newElement = (struct element *)malloc(sizeof(struct element));
newElement->value = a;
newElement->next = NULL;
if(head == NULL) {
head = newElement;
} else {
newElement->next = head;
head = newElement;
}
}
};
int main()
{
// Create an object of the class linkedlist.
linkedlist l = linkedlist();
int a;
do {
cout << \"Enter a number : \";
cin >> a;
if(a!=-1) { // If the number is -1 do not add it to the list.
l.add(a); // Add the number to the list.
}
l.display(); // Display the list.
} while(a!=-1); // Keep asking for a number until -1 is pressed.
return 0;
}.
--12 Points- DEVORESTATS 2-5-074- Suppose thut the proportions of bloo.pdfganisyedtrd
[-12 Points] DEVORESTATS 2.5.074 . Suppose thut the proportions of blood phenotypes in a
panticular poputation are as follows: What in the ponshability that the phenotypes of two
randomiy silected individgals matoh? (Enter your antwer to four secimal places.).
--import statemnts for Random- Scanner and IO import java-util-Random-.pdfganisyedtrd
//import statemnts for Random, Scanner and IO
import java.util.Random;
import java.util.Scanner;
import java.io.*;
public class Hobbits
{
public static void main(String[] args) throws IOException
{
final int NUM_HOBBITS = 5;
final int NUM_COLUMNS = 2;
String fileName = "hobbits.csv";
//call populateHobbits( ) to create the two dimensional array
double[][] hobbits = populateHobbits(NUM_HOBBITS, NUM_COLUMNS);
//display the number of hobbits
System.out.println(hobbits.length + " hobbits accepted Gandalf's invitation to lunch\n");
//calculate the means of the columns
double[] hobbitMeans = getColMeans(hobbits);
//write hobbits array to file
writeHobbits(hobbits, fileName);
//read and display the file that has been read
readHobbitses(fileName);
//call displayColMeans to display hobbit means
displayColMeans(hobbitMeans);
}
//method to populate hobbits array with random double values
public static double[][] populateHobbits(int numHobbits, int numCols)
{
final double HT_MULTIPLIER = 10.0; //multiplier for the hobbit height
final double WT_MULTIPLIER = 250.0; //multiplier for the hobbit weight
//instantiate Random object
Random rand = new Random();
//declare two dim array with numHobbits rows numCols columns
double[][] hobbitArray = new double[numHobbits][numCols];
//assign random double values to all elements
for (int i = 0; i < numHobbits; i++) //outer loop is for rows
{
for (int j = 0; j < numCols; j++) //inner loop is for columns
{
//get a random double value in range [0.2, 0.4]
double randDouble = getRandDouble(rand);
//assign this double to the current array element
hobbitArray[i][j] = randDouble;
//determine which multiplier to use
if (j == 0) //this is column for height
hobbitArray[i][j] *= HI_MULTIPLIER;
else //this is column for weight
hobbitArray[i][j] *= WT_MULTIPLIER;
}
}
return hobbitArray; //return the two dimensional array
}
//method to write hobbits array to file
public static void writeHobbits(double[][] ar, String fileName) throws IOException
{
//open the file to write
PrintWriter outFile = new PrintWriter(fileName);
//print columen heading of the array of stats
outFile.println("HEIGHT,WEIGHT");
for (int i = 0; i < ar.length; i++)
{
for (int j = 0; j < ar[i].length; j++)
{
outFile.print(ar[i][j]);
//if at end of a row, add newline char
if (j == ar[i].length - 1)
outFile.print("\n");
else //add the "," delimiter
outFile.print(",");
} //end of inner loop
} //end of outer loop
outFile.close(); //close outfile
System.out.println("The file was successfully written\n");
} //end of method
//method to read the hobbits file
public static void readHobbitses(String fileName) throws IOException {
//open the file to read
File dataFile = new File(fileName);
Scanner inFile = new Scanner(dataFile);
//variable to contain the substrings of one line of file
String[] oneLine = new String[2];
int counter = 0; //keep track of line numbers
System.out.println("Data read from the " + fileName + " file:");
//read file, one line at a time
while (inFile.hasNe.
--kindly help with the correct answer --must show diagram Explain what.pdfganisyedtrd
//kindly help with the correct answer
//must show diagram
Explain what happens when the POPA instruction executes. Make sure to show the physical
addresses where data are stored. (Assume that SP = FFFDH and SS = 1000H before execution.)
Show Schematic diagram of what happens after the execution and also show base address ,
physical address and final address in that diagram.
--- Which of the following influences the instantaneous rate of change.pdfganisyedtrd
... Which of the following influences the instantaneous rate of change in a two-species
competitive* community's state at a given time? Assume that both species are competing, at least
to some degree (it is a true -/- interaction). density of species 2 inter-specific competition density
of species 1 intra-specific competition all of these.
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdfganisyedtrd
// USING UNITY TRYING TO CREATE A CLICK TO PATH, THAT YOU CLICK ON AND
THE AGENT/AVATAR FOLLOWS THE BEST PATH TO GET THERE
// AT THE SAME TIME THERE IS A GUARD CHASING THE AGENT USING
AWARENESS AND PAHTFINDING.
//THIS IS THE MapManager.cs the Agent.cs I could upload it
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
// Custom struct to hold the per-tile information needed for the A* pathing search
public struct grid_cell
{
public bool visited;
public bool isBlocked;
public Vector2Int parent;
public float g, h, f;
}
public class MapManager : MonoBehaviour
{
// fixed map size for simplicity - map file must match
public const int WIDTH = 12;
public const int HEIGHT = 12;
// need to know tile size (color for debugging)
private Vector2 TILE_SIZE;
private Color TILE_COLOR;
// prefab tiles (and debugging labels)
public GameObject[] _tilePrefabs;
public GameObject _labelPrefab;
public GameObject _uiCanvas;
// A* pathfinding array and queue
private grid_cell[,] _map = new grid_cell[WIDTH, HEIGHT];
private List<KeyValuePair<float, Vector2Int>> _openList = new List<KeyValuePair<float,
Vector2Int>>();
// references to tile spriterenderers and tile labels for debugging
private SpriteRenderer[,] _tiles = new SpriteRenderer[WIDTH, HEIGHT];
private Text[,] _labels = new Text[WIDTH, HEIGHT];
// steps is a convenient way to generate the 8 children of a grid square
private Vector2Int[] _steps = new Vector2Int[8];
void Start()
{
TILE_SIZE = _tilePrefabs[0].transform.GetComponent<SpriteRenderer>()
.bounds.extents * 2;
// load map and create tiles
readMapFile();
// for debugging, store the color of an unblocked tile (for changing them back)
TILE_COLOR = _tiles[0,0].color;
// store "step" vectors for the four cardinal directions
_steps[0].x = -1; _steps[0].y = 0;
_steps[1].x = 0; _steps[1].y = -1;
_steps[2].x = 0; _steps[2].y = 1;
_steps[3].x = 1; _steps[3].y = 0;
// and the four diagonal directions
_steps[4].x = 1; _steps[4].y = 1;
_steps[5].x = 1; _steps[5].y = -1;
_steps[6].x = -1; _steps[6].y = 1;
_steps[7].x = -1; _steps[7].y = -1;
}
/*********************************************************************************************
Collision with blocked tiles (walls)
- called by agents
- returns a response vector indicating the amount to "push" the agent out of the walls
- (0,0) indicates no collisions happening
*/
public Vector2 checkBlockedCollision(Vector2 pos, Vector2 extents)
{
// convert the world position that we're checking to the coordinates of a grid cell
Vector2Int posGC = vectorToGC(pos);
// loop over the diagonal steps to check the diagonally-adjacent cells
// check those first, because a diagonal collision implies two cardinal direction collisions
for (int si=4;si<_steps.Length;si++) {
// for each diagonal neighbor
Vector2Int step = _steps[si];
Vector2Int neighbor = posGC + step;
// if it's not on the map or not blocked, then no collision possible
if (!onMap(neighbor)) continue;
if.
- TIF B cells and T cells are able to alter their genome- What kind of.pdfganisyedtrd
- TIF B cells and T cells are able to alter their genome. What kind of diversity does this give the
variable region? Why would dedicating a part of our genome for this variability not be possible?
- Complete immunoglobulin genes are generated by the of separate gene segments. What is this
process? - Hypervariable (HV) regions are also known as what? - What segment are CDR1 and
CDR2 located on? Where does the CDR3 region originate from? - What is the CDR3 loop
formed from? - How are light-chain V regions constructed?.
- The array data of integers is sorted in an increaning order- - The i.pdfganisyedtrd
- The array data of integers is sorted in an increaning order. - The input argunent target in the
value that in nought in data. - binarysearch should return the index of the element found in data
or - 1 if target is not present. - The initial call is binarysearch (data, target, 0, data-langth - 1). -
You aro given 15 blank lines (numbered below) to enter your code, which is more than is
needed. public atatic int binarySearch(int[] data, int target, int low, int high) f , Il Start of your
Java code.
- Quantitative (record completenessdocuments are present- forms authen.pdfganisyedtrd
- Quantitative (record completenessdocuments are present, forms authenticated)
4. Mrs, Kitty Wells was admitted today, November 14, 2019, and upon review of her chart it was
noted that an H\&P was found dated from October 18, 2019. Mrs. Wells has not had any
significant changes to her medical history or condition since her last appointment with her
physician. - Is this an acceptable timeframe for her H\&P? 5. Mr. Jim Caldwell presented for a
colon resection surgery this morning at 8:00 am. - What specific document must have been on
the chart prior to surgery? - What specific document must be dictated ASAP and no later than 24
hours of surgery? 6. You are reviewing the chart for completeness of documentation for Wendy
Jones' surgery on October 2 5 th . You were able to locate the following items: - H\&P - Pre-Op
anesthesia evaluation - Intra-Op documents - Operative report - Discharge summary.
- In 150-250 words- respond to all questions- This is your initial dis.pdfganisyedtrd
- In 150-250 words, respond to all questions. This is your initial discussion post, due by
Thursday at midnight. - Post a 100-200 word response to a peer's post by Monday at midnight. -
See this description of what a substantial discussion response/post looks like. - See this rubric for
how discussion posts are graded. Using the reading from Ch. 11 ("Mining for Cell Phones", and
"Recycling Metals from E-Waste") as a resource to answer the following questions. The use of
the metal tantalum, mined from the ore coltan, has had a variety of societal, economic, and
environmental impacts on the Democratic Republic of Congo (DRC). Tantalum is such a useful
metal that it is used in an even wider array of items than cell phones. including other electronics,
turbines, capacitors, biomedical supplies, and a variety of products used in the chemical, textile,
and aerospace industries. The story of coltan in DRC is just one example of how an abundance of
exploitable resources can often worsen or prolong military conflicts in nations that are too poor
or ineffectively governed to protect these resources. In such wars, civilians often suffer the most
as civil society breaks down. Question 1: Suppose you are the head of an international aid
agency that has $10 million to help address conflicts related to mining in DRC. You have access
to government and rebel leaders in DRC and neighboring countries, to ambassadors of the
world's nations in the United Nations, and to representatives of international mining
corporations. Based on what you have learned in this section, what steps would you consider
taking to help improve the situation in this nation? Due to grassroots activism, the international
community became aware of the conflicts associated with tantalum mining in Congo and since
the early 2000 s, steps have been taken by several countries to reduce the societal and
environmental impacts of mining this mineral. One example is when the U.S. Congress passed
the Dodd-Frank Wall Street Reform and Consumer Protection Act in 2010, which required
publicly traded companies on the U.S. Stock Exchange to disclose if their minerals were coming
from the DRC or any adjoining country, and to guarantee they were conflict-free. Your book also
outlines the push for recycling e-waste in order to re-use tantalum and some of the other rare
metals present in electronics. This case study highlights several aspects of environmental studies
(science, law, policy, activism) which have all played a role in this issue. Question 2: Do you see
a role for activism in solving environmental crise i ? Do you think the role of an activist is
contrary to or supportive of the role of politicians and governments or industries? How do you
think they can work together? Question 3: Several municipalities in our region have e-waste
recycling programs, although they are not as comprehensive as recycling programs for paper,
plastics, and metal cans and jars. If you had e-waste right now, what would .
- Bag breaks open- included as delay in the allowance factor ^ Conveyo.pdfganisyedtrd
* Bag breaks open; included as delay in the allowance factor ^ Conveyor jams; included as delay
in the allowance factor a) The standard time for this process = seconds (round your response to
two decimal places)..
- If your class investigated two different types of tissues (plants)-.pdfganisyedtrd
. If your class investigated two different types of tissues (plants), is there a difference between
the species used regarding what percent of cells are in interphase?
These tissues have been treated chemically to arrest cells during mitosis. In normal tissues,
which phase do cells capable of dividing spend most of their time in? Briefly describe what
happens inside the cell during that phase..
- Cytosolic pathogens- - Where are they degraded- - What do their pept.pdfganisyedtrd
- Cytosolic pathogens: - Where are they degraded? - What do their peptides bind to? - What kind
of cells do they present to? - What is the effect on the presenting cell? - Intravesicular pathogens:
- Where are they degraded? - What do their peptides bind to? - What kind of cells do they
present to? - What is the effect on the presenting cell? - Extracellular pathogens and toxins: -
Where are they degraded? - What do their peptides bind to? - What kind of cells do they present
to? - What is the effect on the presenting cell.
- Drag the labels of Group 1 to their respective targets to identify p.pdfganisyedtrd
- Drag the labels of Group 1 to their respective targets to identify processes. - Drag the labels of
Group 2 to their respective targets to identify structures. metamorphosis meiosis ectoderm
blastula ( 2 n ) gastrula ( 2 n ) zygote ( 2 n ) larva ( 2 n ) endoderm.
- Each student must post ane (1) substantial intid post as a response.pdfganisyedtrd
- Each student must post ane (1) substantial intid post as a response to the disatsion queston weh
a mirimum af 150 words by Wednesday at 11.59 PM Discussion Question(s) Bevied the modele
resources and read the scenario to arswer the dispasishon quatstent. neans of planitic polsution
control and fulty itiliand ty the waste dinposal indeytry. Bacturia? Why are enly humans being
afiected? 1. Anawer the senateris questions. = How can a plattic-enating bacteria tum into a
muscie-nsting bacterie? = Why are ondy thumans being atectedi Peer Response Instructions 1.
Aespond in two peers. 2. Subent both peer responses by the asugned due date.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
-- 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);