Write a program (C++) that will use partially filled parallel arrays to store th
ID: 3678416 • Letter: W
Question
Write a program (C++) that will use partially filled parallel arrays to store the periodic table information.
1. Your main program will call ther function read_periodic_table to read the periodic table from the periodictable.dat file. Each line in this file consists of: atomic-number abbreviation name atomic-weight The function will return the actual number of elements read from the file.
2. After reading the file into the array, your main program will provide the user with the ability to search for element with atomic number or abbreviation and a print operation. The menu will repeat until the user selects exit.
3. All data must be passed between the functions. NO global variables or arrays.
Explanation / Answer
Please use the below code to read the periodic table:
#include <iostream>
#include <fstream>
using namespace std;
class PeriodicTable
{
char Name[15], Symbol[3], Block, State[10], Colour[15], Classification[20];
int GroupNo, AtomicNo, PeriodNo;
float Weight;
public:
void GetInfo();
};
int Read_Periodic_Table()
{
ifstream file;
file.open("PeriodicTable.dat", ios::binary | ios::in);
while (0 == file.rdstate())
{
PeriodicTable ptele;
file.read((char *)&ptele, sizeof(ptele));
//if (0 == file.rdstate())
// ptele.PrintInfo();
}
file.close();
return 0;
}
void PeriodicTable::GetInfo()
{
cout << "Full Name of the element: ";
cin >> Name;
cout << "Symbol: ";
cin >> Symbol;
cout << "Block: ";
cin >> Block;
cout << "State(at Room Temperature): ";
cin >> State;
cout << "Colour: ";
cin >> Colour;
cout << "Classification: ";
cin >> Classification;
cout << "Group Number: ";
cin >> GroupNo;
cout << "Atomic Number: ";
cin >> AtomicNo;
cout << "Period Number: ";
cin >> PeriodNo;
cout << "Atomic Weight: ";
cin >> Weight;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.