Write a C program called Assignment4.c, that creates a linked list of Computer data. Each entry in the list is to have the computer’s brand name, memory (float), speed (float), price (float), and a pointer to the next computer data. Create a struct for the Computer first. Then create a pointer (“head”) that points to the first element in the linked list (initially NULL), as a global variable. Also, you need to create the following functions:

  • int insertAtIndex(char * brandname, float memory, float speed, float price, int index): This function attemps to insert a new computer data into the linked list using the parameter values – brandname, memory, speed, and price at the location indicated by the parameber “index”. If “index” is 0, then that means that it should be inserted as the first data in the linked list. If it is successfully inserted, then it should return the index of where it is inserted. If the parameter “index” value is not within the linked list size (for instance, less than 0, or greater than the index of the end data in the list.), then it should return -1.
  • int size(): This function returns the number of entries in the linked list. If the linked list is empty, it should return 0.
  • void displayLinkedList( ): It prints all entries in the linked list in the following format:
Brand Name: Dell
Memory: 3.500GB
Speed: 1.500GHz
Price: $ 2000.00

Brand Name: IBM
Memory: 4.000GB
Speed: 2.000GHz
Price: $ 1050.00

Brand Name: Sony
Memory: 4.000GB
Speed: 2.500GHz
Price: $ 2519.00

Brand Name: Acer
Memory: 1.000GB
Speed: 0.700GHz
Price: $ 664.30
  • int removeComputer(float memory, float speed): This function searches a computer with the parameters, memory and speed, removes the computer entry, and returns the index of where that entry was located. It should return -1 if such computer entry with the given memory and speed was not found. The first computer in the linked list with the memory and speed should be removed if there are two such computer entries.
  • struct Computer * searchComputer(float memory, float speed): This function searches a computer entry with the parameters, memory and speed, and returns that computer entry once it is found (The first found entry should be returned). It should return NULL if not found.
  • int main(): The main function should start by displaying this menu in this format:
Choicett Actionn
------tt ------n
Att Add Computern
Dtt Display List Sizen
Ptt Print List Elementsn
Rtt Remove Computern
Stt Search Computern
Qtt Quitn
? tt Display Helpnn

Next, the following prompt should be displayed:

What action would you like to perform?n

Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following describes what needs to be done for each command.

A Add Computer

Your program should display the following prompt:

Please enter a computer to add:n
Please enter the brand name:n

Read in the computer’s brand name. Then prompt the following:

Please enter the memory:n

Read in the computer’s memory. Then prompt the following:

Please enter the speed:n

Read in the computer’s speed. Then prompt the following:

Please enter the price:n

Read in the computer’s price. Then prompt the following:

Please enter the index to insert:n

Read in the index. Then attempt to insert the computer entry with the information at the given index. If the insertion is not successful, then display the message:

The computer could not be addedn

If the insertion is successful, then display the message:

The computer is added at 2n

where 2 is the index where it was added.

D Display List Size

Your program should display the following message:

The size of the linked list is 5n

where 5 is the number of entries in the linked list.

P Print List Elements

Each computer information in the computer list should be displayed in the following format:

Brand Name: Dell
Memory: 3.500GB
Speed: 1.500GHz
Price: $ 2000.00

If there is no computer entry in the linked list, display:

The list is emptyn

A real example is looked like this:

What action would you like to perform?

Brand Name: Dell
Memory: 3.500GB
Speed: 1.500GHz
Price: $ 2000.00

Brand Name: IBM
Memory: 4.000GB
Speed: 2.000GHz
Price: $ 1050.00

Brand Name: Sony
Memory: 4.000GB
Speed: 2.500GHz
Price: $ 2519.00

Brand Name: Acer
Memory: 1.000GB
Speed: 0.700GHz
Price: $ 664.30
R Remove Computer

Your program should display the following prompt:

Please enter a memory(number) to remove:n

Read in the memory. Then prompt the following:

Please enter a speed(number) to remove:n

Read in the speed. If a computer entry with the memory and speed is found in the linked list, then remove it from the list, and display the following:

Computer was removedn

If there is no such computer entry in the linked list, display:

Computer with the memory and speed was not foundn
S Search Computer

Your program should display the following prompt:

Please enter a memory(number) to search:n

Read in the memory. Then prompt the following:

Please enter a speed(number) to search:n

Read in the speed and look up the linked list, if there does not exist a computer with the memory and speed, then it should display the following:

The computer with the memory and speed was not foundn

If a computer with the memory and speed was found, display their brand name, memory, speed, and price in the following format (the first found one should be used if there are two computers with the same memory and speed):

The computer's brand name is Dell
The computer's memory is 1.550GB
The computer's speed is 0.900GHz
The computer's price is $ 1500.40

The following is an example run (user input is in bold letter):

Choice Action
------ ------
A Add Computer
D Display List Size
P Print List Elements
R Remove Computer
S Search Computer
Q Quit
? Display Help

What action would you like to perform?
A
Please enter a computer to add:
Please enter the brand name:
Dell
Please enter the memory:
3.5
Please enter the speed:
1.5
Please enter the price:
2000.0
Please enter the index to insert:
0
The computer is added at 0
What action would you like to perform?
A
Please enter a computer to add:
Please enter the brand name:
Acer
Please enter the memory:
1.0
Please enter the speed:
0.7
Please enter the price:
664.3
Please enter the index to insert:
0
The computer is added at 0
What action would you like to perform?
A
Please enter a computer to add:
Please enter the brand name:
IBM
Please enter the memory:
4
Please enter the speed:
2
Please enter the price:
1050.0
Please enter the index to insert:
2
The computer is added at 2
What action would you like to perform?
A
Please enter a computer to add:
Please enter the brand name:
HP
Please enter the memory:
4
Please enter the speed:
2.5
Please enter the price:
2519.0
Please enter the index to insert:
1
The computer is added at 1
What action would you like to perform?
P

Brand Name: Acer
Memory: 1.000GB
Speed: 0.700GHz
Price: $ 664.30

Brand Name: HP
Memory: 4.000GB
Speed: 2.500GHz
Price: $ 2519.00

Brand Name: Dell
Memory: 3.500GB
Speed: 1.500GHz
Price: $ 2000.00

Brand Name: IBM
Memory: 4.000GB
Speed: 2.000GHz
Price: $ 1050.00

What action would you like to perform?
R
Please enter a memory(number) to remove:
4
Please enter a speed(number) to remove:
2.5
Computer was removed
What action would you like to perform?
D
The size of the linked list is 3
What action would you like to perform?
S
Please enter a memory(number) to search:
4
Please enter a speed(number) to search:
2.5
The computer with the memory and speed was not found
What action would you like to perform?
D
The size of the linked list is 3
What action would you like to perform?
S
Please enter a memory(number) to search:
1
Please enter a speed(number) to search:
0.7
The computer's brand name is Acer
The computer's memory is 1.000GB
The computer's speed is 0.700GHz
The computer's price is $ 664.30

What action would you like to perform?
P

Brand Name: Acer
Memory: 1.000GB
Speed: 0.700GHz
Price: $ 664.30

Brand Name: Dell
Memory: 3.500GB
Speed: 1.500GHz
Price: $ 2000.00

Brand Name: IBM
Memory: 4.000GB
Speed: 2.000GHz
Price: $ 1050.00

What action would you like to perform?
Q
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.