Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

**I cannot use vectors. This assignment is focused on pointers and arrays. Please separate periodic_table.cpp, Element.h, and read_table.cpp **

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.(if you ask where the file is, its accessible through this path). 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.

image text in transcribed

I will be using the following: (feel free to use others, but take into account this is a beginner c++ class so if its too advanced i cant use it. Thanks!)
#include "Element.h" #include  #include  #include  #include  

to open the file:

#include  #include 
using namespace std;

struct Element {

int atomic_number;

string name;

string abbreviation;

double mass;

};

For additional references, use pointer variables (*&), nullptr, pointers as function parameters, use "new" operator to allocate dynamic memory. For preference, please use qsort from cstlib. Additionally use accessible structure members via pointer variables (->)

Example:

Element *e = new Element; e->ANum = aNum; e->Abr = aBr; e->Mass = mass; e->Name = name; n = new Node; n->pElement = e; n->next = nullptr; 

Required Output: formatting guide 123456789012345678901234456789012345679 Periodic Table by F. Last Number of elements: 118 Name Actinium Abr ANo Mass Ac 89 227.00 Al 13 26.98 Aluminum all the elements Zinc Zirconium Zn 30 65.38 Zr 40 91.22 146.44 The average mass: Required Output: formatting guide 123456789012345678901234456789012345679 Periodic Table by F. Last Number of elements: 118 Name Actinium Abr ANo Mass Ac 89 227.00 Al 13 26.98 Aluminum all the elements Zinc Zirconium Zn 30 65.38 Zr 40 91.22 146.44 The average mass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago