Energy – mass Converter program c++ (cpp) source

This is a Simple C++ code for a converter program that converts energy into mass according to the famous equation from greatest scientist Albert Einstein. E= MC2
Input energy in MeV( Mega electron volt), GeV( Giga electron volt) or in  Tev( Tera electron volt).
You can use visual c++ compiler for compiling and running program. You can find the Source code below. if you are using Borland turbo C++ don’t use “using namespace std;” and insert .h extension for iostream, iomanip header files. Moreover, it will not support  “system(“CLS”);” and replace it by “clrscr();”
 
E= MC2: –
E = Energy
M = Mass
C = speed of light in vacuum (299792458 m/s)
Let’s imagine the practical use of this equation. Consider just a stone, which weigh 250g. If you convert it completely into energy, then the total energy from the mass;
E = 0.250(kg) x 89875517873681764 (c x c)
   = 22468879468420441 J
#include<iostream>
#include<Windows.h>//for_sleep()
#include<iomanip>
#include<process.h>  //for_exit()_function;
#include<conio.h>
    using namespacestd; 
void main()
{   system(“color f1”);   //making_colour_combinations
       double consteV=1.60219e-19;
       double constc2=9*10e16;   //c^2;
       int ch;   //for_input
       double e, mass;
       start:    //For_returning_into_main_menu
    system(“CLS”);
       cout<<“tt***********************************************n”;
       cout<<“tt   ENERGY – MASS CONVERTER : UNIT CHOICE MENUn”;
       cout<<“tt***********************************************n”;
       cout<<“nn 1. MeV (Mega Electrone Volts)n 2. GeV (Giga electrone volts)n 3. TeV (Tera Electrone Volts) n 4. Exit”;
       cout<<“nn Please Enter Your Choice :”;
       cin>>ch;
       system(“CLS”);    //Clear_screen_command
       switch(ch)
        {
              case 1:
                         cout<<“ntt     ENERGY-MASS CONVERTER ( E = mc^2 )”;
                         cout<<“nnnnPlease enter energy in MeV :”;
                         cin>>e;
                         e=e*10e6*eV;          // Energy Converted into Joules
                         mass=e/c2;
                         cout<<“nnntttMass = “<<setprecision(10)<<mass<<” Kilograms”;
                             break;
              case 2:
                        cout<<“tttENERGY-MASS CONVERTER ( E = mc^2 )”;
                        cout<<“nnnnPlease enter energy in GeV :”;
                        cin>>e;
                        e=e*10e9*eV;          // Energy Converted into Joules
                        mass=e/c2;
                        cout<<“nnntttMass = “<<setprecision(10)<<mass<<” Kilograms”;
                             break;
              case 3:
                         cout<<“tttENERGY-MASS CONVERTER ( E = mc^2 )”;
                         cout<<“nnnnPlease enter energy in TeV :”;
                         cin>>e;
                         e=e*10e12*eV;          // Energy Converted into Joules
                         mass=e/c2;
                         cout<<“nnntttMass = “<<setprecision(10)<<mass<<” Kilograms”;
                             break;
              case 4 : system(“CLS”);
                          cout<<“nnttttThank you………..”;
                            Sleep(1000);
                            exit(0);
              default: cout<<“naInvalid Choice !….nnPlease Try again.”;
                                  break;
        }                                              // End of switch
       if(_getch())       //wait_for_any_input_through_keyboard
         goto start;
return;
}
____________________________________________________________
Muhammed Afsal Villan
Muhammed Afsal Villan is an experienced full-stack developer, specialized in desktop and mobile application development. He also regularly publishes quality tutorials on his YouTube channel named 'Genuine Coder'. He likes to contribute to open-source projects and is always enthusiastic about new technologies.

5 COMMENTS