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:
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
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