Write a program that reads the data from the file mydatatxt


Write a program that reads the data from the file 'mydata.txt', saves it in an array of structures and finally prints the array of structures to the monitor.

The file 'mydata.txt' is posted on Webcourses with the homework file. This file contains information about computer hard disks (ie: hard disk name, diameter in inch, size in MB, manufacturing year).

In your code, declare a structure called 'hard_disk'. This structure should contain all the information about a hard disk, as described in the file. Therefore it should have these member variables:
? A string called 'name'. Look at the names of the hard disks in the file to decide how large this string
should be.
? A variable of type 'double' called 'size'that will hold the size of the hard disk
? Two 'int' member variables in the structure, one for the 'capacity' and one for the manufacturing 'year'

After declaring the structure, declare an array of 'struct hard_disk' called 'mydisks'.This array should have a size of 6 since there are data about 6 hard disks in the file.

Next, write a loop in the 'main' function that reads the datafrom the file and stores it in the array of disks. Don't print the data in this loop. You can print it for debugging,but your final solution should not print the data in this loop.

Once the array of disks has been filled, write another loop that prints the data from the array of disks. Your output should look like in the figure below. Notice, for the third hard disk in the file, the year is '0'. Therefore, the program prints 'unknown' for this. Your program should take care of this case by comparing the 'year' to '0' and printing 'unknown' if the year is zero.


Finally, remember to close the file pointer.


Include the output that you obtained.
Product     Size(inch)        Capacity(MB)        Year
-------------------------------------------------------
DEC-R81         14.00                 456                1985
Fujitsu             8.00                 130                  1984
Micropolis-RD53 5.25                 85                Unkown
IBM-0361         3.50                320                 1988
Conner-CP-2045 2.50                40                 1990
Integral-1820    1.80                 20                1992

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a program that reads the data from the file mydatatxt
Reference No:- TGS0661423

Expected delivery within 24 Hours