📄 periodic_table.cpp
字号:
// PROJECT - THE PERIODIC TABLE
// ----------------------------
// HEADER FILES
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
class MENUS
{
public:
void MainMenu(void);
void AtomMenu(void);
void QueryMenu(void);
};
class ATOM
{
public:
void Introduction(void);
void InsertElement(int, char [5], char [20], int, int, char [5], int, int);
void CreateAtomArray(void);
void DisplayElement(int, int, int);
void PeriodicTable(void);
void AtomInfo_Symbol(void);
void AtomInfo_Name(void);
void AtomInfo_AtomicNo(void);
void AtomInfo_MassNo(void);
void AtomList(void);
void Query_Group(void);
void Query_Period(void);
void Query_Reactive(void);
void Query_Transition(void);
void Query_Poor(void);
void Query_Non(void);
void Query_Noble(void);
private:
int AtomicNo, MassNo, Period, Key;
char GroupNo[5], eleSymbol[5], eleName[20];
} ArrAtom[104]; // Array for all elements in Periodic Table
// FUNCTION TO DISPLAY MAIN MENU
void MENUS :: MainMenu(void)
{
char ch;
ATOM A;
do
{
textcolor(YELLOW);
textbackground(CYAN);
clrscr();
textcolor(YELLOW);
textbackground(BLUE);
for (int i=6; i<=19; i++)
{
gotoxy(25,i);
cprintf(" ");
delay(20);
}
gotoxy(33,8);
textcolor(LIGHTGREEN);
cprintf("PERIODIC TABLE");
gotoxy(31,10);
cout<<"1. Introduction";
gotoxy(31,11);
cout<<"2. Periodic Table";
gotoxy(31,12);
cout<<"3. Atom Information";
gotoxy(31,13);
cout<<"4. List of all Atoms";
gotoxy(31,14);
cout<<"5. Query";
gotoxy(31,15);
cout<<"0. Quit";
gotoxy(31,17);
cout<<"Enter your Choice : ";
ch = getch();
textcolor(LIGHTGRAY);
textbackground(BLACK);
clrscr();
switch(ch)
{
case '1':
A.Introduction();
break;
case '2':
A.PeriodicTable();
break;
case '3':
AtomMenu();
break;
case '4':
A.AtomList();
break;
case '5':
QueryMenu();
break;
}
} while(ch != '0' && ch != 27);
}
// FUNCTION TO DISPLAY ATOM INFORMATION MENU
void MENUS :: AtomMenu(void)
{
char ch;
ATOM A;
do
{
textcolor(YELLOW);
textbackground(CYAN);
clrscr();
textcolor(YELLOW);
textbackground(BLUE);
for (int i=20; i>=6; i--)
{
gotoxy(25,i);
cprintf(" ");
delay(20);
}
gotoxy(32,8);
textcolor(LIGHTGREEN);
cprintf("ATOM INFORMATION");
gotoxy(27,10);
textcolor(WHITE);
cprintf("according to......");
gotoxy(32,12);
cout<<"1. Element Symbol";
gotoxy(32,13);
cout<<"2. Element Name";
gotoxy(32,14);
cout<<"3. Atomic No.";
gotoxy(32,15);
cout<<"4. Mass No.";
gotoxy(32,16);
cout<<"0. Return";
gotoxy(32,18);
cout<<"Enter your Choice : ";
ch = getch();
textcolor(LIGHTGRAY);
textbackground(BLACK);
switch(ch)
{
case '1':
A.AtomInfo_Symbol();
break;
case '2':
A.AtomInfo_Name();
break;
case '3':
A.AtomInfo_AtomicNo();
break;
case '4':
A.AtomInfo_MassNo();
break;
}
} while(ch != '0' && ch != 27);
}
// FUNCTION TO DISPLAY QUERY MENU
void MENUS :: QueryMenu(void)
{
char ch;
ATOM A;
do
{
textcolor(YELLOW);
textbackground(CYAN);
clrscr();
textcolor(YELLOW);
textbackground(BLUE);
for (int i=20; i>=6; i--)
{
gotoxy(25,i);
cprintf(" ");
delay(20);
}
gotoxy(35,7);
textcolor(LIGHTGREEN);
cprintf("QUERY MENU");
gotoxy(30,9);
cout<<"1. Atoms in Group No...";
gotoxy(30,10);
cout<<"2. Atoms in Period...";
gotoxy(30,11);
cout<<"3. Reactive Metals";
gotoxy(30,12);
cout<<"4. Transition Elements";
gotoxy(30,13);
cout<<"5. Poor Metals";
gotoxy(30,14);
cout<<"6. Non-Metals";
gotoxy(30,15);
cout<<"7. Noble Gases";
gotoxy(30,16);
cout<<"0. Return";
gotoxy(30,18);
cout<<"Enter your Choice : ";
ch = getch();
textcolor(LIGHTGRAY);
textbackground(BLACK);
switch(ch)
{
case '1':
A.Query_Group();
break;
case '2':
A.Query_Period();
break;
case '3':
A.Query_Reactive();
break;
case '4':
A.Query_Transition();
break;
case '5':
A.Query_Poor();
break;
case '6':
A.Query_Non();
break;
case '7':
A.Query_Noble();
break;
}
} while(ch != '0' && ch != 27);
}
// FUNCTION TO INSERT AN ELEMENT WITH GIVEN INFO. IN AN ARRAY
void ATOM :: InsertElement(int i, char teleSymbol[5], char teleName[20], int tAtomicNo, int tMassNo, char tGroupNo[5], int tPeriod, int tKey)
{
strcpy(ArrAtom[i].eleSymbol,teleSymbol);
strcpy(ArrAtom[i].eleName,teleName);
ArrAtom[i].AtomicNo = tAtomicNo;
ArrAtom[i].MassNo = tMassNo;
strcpy(ArrAtom[i].GroupNo,tGroupNo);
ArrAtom[i].Period = tPeriod;
ArrAtom[i].Key = tKey;
}
void ATOM :: Introduction(void)
{
clrscr();
textcolor(RED);
gotoxy(1,1);
cprintf("THE PERIODIC TABLE");
textcolor(LIGHTGRAY);
gotoxy(1,4);
cout<<"The different kinds of elements can be arranged in a pattern, according";
gotoxy(1,6);
cout<<"to the structure of their atoms and the way in which they behave.";
textcolor(GREEN);
gotoxy(1,9);
cprintf("The Periodic Table shows all the elements arranged in groups.");
textcolor(LIGHTGRAY);
gotoxy(1,11);
cout<<"The elements in each group are arranged vertically. The element with the";
gotoxy(1,13);
cout<<"smallest atomic number is at the top of the group, and the one with the";
gotoxy(1,15);
cout<<"largest atomic number at the bottom.";
gotoxy(1,17);
cout<<" The horizontal rows in the Periodic Table are called periods.";
getch();
}
// FUNCTION TO CREATE ARRAY TO ATOMS
void ATOM :: CreateAtomArray(void)
{
InsertElement(1,"H","Hydrogen",1,1,"1",1,0);
InsertElement(2,"He","Helium",2,4,"0",1,5);
InsertElement(3,"Li","Lithium",3,7,"1",2,1);
InsertElement(4,"Be","Beryllium",4,9,"2",2,1);
InsertElement(5,"B","Boron",5,11,"3",2,4);
InsertElement(6,"C","Carbon",6,12,"4",2,4);
InsertElement(7,"N","Nitrogen",7,14,"5",2,4);
InsertElement(8,"O","Oxygen",8,16,"6",2,4);
InsertElement(9,"F","Fluorine",9,19,"7",2,4);
InsertElement(10,"Ne","Neon",10,20,"0",2,5);
InsertElement(11,"Na","Sodium",11,23,"1",3,1);
InsertElement(12,"Mg","Magnesium",12,24,"2",3,1);
InsertElement(13,"Al","Aluminium",13,27,"3",3,3);
InsertElement(14,"Si","Silicon",14,28,"4",3,4);
InsertElement(15,"P","Phosphorus",15,31,"5",3,4);
InsertElement(16,"S","Sulphur",16,32,"6",3,4);
InsertElement(17,"Cl","Chlorine",17,35,"7",3,4);
InsertElement(18,"Ar","Argon",18,40,"0",3,5);
InsertElement(19,"K","Potassium",19,39,"1",4,1);
InsertElement(20,"Ca","Calcium",20,40,"2",4,1);
InsertElement(21,"Sc","Scandium",21,45,"1b",4,2);
InsertElement(22,"Ti","Titanium",22,48,"2b",4,2);
InsertElement(23,"V","Vanadium",23,51,"3b",4,2);
InsertElement(24,"Cr","Chromium",24,52,"4b",4,2);
InsertElement(25,"Mn","Manganese",25,55,"5b",4,2);
InsertElement(26,"Fe","Iron",26,56,"6b",4,2);
InsertElement(27,"Co","Cobalt",27,59,"7b",4,2);
InsertElement(28,"Ni","Nickel",28,59,"8b",4,2);
InsertElement(29,"Cu","Copper",29,63,"9a",4,2);
InsertElement(30,"Zn","Zinc",30,65,"9b",4,2);
InsertElement(31,"Ga","Gallium",31,70,"3",4,3);
InsertElement(32,"Ge","Germanium",32,73,"4",4,3);
InsertElement(33,"As","Arsenic",33,75,"5",4,4);
InsertElement(34,"Se","Selenium",34,79,"6",4,4);
InsertElement(35,"Br","Bromine",35,80,"7",4,4);
InsertElement(36,"Kr","Krypton",36,84,"0",4,5);
InsertElement(37,"Rb","Rubidium",37,85,"1",5,1);
InsertElement(38,"Sr","Strontium",38,88,"2",5,1);
InsertElement(39,"Y","Yttrium",39,89,"1b",5,2);
InsertElement(40,"Zr","Zirconium",40,91,"2b",5,2);
InsertElement(41,"Nb","Niobium",41,93,"3b",5,2);
InsertElement(42,"Mo","Molybdenum",42,96,"4b",5,2);
InsertElement(43,"Tc","Technetium",43,99,"5b",5,2);
InsertElement(44,"Ru","Ruthenium",44,101,"6b",5,2);
InsertElement(45,"Rh","Rhodium",45,103,"7b",5,2);
InsertElement(46,"Pd","Palladium",46,106,"8b",5,2);
InsertElement(47,"Ag","Silver",47,108,"9a",5,2);
InsertElement(48,"Cd","Cadmium",48,112,"9b",5,2);
InsertElement(49,"In","Indium",49,115,"3",5,3);
InsertElement(50,"Sn","Tin",50,119,"4",5,3);
InsertElement(51,"Sb","Antimony",51,122,"5",5,3);
InsertElement(52,"Te","Tellurium",52,128,"6",5,4);
InsertElement(53,"I","Iodine",53,127,"7",5,4);
InsertElement(54,"Xe","Xenon",54,131,"0",5,5);
InsertElement(55,"Cs","Caesium",55,133,"1",6,1);
InsertElement(56,"Ba","Barium",56,137,"2",6,1);
InsertElement(57,"La","Lanthanum",57,139,"1b",6,2);
InsertElement(58,"Ce","Cerium",58,140,"N",0,2);
InsertElement(59,"Pr","Praseodymium",59,141,"N",0,2);
InsertElement(60,"Nd","Neodymium",60,144,"N",0,2);
InsertElement(61,"Pm","Promethium",61,145,"N",0,2);
InsertElement(62,"Sm","Samarium",62,150,"N",0,2);
InsertElement(63,"Eu","Europium",63,152,"N",0,2);
InsertElement(64,"Gd","Gadolinium",64,157,"N",0,2);
InsertElement(65,"Tb","Terbium",65,159,"N",0,2);
InsertElement(66,"Dy","Dysprosium",66,162,"N",0,2);
InsertElement(67,"Ho","Holmium",67,165,"N",0,2);
InsertElement(68,"Er","Erbium",68,167,"N",0,2);
InsertElement(69,"Tm","Thulium",69,169,"N",0,2);
InsertElement(70,"Yb","Ytterbium",70,173,"N",0,2);
InsertElement(71,"Lu","Lutetium",71,175,"N",0,2);
InsertElement(72,"Hf","Hafnium",72,178,"2b",6,2);
InsertElement(73,"Ta","Tantalum",73,181,"3b",6,2);
InsertElement(74,"W","Tungstem",74,184,"4b",6,2);
InsertElement(75,"Re","Rhenium",75,186,"5b",6,2);
InsertElement(76,"Os","Osmium",76,190,"6b",6,2);
InsertElement(77,"Ir","Iridium",77,192,"7b",6,2);
InsertElement(78,"Pt","Platinum",78,195,"8b",6,2);
InsertElement(79,"Au","Gold",79,197,"9a",6,2);
InsertElement(80,"Hg","Mercury",80,201,"9b",6,2);
InsertElement(81,"Tl","Thallium",81,204,"3",6,3);
InsertElement(82,"Pb","Lead",82,207,"4",6,3);
InsertElement(83,"Bi","Bismuth",83,209,"5",6,3);
InsertElement(84,"Po","Polonium",84,210,"6",6,3);
InsertElement(85,"At","Astatin",85,210,"7",6,4);
InsertElement(86,"Rn","Radon",86,222,"0",6,5);
InsertElement(87,"Fr","Francium",87,223,"1",7,1);
InsertElement(88,"Ra","Radium",88,226,"2",7,1);
InsertElement(89,"Ac","Actinium",89,227,"1b",7,2);
InsertElement(90,"Th","Thorium",90,232,"N",0,2);
InsertElement(91,"Pa","Protactinium",91,231,"N",0,2);
InsertElement(92,"U","Uranium",92,238,"N",0,2);
InsertElement(93,"Np","Neptunium",93,237,"N",0,2);
InsertElement(94,"Pu","Plutonium",94,242,"N",0,2);
InsertElement(95,"Am","Americium",95,243,"N",0,2);
InsertElement(96,"Cm","Curium",96,245,"N",0,2);
InsertElement(97,"Bk","Berkelium",97,245,"N",0,2);
InsertElement(98,"Cf","Californium",98,251,"N",0,2);
InsertElement(99,"Es","Einsteinium",99,254,"N",0,2);
InsertElement(100,"Fm","Fermium",100,254,"N",0,2);
InsertElement(101,"Md","Mendelevium",101,256,"N",0,2);
InsertElement(102,"No","Nobelium",102,254,"N",0,2);
InsertElement(103,"Lr","Lawrencium",103,257,"N",0,2);
}
// FUNCTION TO DISPLAY AN ELEMENT IN PERIODIC TABLE
void ATOM :: DisplayElement(int col, int row, int tAtomicNo)
{
enum MyColor {BLUE=1,GREEN,CYAN,MAGENTA=5,BROWN};
MyColor color;
if (!strcmpi(ArrAtom[tAtomicNo].GroupNo,"1") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"2"))
color = BLUE;
if (!strcmpi(ArrAtom[tAtomicNo].GroupNo,"1b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"2b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"3b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"4b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"5b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"6b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"7b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"8b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"9a") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"9b") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"N"))
color = BROWN;
if (!strcmpi(ArrAtom[tAtomicNo].GroupNo,"3") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"4") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"5") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"6") || !strcmpi(ArrAtom[tAtomicNo].GroupNo,"7"))
color = GREEN;
if (tAtomicNo==13 || tAtomicNo==31 || tAtomicNo==32 || tAtomicNo==49 || tAtomicNo==50 || tAtomicNo==51 || tAtomicNo==81 || tAtomicNo==82 || tAtomicNo==83 || tAtomicNo==84)
color = CYAN;
if (!strcmpi(ArrAtom[tAtomicNo].GroupNo,"0"))
color = MAGENTA;
textbackground(BLACK);
textcolor(color);
gotoxy(col,row);
cprintf("苘
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -