I understand that this is very lengthy and time consuming, I will gladly extend
ID: 3560179 • Letter: I
Question
I understand that this is very lengthy and time consuming, I will gladly extend time and award extra points if necessary.
This project allows the user to explore the Periodic Table of the Elements. The user can perform different search and the program provides an overview of the element's Group, Period, Atomic Number, Atomic Weight, Chemical Symbols, Chemical Names and Oxidation State(s).
The user can search by specific value or a range of values (when applicable):
A menu with options a-f should be available to the user. After the user selects an option, the element's data should be displayed as a table (clear the screen first), with table header:
GÂ Â Â Â PÂ Â Â Â ANÂ Â Â AWÂ Â Â CSÂ Â Â CNÂ Â Â OSÂ Â
The headers are explained in the following section. The program waits for the user to press a key to continue, and show the main menu again.
The computer program should comply with the commenting and formatting rules as has been done in class. For example, there should be a header for the whole program that gives the author
Explanation / Answer
#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <windows.h>
using namespace std;
using namespace System;
struct Element
{
int Atomic_Number;
int x;
int y;
string Symbol;
string Name;
double Atomic_Weight;
float Melting_Point;
float Boiling_Point;
double Density;
int Discovery_Year;
double Ionization_Energy;
int Element_Type;
int Element_State;
};
void display(vector< Element >&, int, int );
void element(int,int);
void Show_Element(vector< Element >&, int, int, int );
void welcome_screen();
void Fill_Vector(vector< Element >&, ifstream& ElementStream);
void Box(int, int, int, int, int, int, int, int, int, int);
void text(int,int);
void gotoXY(int,int);
void gotoXY(int,int,string);
void frame();
void clrscr();
void setcursor(bool visible, DWORD size);
void WaitKey();
#define ENTER 13
#define ESC 27
#define UP 72
#define LEFT 75
#define RIGHT 77
#define DOWN 80
#define on ,
enum Colors{
black,         // 0
dark_blue,     // 1
dark_green,    // 2
dark_cyan,     // 3
dark_red,      // 4
dark_magenta,  // 5
dark_yellow,   // 6
light_gray,    // 7
dark_gray,     // 8
light_blue,    // 9
light_green,   // 10
light_cyan,    // 11
light_red,     // 12
light_magenta, // 13
light_yellow,  // 14
white          // 15
};
const int width = 80, height = 30;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void main()
{
string rub(58,' ');
string shadowline(39,'Ä');
Console::SetWindowSize(width, height );
vector <Element> Number;
ifstream ElementStream;
ElementStream.open("Element_Data.txt");
Fill_Vector( Number, ElementStream);
Box(0,0,0,78,25,black on light_gray,0,0,0);
setcursor(0,0);
welcome_screen();
Sleep(1500);
Box(2,25,9,28,9,black on light_gray,0,0,0);
gotoXY(36,10,"WELCOME");
gotoXY(36,13,"TO THE");
gotoXY(33,16,"PERIODIC TABLE");
Sleep(3000);
display(Number, 13,5);
Box(2,20,12,39,8,black on light_yellow,0,0,0);
text(black on dark_cyan);
gotoXY(59,13,"e");
gotoXY(59,14,"Ä");
gotoXY(59,15,"o");
gotoXY(59,16,"Ä");
gotoXY(59,17,"v");
gotoXY(59,18,"Ä");
gotoXY(59,19," ");
gotoXY(21,20,shadowline);
for(int x=0;x<12;x++)
gotoXY(24+x*3,20,"Â");
Console::SetWindowSize(width, height );
text(black on light_yellow);
gotoXY(27,13, "Program Written Using :");
gotoXY(23,14,"Microsoft Visual C++ 2012 Express");
gotoXY(28,16,"Written By: whitenite1");
gotoXY(26,18,"Written In : December 2012");
text(black on light_gray);
gotoXY(12,28, rub);
gotoXY(22,28);
WaitKey();
}
void display(vector< Element >& Number, int x, int y)
{
string Element_Group[11] = { "Alkali Metal","Alkaline Earth Metal","Lanthanide","Actinide","Transition Metal","Basic Metal","Semi-Metal","Nonmetal","Halogen","Noble Gas","Metalloid"};
string State[4] = {"At Room Temp: Gas","At Room Temp: Liquid","At Room Temp: Solid","Artifically Prepared" };
text(black on light_gray);
int i,j, g, Num;
Box(2,8,1,63,26,black on light_cyan,2,dark_gray on light_gray);
gotoXY(30,0,"ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoXY(30,1,"µ PERIODIC TABLE Æ");
gotoXY(30,2,"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
gotoXY(12,4);
cout<<'Ú';
for (i=13;i<64;i+=3)
{
gotoXY(i,4);
cout << "ÄÄÂ";
}
cout << "ÄÄ¿";
for(j=5;j<23;j+=2)
{
gotoXY(12,j);
cout << "³ ";
gotoXY(12,j+1);
cout << "ÃÄÄ";
for (i=15;i<64;i+=3)
{
gotoXY(i,j);
cout << "³ ";
gotoXY(i,j+1);
cout << "ÅÄÄ";
}
gotoXY(66,j , "³");
gotoXY(66,j+1,"´");
}
gotoXY(12,23);
cout << '³';
gotoXY(12,24);
cout << 'À';
for (i=13;i<65;i+=3)
{
gotoXY(i,23);
cout << " ³";
gotoXY(i,24);
cout << "ÄÄÁ";
}
gotoXY(66,24);
cout << 'Ù';
gotoXY(12,18);
cout << 'À';
gotoXY(12,19);
cout << " ";
gotoXY(12,20);
cout << 'Ú';
for (i=13;i<65;i+=3)
{
gotoXY(i,18);
cout << "ÄÄÁ";
gotoXY(i,19);
cout << " ";
gotoXY(i,20);
cout << "ÄÄÂ";
}
gotoXY(66,18);
cout << 'Ù';
gotoXY(66,19);
cout << " ";
gotoXY(66,20);
cout << '¿';
gotoXY(15,4,"¿ ");
gotoXY(18,8,"´ ");
for (i=16;i<63;i++)
{
gotoXY(i,4," ");
gotoXY(i,5," ");
if(i>48 && i%3==0)
gotoXY(i,6,"Â");
}
gotoXY(63,4,"Ú");
gotoXY(18,6,"¿ ");
for (i=21;i<48;i++)
{
gotoXY(i,6," ");
gotoXY(i,7," ");
gotoXY(i,8," ");
gotoXY(i,9," ");
}
gotoXY(48,6,"Ú");
gotoXY(48,8,"Ã");
for (i=19;i<48;i++)
{
gotoXY(i,7," ");
gotoXY(i,9," ");
}
for(i=21;i<46;i+=3)
gotoXY(i,10,"Â");
gotoXY(12,20);
cout << "ÚÄÄÄÄÄÄÄÄÄ";
gotoXY(15,22);
cout << "ÄÄÄÄÄÄÄ";
gotoXY(12,24);
cout << "ÀÄÄÄÄÄÄÄÄÄ";
gotoXY(13,21);
cout<<"Lanthanides";
gotoXY(14,23);
cout<<"Actinides";
for(i=0;i<118;i++)
gotoXY(Number[i].x, Number[i].y, Number[i].Symbol);
Console::SetWindowSize(width, height );
i=x,j=y;
do
{
Box(1,22,4,22,5,dark_gray on light_yellow,2,dark_cyan on light_cyan);
text(black on light_gray);
gotoXY(12,28, "ARROWS TO SCROLL - ENTER TO SELECT ELEMENT - ESC TO EXIT.");
for(int a=0;a<118;a++)
{
gotoXY(Number[a].x,Number[a].y);
text(black on light_cyan);
cout << Number[a].Symbol;
if(i==Number[a].x && j == Number[a].y)
{
text(dark_gray on light_yellow);
gotoXY(33-(Element_Group[Number[a].Element_Type].length()/2),5,Element_Group[Number[a].Element_Type]);
gotoXY(33-(State[Number[a].Element_State].length()/2),6,State[Number[a].Element_State]);
gotoXY(33-(Number[a].Name.length()/2),7, Number[a].Name);
gotoXY(Number[a].x,Number[a].y);
text(light_red on light_cyan);
cout << Number[a].Symbol;
Num = Number[a].Atomic_Number-1;
}
}
gotoXY(i,j);
g =_getch();
switch(g)
{
case ESC:
return;
case DOWN:
{
if(j+2 <=23)
j+=2;
if(j==19)
{
if(i<25)
i=25;
j+=2;
}
break;
}
case RIGHT:
{
if(j==5 && i==13)
{
i=64;
break;
}
if((j>5 && j<=9) && i==16)
{
i=49;
break;
}
if(j>=11 || ((j>=7 && j<=9) && (i>=13 && i<16)) || ((j>=7 && j<=9) && (i>=49 && i<64)) )
{
if(i+3<=64)
i+=3;
}
break;
}
case LEFT:
{
if(j==5 && i==64)
{
i=13;
break;
}
if((j>5 && j<=9) && i==49)
{
i=16;
break;
}
if(j>=11 || ((j>=7 && j<=9) && (i>13 && i<=16)) || ((j>=7 && j<=9) && (i>49 && i<=64)) )
{
if(i-3 >=13 && j<18)
i-=3;
else
if(i-3 >=25 && j>18)
i-=3;
}
break;
}
case UP:
{
if(j>11 || ((j>7 && i>=13 && i<=16) || (j>7 && (i>=49 && i<=64) )) || i==13 && j==7 || i==64 && j==7 )
{
if(j-2 >= 5 )
j-=2;
if(j==19)
j-=2;
}
break;
}
case ENTER:
{
Show_Element(Number, Num, i, j );
}
}
} while(g!=ESC);
}
void welcome_screen()
{
clrscr();
int x;
for(x = 45;x> 24;x--)
{
Sleep(150);
gotoXY(x,11,"E L E M E N T P R O J E C T ");
gotoXY(x+3,13,"D E V E L O P E D B Y : ");
gotoXY(x+10,15,"whitenite1 ");
}
}
void Fill_Vector(vector< Element >& Number, ifstream& ElementStream)
{
Element Atomic;
Number.clear();
while( ElementStream )
{
ElementStream >> Atomic.Atomic_Number;
ElementStream >> Atomic.x;
ElementStream >> Atomic.y;
ElementStream >> Atomic.Symbol;
ElementStream >> Atomic.Name;
ElementStream >> Atomic.Atomic_Weight;
ElementStream >> Atomic.Melting_Point;
ElementStream >> Atomic.Boiling_Point;
ElementStream >> Atomic.Density;
ElementStream >> Atomic.Discovery_Year;
ElementStream >> Atomic.Ionization_Energy;
ElementStream >> Atomic.Element_Type;
ElementStream >> Atomic.Element_State;
Number.push_back(Atomic);
}
ElementStream.close();
}
void Show_Element(vector< Element >& Number, int number, int x, int y )
{
string Renew[6]={
"ÄÄÅÄÄÅÄÄÅÄÄÅÄÄ ",
" ³ ³ ³ ³ ³ ³ ",
"Ä´ ÃÄÄÅÄÄÅÄÄÅÄÄÅÄÄ",
" ´ Ã Å Å Å Å ",
"Ä´ ÃÄÄÅÄÄÅÄÄÅÄÄÅÄÄ",
"ÄÅÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄ"
};
text(black on light_gray);
string bar(6,'Ä');
string rub(57,' ');
gotoXY(12,28, rub);
gotoXY(28,28, "Press Any Key To Return....");
text(black on dark_cyan);
for (int i = 8;i<22;i+=2)
{
gotoXY(62,i,"Ä");
gotoXY(62,i+1," ");
}
gotoXY(18,22,bar);
for(int i=24;i<61;i+=3)
gotoXY(i,22,"ÅÄÄ");
string In_Shadow[]={"l","r"," ","t","s"," ","b"};
int p=0;
for(int i=9;i<=21;i+=2)
{
gotoXY(62,i);
if(x==61 && y==i) // You're viewing an element that now is in a shadow
{
text(dark_red on dark_cyan); // Print letter in dark red
cout << In_Shadow[p];
}
else
{
text(black on dark_cyan); // Otherwise, print letter in black
cout << In_Shadow[p];
}
p++;
}
Box(2, 17, 7, 45, 15,black on light_gray, 0,0,0);
gotoXY(21,8,"Element Name : ");
cout << Number[number].Name;
gotoXY(21,9,"Element Symbol : ");
if( number == 112 || number == 114 || number == 116 || number == 117)
cout << "U";
cout << Number[number].Symbol;
gotoXY(21,11,"Atomic Number : ");
cout << Number[number].Atomic_Number;
gotoXY(21,12,"Relative Atomic Mass : ");
if( Number[number].Atomic_Weight == 0)
cout << "[ Unknown ]";
else
cout << fixed << setprecision(4) << Number[number].Atomic_Weight;
cout << fixed << setprecision(0);
gotoXY(21,14,"Melting Point (Celcius) : ");
if( Number[number].Melting_Point == 0)
cout << "[ Unknown ]";
else
cout << Number[number].Melting_Point << "ø";
gotoXY(21,15,"Boiling Point (Celcius) : ");
if( Number[number].Boiling_Point == 0)
cout << "[ Unknown ]";
else
cout << Number[number].Boiling_Point << "ø";
gotoXY(21,17,"Density (g/cm^3) : ");
if( Number[number].Density == 0)
cout << "[ Unknown ]";
else
cout << fixed << setprecision(2) << Number[number].Density;
gotoXY(21,18,"Ionization Energy : ");
if( Number[number].Ionization_Energy == 0)
cout << "[ Unknown ]";
else
cout  << fixed << setprecision(4) << Number[number].Ionization_Energy;
cout << fixed << setprecision(0);
gotoXY(21,20,"Year Of Discovery : ");
if ( Number[number].Discovery_Year == 0)
cout << "Ancient Times";
else
cout << Number[number].Discovery_Year;
char key;
key=_getch();
text(black on light_cyan);
gotoXY(17,10,Renew[5]);
for( int i=11;i<18;i+=2)
{
gotoXY(17,i);
  for(int j=0;j<16;j++)
  cout << " ³ ";
gotoXY(17,i+1);
  for(int j=0;j<16;j++)
  cout << "ÄÅÄ";
}
gotoXY(17,7,Renew[1]);
gotoXY(17,8,Renew[2]);
gotoXY(17,9,Renew[1]);
gotoXY(17,18);
for(int j=0;j<16;j++)
  cout << "ÄÁÄ";
gotoXY(12,19,rub);
gotoXY(17,20,"ÄÄÄÄÄÄ");
for(int j=0;j<14;j++)
  cout << "ÄÂÄ";
gotoXY(17,21);
  for(int j=0;j<16;j++)
  cout << " ³ ";
gotoXY(17,21,"hanides");
gotoXY(17,22,"ÄÄÄÄÄÄ");
for(int j=0;j<14;j++)
  cout << "ÄÅÄ";
for(int i=3;i<118;i++)
gotoXY(Number[i].x, Number[i].y, Number[i].Symbol);
Console::SetWindowSize(width, height );
}
void Box(int style, int across, int down, int amount, int rows, int f_color, int b_color, int shadow, int shadow_fc, int shadow_bc)
{
char Shadow[4] = { ' ','°','±','²' };
char Style[5][7] = {
{' ',' ',' ',' ',' ',' ',' ' },
{' ','Ú','Ä','¿','³','À','Ù'},
{' ','É','Í','»','º','È','¼'},
{' ','Õ','Í','¸','³','Ô','¾'},
{' ','Ö','Ä','·','º','Ó','½'}
};
int x;
string BoxLine(amount-2, Style[style][2]);
string BoxBody(amount-2, ' ');
string ShadowLine(amount, Shadow[shadow]);
gotoXY(across,down);
text(f_color on b_color);
cout << Style[style][1] << BoxLine << Style[style][3];
for (x=1; x<rows; x++)
{
gotoXY(across,down+x);
cout << Style[style][4] << BoxBody << Style[style][4];
if (shadow)
{
text(shadow_fc on shadow_bc);
cout << Shadow[shadow];
text(f_color on b_color);
}
}
gotoXY(across,down+rows-1);
cout << Style[style][5] << BoxLine << Style[style][6];
if (shadow)
{
text(shadow_fc on shadow_bc);
cout << Shadow[shadow];
gotoXY(across+1,down+rows);
cout << ShadowLine;
text(f_color on b_color);
}
}
void text(int text_color on int paper_color)
{
int color = (text_color+(paper_color*16));
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color );
}
Output