90.7k views
1 vote
Description: Write a C++ program to process periodic table information from a file.

Each element will have an atomic number, a name, an abbreviation, and a mass. Your program must include:
1. An Element structure to be defined in a header file: Element.h
2. A function read_table that will return the number of elements read from the file and via a reference parameter, a pointer to an array of pointers to the elements read. The data file is located at /user/tvnguyen7/data/periodictable.dat. This function must read in the data by constructing a linked list and convert the linked list into an array of pointers. The prototype for this function is to be included in the Element.h file. The function will return 0 on any error condition.
3. A main program that will call read_table to read in the table, sort the table using the element name and print out the table using the required output format. You can use qsort in cstdlib or write your own sort function.
4. Dynamic memory must be allocated and deallocated properly.

User Tnavidi
by
8.4k points

1 Answer

3 votes

Final answer:

The student must create a C++ program to read and sort periodic table information using an Element structure and dynamic memory management, leading to properties of each element, atomic number, atomic mass being processed and displayed.

Step-by-step explanation:

The student's question involves writing a C++ program that processes periodic table information from a file, where each element includes an atomic number, a name, an abbreviation, and a mass. The program requires defining an Element structure within a header file, writing a function named read_table that utilizes a linked list to read data from the file /user/tvnguyen7/data/periodictable.dat and converts it into an array of pointers to Element, and writing a main program that sorts and prints the periodic table data.

The requirements also state that the memory management needs to be handled properly, ensuring dynamic memory is allocated and deallocated as needed. The sorting can be conducted using the qsort function from cstdlib or by implementing a custom sort function. The function read_table should also handle error conditions by returning 0.

User Ayat Ullah Sony
by
7.6k points