A database of laptops is kept in a text file as shown below. The
entries are brand name, number of models (maximum number is limited
to 5), model name, and price in that order. A small segment of the
file might look like the following. Dell 4 Latitude 1000 Inspiron
750 XPS 2000 G15 3000 Lenovo 3 ThinkPad 1200 IdeaPad 1100 Yoga 1600
HP 2 ProBook 1300 Envy 1000 Apple 2 MacBookPro 3000 MacBookAir 2700
Asus 3 X515A 1200 ZenBook 1500 ExpertBook 1700 So, according to the
data presented above, the first brand is Dell; it has 4 models
Latitude, Inspiron, XPS, and G15; the prices of these models are
1000, 750, 2000, and 3000 respectively. The second brand is Lenovo;
it has 3 models ThinkPad, IdeaPad, and Yoga; the prices of these
models are 1200, 1100, and 1600 respectively, and so on. Step 1:
Create a text file that contains the database of laptops as shown
in the example above. Declare an array of laptop structure shown
below in main; the maximum size of the array is limited to 100.
laptop1.JPG Step 2: Create a menu-driven C program Call a function
named readDetails to read the contents of the text file into the
array of laptop structure (function prototypes are given below).
brandName: stores the brand name of the laptop noOfmodels: stores
the number of models for a particular brand laptopName: stores the
name of the models price: stores price of the models Display the
menu for the user using a menu function. The contents of the menu
function should be: Enter 1 to display the laptop details Enter 2
to add laptop details into a LinkedList Enter 3 to display
LinkedList Enter 4 to find average prices for a brand Enter -1 to
exit the program Option 1: displays all the contents of the array
of the laptop structure on a terminal as shown on the screenshot
below. Use displayArray function for this option. This displayArray
function must use the array of the structure to display the
details. Option 2: adds the contents of the array into a
LinkedList. Contents of the first array go to node 1 and contents
of the second array go to node 2 and so on. Use the fillLinkedlist
function for this option. Option 3: displays all the contents of
LinkedList on a terminal as shown on the screenshot below. Use
printList function for this option. This printList function must
use the LinkedList created in option 2 to display the details.
Option 4: ask the user to enter a brand name of a laptop and then
calculate and display the average price (precision-two decimal
places) of all the models of that brand, if there is no such brand
the program should report it back to the user. Use the
findAverageprice function for this option. This findAverageprice
function must use LinkedList created in option2 to calculate the
average. All printing happens in main for option 4. The program
should exit only when the user inputs -1. Your program must have 5
functions (function prototypes are given) in addition to the main
(3 marks): A readDetails//function 1 (3 marks) A menu //function 2
( 1 mark) A displayArray //function 3 (2 marks) A fillLinkedlist
//function 4 (3 marks) A printList //function 5 (3 marks) A
findAverageprice //function 6 (5 marks) Marks will be deducted if
separate functions are not implemented to do these actions. You are
free to use different parameters and data types for the
functions
A database of laptops is kept in a text file as shown below. The entries are brand name, number of models (maximum numbe
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am