Month: June 2012

  • GUI Simple Calculator Visual C++ Source : Windows Form Application

    GUI Simple Calculator Visual C++ Source : Windows Form Application

    Today let’s work around a new interesting visual C++ (cpp) calculator with Graphical User Interface (Windows Form Application). I made this source as easier as possible. You can compile the source by downloading the project source from below.

    Why is it simple calculator? It has only the basic functions of a calculator such as addition, subtraction, multiplication,division and 2 others. First Entered number is taken to the first variable a. Then select and operator, enter the second number. Do the necessary operations and When you press “=” equals button, you can see the answer right where you expect it.

    More than these basic operations, you can also find the square and square root of a number. I have added buttons for this. This program make use of “math.h” which contains “sqrt()” and “power()” functions for accomplishing these tasks.

    Visual Cpp Calculator

    Let me know your feedback in the comments.
    Use visual c++ 2010 compiler for execution.

                                                   Download Calculator Visual C++ Project

    Source……………………………Form1.h[design]

     #pragma once  
     #include<conio.h> //For_getch()_function  
     #include<math.h>  
     double ans, a, b;  
     int flag=0;  
     using namespace std;  
     namespace Calculator {  
         using namespace System;  
         using namespace System::ComponentModel;  
         using namespace System::Collections;  
         using namespace System::Windows::Forms;  
         using namespace System::Data;  
         using namespace System::Drawing;  
         /// <summary>  
         /// Summary for Form1  
         /// </summary>  
         public ref class Form1 : public System::Windows::Forms::Form  
         {  
         public:  
            Form1(void)  
            {  
                InitializeComponent();  
                //  
                //TODO: Add the constructor code here  
                //  
            }  
         protected:  
            /// <summary>  
            /// Clean up any resources being used.  
            /// </summary>  
            ~Form1()  
            {  
                if (components)  
                {  
                   delete components;  
                }  
            }  
         private: System::Windows::Forms::TextBox^ txtb;  
         private: System::Windows::Forms::Button^ button1;  
         private: System::Windows::Forms::Button^ button2;  
         private: System::Windows::Forms::Button^ button3;  
         private: System::Windows::Forms::Button^ button4;  
         private: System::Windows::Forms::Button^ button5;  
         private: System::Windows::Forms::Button^ button6;  
         private: System::Windows::Forms::Button^ button7;  
         private: System::Windows::Forms::Label^ label1;  
         private: System::Windows::Forms::MenuStrip^ menuStrip1;  
         private: System::Windows::Forms::ToolStripMenuItem^ menuToolStripMenuItem;  
         private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;  
         protected:  
         protected:  
         protected:  
         private:  
            /// <summary>  
            /// Required designer variable.  
            /// </summary>  
            System::ComponentModel::Container ^components;  
     #pragma region Windows Form Designer generated code  
            /// <summary>  
            /// Required method for Designer support - do not modify  
            /// the contents of this method with the code editor.  
            /// </summary>  
            void InitializeComponent(void)  
            {  
                System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));  
                this->txtb = (gcnew System::Windows::Forms::TextBox());  
                this->button1 = (gcnew System::Windows::Forms::Button());  
                this->button2 = (gcnew System::Windows::Forms::Button());  
                this->button3 = (gcnew System::Windows::Forms::Button());  
                this->button4 = (gcnew System::Windows::Forms::Button());  
                this->button5 = (gcnew System::Windows::Forms::Button());  
                this->button6 = (gcnew System::Windows::Forms::Button());  
                this->button7 = (gcnew System::Windows::Forms::Button());  
                this->label1 = (gcnew System::Windows::Forms::Label());  
                this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());  
                this->menuToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());  
                this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());  
                this->menuStrip1->SuspendLayout();  
                this->SuspendLayout();  
                //  
                // txtb  
                //  
                this->txtb->BackColor = System::Drawing::Color::White;  
                this->txtb->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;  
                this->txtb->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 26.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->txtb->ForeColor = System::Drawing::Color::Black;  
                this->txtb->Location = System::Drawing::Point(32, 44);  
                this->txtb->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->txtb->Name = L"txtb";  
                this->txtb->Size = System::Drawing::Size(300, 48);  
                this->txtb->TabIndex = 0;  
                this->txtb->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;  
                this->txtb->WordWrap = false;  
                this->txtb->TextChanged += gcnew System::EventHandler(this, &Form1::txtb_TextChanged);  
                //  
                // button1  
                //  
                this->button1->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button1->Location = System::Drawing::Point(32, 108);  
                this->button1->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button1->Name = L"button1";  
                this->button1->Size = System::Drawing::Size(98, 49);  
                this->button1->TabIndex = 1;  
                this->button1->Text = L"+";  
                this->button1->UseVisualStyleBackColor = true;  
                this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);  
                //  
                // button2  
                //  
                this->button2->Font = (gcnew System::Drawing::Font(L"Letterman-Solid", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button2->Location = System::Drawing::Point(234, 108);  
                this->button2->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button2->Name = L"button2";  
                this->button2->Size = System::Drawing::Size(98, 49);  
                this->button2->TabIndex = 2;  
                this->button2->Text = L"=";  
                this->button2->UseVisualStyleBackColor = true;  
                this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);  
                //  
                // button3  
                //  
                this->button3->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button3->Location = System::Drawing::Point(32, 160);  
                this->button3->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button3->Name = L"button3";  
                this->button3->Size = System::Drawing::Size(98, 49);  
                this->button3->TabIndex = 3;  
                this->button3->Text = L"-";  
                this->button3->UseVisualStyleBackColor = true;  
                this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);  
                //  
                // button4  
                //  
                this->button4->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button4->Location = System::Drawing::Point(32, 212);  
                this->button4->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button4->Name = L"button4";  
                this->button4->Size = System::Drawing::Size(98, 49);  
                this->button4->TabIndex = 4;  
                this->button4->Text = L"x";  
                this->button4->UseVisualStyleBackColor = true;  
                this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);  
                //  
                // button5  
                //  
                this->button5->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button5->Location = System::Drawing::Point(32, 264);  
                this->button5->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button5->Name = L"button5";  
                this->button5->Size = System::Drawing::Size(98, 49);  
                this->button5->TabIndex = 5;  
                this->button5->Text = L"/";  
                this->button5->UseVisualStyleBackColor = true;  
                this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);  
                //  
                // button6  
                //  
                this->button6->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button6->Location = System::Drawing::Point(234, 161);  
                this->button6->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button6->Name = L"button6";  
                this->button6->Size = System::Drawing::Size(98, 49);  
                this->button6->TabIndex = 6;  
                this->button6->Text = L"ROOT";  
                this->button6->UseVisualStyleBackColor = true;  
                this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);  
                //  
                // button7  
                //  
                this->button7->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->button7->Location = System::Drawing::Point(234, 212);  
                this->button7->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->button7->Name = L"button7";  
                this->button7->Size = System::Drawing::Size(98, 49);  
                this->button7->TabIndex = 7;  
                this->button7->Text = L"SQUARE";  
                this->button7->UseVisualStyleBackColor = true;  
                this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);  
                //  
                // label1  
                //  
                this->label1->AutoSize = true;  
                this->label1->BackColor = System::Drawing::SystemColors::HighlightText;  
                this->label1->Font = (gcnew System::Drawing::Font(L"KabobExtrabold", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->label1->Location = System::Drawing::Point(123, 3);  
                this->label1->Name = L"label1";  
                this->label1->Size = System::Drawing::Size(135, 18);  
                this->label1->TabIndex = 8;  
                this->label1->Text = L"Simple Calculator";  
                this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);  
                //  
                // menuStrip1  
                //  
                this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->menuToolStripMenuItem});  
                this->menuStrip1->LayoutStyle = System::Windows::Forms::ToolStripLayoutStyle::Flow;  
                this->menuStrip1->Location = System::Drawing::Point(0, 0);  
                this->menuStrip1->Name = L"menuStrip1";  
                this->menuStrip1->Size = System::Drawing::Size(360, 23);  
                this->menuStrip1->TabIndex = 10;  
                this->menuStrip1->Text = L"menuStrip1";  
                this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::menuStrip1_ItemClicked);  
                //  
                // menuToolStripMenuItem  
                //  
                this->menuToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->exitToolStripMenuItem});  
                this->menuToolStripMenuItem->Name = L"menuToolStripMenuItem";  
                this->menuToolStripMenuItem->Size = System::Drawing::Size(50, 19);  
                this->menuToolStripMenuItem->Text = L"Menu";  
                this->menuToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::menuToolStripMenuItem_Click);  
                //  
                // exitToolStripMenuItem  
                //  
                this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";  
                this->exitToolStripMenuItem->Size = System::Drawing::Size(92, 22);  
                this->exitToolStripMenuItem->Text = L"Exit";  
                this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::exitToolStripMenuItem_Click);  
                //  
                // Form1  
                //  
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);  
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;  
                this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));  
                this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;  
                this->ClientSize = System::Drawing::Size(360, 324);  
                this->Controls->Add(this->label1);  
                this->Controls->Add(this->button7);  
                this->Controls->Add(this->button6);  
                this->Controls->Add(this->button5);  
                this->Controls->Add(this->button4);  
                this->Controls->Add(this->button3);  
                this->Controls->Add(this->button2);  
                this->Controls->Add(this->button1);  
                this->Controls->Add(this->txtb);  
                this->Controls->Add(this->menuStrip1);  
                this->DoubleBuffered = true;  
                this->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,  
                   static_cast<System::Byte>(0)));  
                this->ForeColor = System::Drawing::Color::Black;  
                this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;  
                this->MainMenuStrip = this->menuStrip1;  
                this->Margin = System::Windows::Forms::Padding(2, 3, 2, 3);  
                this->Name = L"Form1";  
                this->Text = L"Form1";  
                this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);  
                this->menuStrip1->ResumeLayout(false);  
                this->menuStrip1->PerformLayout();  
                this->ResumeLayout(false);  
                this->PerformLayout();  
            }  
     #pragma endregion  
         private: System::Void txtb_TextChanged(System::Object^ sender, System::EventArgs^ e) {  
                   int temp;  
                          if(Int32::TryParse(txtb->Text, temp))  
                     a = float::Parse(txtb->Text);  
                }  
         private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {  
                   flag=1;  
                   b = double::Parse(txtb->Text);  
                   ans=a+b;  
                }  
     private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {  
                flag=2;  
                 b = float::Parse(txtb->Text);  
             }  
         private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {  
                   if(a==0 && b==0)  
                   {  
                       txtb->Text = "Enter Numbers";  
                   }  
                   if(flag==1)  
                   {  
                   ans=a+b;  
                       txtb->Text = Convert::ToString(ans);  
                   }  
                   else if(flag==2)  
                   {  
                      ans=b-a;  
                      txtb->Text = Convert::ToString(ans);  
                   }  
                   else if(flag==3)  
                   {  
                      ans=b*a;  
                      txtb->Text = Convert::ToString(ans);  
                   }  
                   else if(flag==4)  
                   {  
                      if(a==0)  
                      {  
                          MessageBox::Show("Divided By Zero Error");  
                      }  
                      ans=b/a;  
                      txtb->Text = Convert::ToString(ans);  
                   }  
                }  
     private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {  
                flag=3;  
                 b = double::Parse(txtb->Text);  
             }  
     private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {  
                flag=4;  
                b = double::Parse(txtb->Text);  
             }  
     private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {  
                ans=sqrt(a);  
                txtb->Text = Convert::ToString(ans);  
             }  
     private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {  
             ans=a*a;  
                txtb->Text = Convert::ToString(ans);  
             }  
     private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {  
                MessageBox::Show("Created By :nn Muhammed Afsal.vn e-mail : [email protected]");  
             }  
     private: System::Void button8_Click(System::Object^ sender, System::EventArgs^ e) {  
                a=b=0;  
             }  
     private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {  
                Application::Exit();  
             }  
     private: System::Void menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) {  
             }  
     private: System::Void menuToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {  
             }  
     private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {  
             }  
     };  
     }  
    ———————————-Calculator.cpp
    // Calculator.cpp : main project file.  
     #include "stdafx.h"  
     #include "Form1.h"  
     using namespace Calculator;  
     [STAThreadAttribute]  
     int main(array<System::String ^> ^args)  
     {  
         // Enabling Windows XP visual effects before any controls are created  
         Application::EnableVisualStyles();  
         Application::SetCompatibleTextRenderingDefault(false);  
         // Create the main window and run it  
         Application::Run(gcnew Form1());  
         return 0;  
     }  
     ———————————————————————————————————-
                                                                   Download Project

    Screen Shots :-

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

    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;
    }
    ____________________________________________________________
  • Sub shell Electron Configuration Calculator Cpp (C++) Source

    Sub shell Electron Configuration Calculator Cpp (C++) Source

    There are 118 elements in our periodic table, which is the base of science. Each element has its own characteristic properties depending upon its electronic configuration. So finding electronic configuration of elements is very important.
    Here is a C++ program for a sub shell electronic configuration calculator. By just typing the atomic number you can get the sub shell electronic configuration of the element. The sub shells are arranged in the increasing order of its energy. This is a windows console application. You can use visual C++ compiler to compile this program. You can download the C++ file and console .exe application from the link below.
    Subscribe for more cool programs and source codes.

                                                             Download Source

    ————————————————————————————————————

    #include<iostream> 
      using namespace std;
    void main()         //Starting_main_function
    {    system(“color f1”);
         cout<<“tt***************************************************n”;
            cout<<“tttElectronic configuration calculatorn”;
            cout<<“tt***************************************************n”;
            int n, s1, s2, p2, s3, p3, s4, d3, p4, s5, d4, p5, s6, f4, d5, p6, s7, f5, d6, p7;
            cout<<“n Enter atomic number :”;
            cin>>n;
            if (n<=2)
             s1=n;
            else if (n>2)
                  s1=2;
            if (n<=4 && n>=2)
             s2=n-2;
            else if (n<2)
             s2=0;
            else
             if (n>4)
                  s2=2;
            if (n<=10 && n>=4)
                  p2=(n-4);
            else if (n<4)
                  p2=0;
            else
                  if (n>10)
                  p2=6 ;
            if (n<=12 && n>=10)
                  s3=n-10;
            else if (n<10)
                  s3=0;
            else
                  if (n>12)
                  s3=2;
            if (n<=18 && n>=12)
                  p3=n-12;
            else if (n<12)
                  p3=0;
            else
                  if (n>18)
                  p3=6;
            if (n<=20 && n>=18)
                  s4=n-18;
            else if (n<18)
                   s4=0;
            else
                  if(n>20)
                  s4=2;
            if (n<=30 && n>=20)
                  d3=n-20;
            else if (n<20)
                  d3=0;
            else
                  if (n>30)
                  d3=10;
            if (n<=36 && n>=30)
                  p4=n-30;
            else if (n<30)
                  p4=0;
            else
                  if(n>36)
                  p4=6;
            if (n<=38 && n>=36)
                  s5=n-36;
            else if (n<36)
                  s5=0;
            else
                  if(n>38)
                  s5=2;
            if (n<=48 && n>=38)
                  d4=n-38;
            else if (n<38)
                  d4=0;
            else
                  d4=10;
            if (n<=54 && n>=48)
                  p5=n-48;
            else if (n<48)
                  p5=0;
            else
                  if (n>54)
                  p5=6;
            if (n<=56 && n>=54)
                  s6=n-54;
            else if (n<54)
                  s6=0;
            else
                  if (n>56)
                  s6=2;
            if (n<=70 &&  n>=56)
                  f4=n-56;
            else if (n<56)
                  f4=0;
            else
                  if(n>70)
                  f4=14;
            if (n<=80 && n>=70)
                  d5=n-70;
            else if (n<70)
                  d5=0;
            else
                  if (n>80)
                  d5=10;
            if (n<=86 && n>=80)
                  p6=n-80;
            else if (n<80)
                  p6=0;
            else
                  p6=6;
            if (n<=88 && n>=86)
                  s7=n-86;
            else if (n<86)
                  s7=0;
            else
                  if(n>88)
                  s7=2;
            if(n<=102 && n>=88)
                  f5=n-88;
            else if (n<88)
                  f5=0;
            else
                  if (n>102)
                  f5=14;
            if (n<=112 && n>=102)
                  d6=n-102;
            else if (n<102)
                  d6=0;
            else
                   if(n>112)
                   d6=10;
            if (n<=118 && n>=112)
                  p7=n-112;
            else if (n<112)
                  p7=0;
            else
                  if (n>118)
                  p7=6;
          
                  cout<<“nn 1s: “<<s1<<“n 2s: “<<s2<<“n 2p: “<<p2<<“n 3s :”<<s3<<“n 3p :”<<p3<<“n 4s :”<<s4;
                  cout<<“n 3d :”<<d3<<“n 4p :”<<p4<<“n 5s :”<<s5<<“n 4d :”<<d4<<“n 5p :”<<p5<<“n 6s :”<<s6<<“n 4f :”<<f4;
                  cout<<“n 5d :”<<d5<<“n 6p :”<<p6<<“n 7s :”<<s7<<“n 5f :”<<f5<<“n 6d :”<<d6<<“n 7p :”<<p7;
                  cout<<“nnnnn”;
                  system(“pause”);       //For_waiting_program_exit_until_a_character_entered
    return;
    }    //Main_function_Completed
    ————————————————————————————————————
                                                                Download Source

    Screen Shots

    Screen Shot 1
    Screen Shot 2

    Periodic Table

    roup → 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    ↓ Period
    1 1
    H
    2
    He
    2 3
    Li
    4
    Be
    5
    B
    6
    C
    7
    N
    8
    O
    9
    F
    10
    Ne
    3 11
    Na
    12
    Mg
    13
    Al
    14
    Si
    15
    P
    16
    S
    17
    Cl
    18
    Ar
    4 19
    K
    20
    Ca
    21
    Sc
    22
    Ti
    23
    V
    24
    Cr
    25
    Mn
    26
    Fe
    27
    Co
    28
    Ni
    29
    Cu
    30
    Zn
    31
    Ga
    32
    Ge
    33
    As
    34
    Se
    35
    Br
    36
    Kr
    5 37
    Rb
    38
    Sr
    39
    Y
    40
    Zr
    41
    Nb
    42
    Mo
    43
    Tc
    44
    Ru
    45
    Rh
    46
    Pd
    47
    Ag
    48
    Cd
    49
    In
    50
    Sn
    51
    Sb
    52
    Te
    53
    I
    54
    Xe
    6 55
    Cs
    56
    Ba
    * 72
    Hf
    73
    Ta
    74
    W
    75
    Re
    76
    Os
    77
    Ir
    78
    Pt
    79
    Au
    80
    Hg
    81
    Tl
    82
    Pb
    83
    Bi
    84
    Po
    85
    At
    86
    Rn
    7 87
    Fr
    88
    Ra
    ** 104
    Rf
    105
    Db
    106
    Sg
    107
    Bh
    108
    Hs
    109
    Mt
    110
    Ds
    111
    Rg
    112
    Cn
    113
    Uut
    114
    Fl
    115
    Uup
    116
    Lv
    117
    Uus
    118
    Uuo
    Lanthanides 57
    La
    58
    Ce
    59
    Pr
    60
    Nd
    61
    Pm
    62
    Sm
    63
    Eu
    64
    Gd
    65
    Tb
    66
    Dy
    67
    Ho
    68
    Er
    69
    Tm
    70
    Yb
    71
    Lu
    ** Actinides 89
    Ac
    90
    Th
    91
    Pa
    92
    U
    93
    Np
    94
    Pu
    95
    Am
    96
    Cm
    97
    Bk
    98
    Cf
    99
    Es
    100
    Fm
    101
    Md
    102
    No
    103
    Lr
  • Student Record C++(cpp) Source Code Windows Console Application

    Student Record C++(cpp) Source Code Windows Console Application

    Let’s have a look at C++ source code for a student record program developed for windows console mode. You can test this code using Microsoft visual C++ compiler without any issues. I believe this sample code will help you to understand some of the basic C++ functions.
    This is a menu driven program. You can add a student, get a student’s mark by entering his roll number, get a student’s details or print a table of all student’s details. This program creates a “student.dat” file at the current directory (The path at which the executable located) to save details that you have entered. During the next execution of the program the data present in the file is taken in to the memory. For deleting all existing data, you can use ’99’ command in main menu. It just delete existing file and create a new one having no records, simply a blank file.

    ……………………………………………………………………………………………………………………………………….

    #include<iostream>
    #include<windows.h> //for_sleep()_function
    #include<iomanip> // for_setwidth_function
    #include<fstream>
    #include<process.h> //For_exit(0)
    #include<conio.h>  //for_getch()
    #include<string.h>
    #include<stdio.h> //for_gets()
      int k=0, sys, str,high=60;   //For_student_object_handling
      using namespace std;
    class person
    {
    protected:
    
           char sex;
    
           int age;
    
           int count;
    
           char name[50];
    
    public:
    
           int length;
    
           void readperson()
    
           {
    
                  system("CLS");
    
               cout<<"tt************************************************";
    
               cout<<"nttttADD A NEW STUDENT ";
    
               cout<<"ntt************************************************";
    
                  cout<<"nn Good name please (Don't Use space; use '_') :";
    
                  cin>>name;
    
                  cout<<"n Please Enter your age :";
    
                  cin>>age;
    
                  cout<<"n Sex ? (M/F) :";
    
                  cin>>sex;
    
           }
    
    };
    
    class student:public person     //This_class_student_is_inherited_from_class_person.
    
    {
    
    protected:
    
           int roll;
    
           int avmark;
    
    public:
    
      void readstudent()
    
      {
    
             cout<<"nn Enter your Roll Number :";cin>>roll;
    
             cout<<"n Enter Your Average Mark( Out of hundred ) :";cin>>avmark;
    
      }
    
      int getroll()           
    
      {
    
             return(roll);
    
      }
    
      void getdetails()
    
      {
    
             cout<<"nn Name  :"<<name;
    
             cout<<"n Sex   :"<<sex;
    
             cout<<"n Age   :"<<age;
    
             cout<<"n Roll  :"<<roll;
    
             cout<<"n Mark  :"<<avmark;
    
      }
    
      void GetDetailsTable() //For_making_table_arrangement_of_students;
    
      {    high--;
    
              if(str<=7)          //For_maintaining_the_exact_form; One_extra_t_is_used_after_name;
    
                  cout<<"ntt"<<name<<"tt"<<sex<<"t"<<age<<"t"<<roll<<"t"<<avmark<<"n";
    
              else
    
               cout<<"ntt"<<name<<"t"<<sex<<"t"<<age<<"t"<<roll<<"t"<<avmark<<"n";
    
     }
    
      int getmark()
    
      {
    
             return(avmark);
    
      }
    
      void prtname()
    
      {
    
             cout<<name;
    
      }
    
      char GetSex()
    
      {
    
             return sex;
    
      }
    
    
    }stu[61];// Class_Defnition_completed
    
    
    void main()        //Beggining_main_function_HERE
    
    
    {  
    
           void SortBySex();
    
           void SortItOnMark();
    
           void SortItOnRoll() ;
    
           ofstream fout;
    
           ifstream fin;
    
           start:                    //For_returning_into_main_menu
    
           fin.close();
    
           fout.close();
    
           fin.open("student.dat", ios::app|ios::binary|ios::in);
    
           int num=0; //Making_input_buffer_zero_after_function_returning_through_start:
    
           while(fin) // Taking Student details into memory
    
           {     
    
               fin.read((char *)&stu[num], sizeof(stu[num]));
    
                  ++num;
    
           }
    
                        //File_input_completed !
    
           sys=num-1;
    
           int p1=100, p2=50;
    
           system("color f1");
    
           int k, Ru, rank(0), rankm(0);
    
           system("CLS");
    
           cout<<"tt************************************************";
    
           cout<<setw(62)<<"MAIN MENU";
    
           cout<<"ntt************************************************";
    
           cout<<"nnn 1.Student Details"<<"n 2.Best Student"<<"n 3.Get Mark"<<"n 4.Add a new student"<<"n 5.View all students"<<"n 6.Exittttttttt99.Reset all!!!"<<"nnn Enter your selection :";
    
           cin>>k;
    
           switch(k)
    
           {  //switch_starts
    
           case 1:system("cls");
    
                  int flag;
    
                  flag=0;
    
               cout<<"tt************************************************";
    
               cout<<"nttttSTUDENT DETAILS";
    
               cout<<"ntt************************************************";
    
                  cout<<"nnEnter Roll Number :";
    
                     cin>>Ru;
    
                     for (int i=0; i<60;++i)
    
                     {
    
                     if (stu[i].getroll()==Ru)
    
                               {
    
                                      flag=1;
    
                                      stu[i].getdetails();
    
                             }
    
                     }
    
                         if (!flag)
    
                         cout<<"nnnnSorry...I cannot find a student with this roll number !";
    
                      cout<<"nnnnnPress Any key.............";
    
                         if(_getch())
    
                          goto start;
    
                        
    
           case 2:system("cls");
    
                  cout<<"tt************************************************";
    
               cout<<"nttttTHE BEST STUDENT ";
    
               cout<<"ntt************************************************";
    
                  cout<<"nn Best Student is :";
    
                     for (int i=0; i<60; ++i)
    
                     {
    
                                                 
    
                            if (stu[i].getmark()>rankm)
    
                            {
    
                                  rankm=stu[i].getmark();
    
                                  rank=i;
    
                            }
    
                     }
    
                     stu[rank].getdetails();
    
                     cout<<"nnnnnPress Any key.............";
    
                         if(_getch())
    
                          goto start;
    
           case 3:system("cls");
    
                  flag=1;
    
               cout<<"tt************************************************";
    
               cout<<"nttttGET THE MARK ";
    
               cout<<"ntt************************************************";
    
                  cout<<"nnnPlease Enter Roll Number :";
    
                  cin>>Ru;
    
                     for (int i=0; i<60;++i)
    
                     {
    
                            if (stu[i].getroll()==Ru)
    
                               {
    
                                      flag=0;
    
                                      cout<<"nnn Mark of ";stu[i].prtname();cout<<" is "<<stu[i].getmark();
    
                             }
    
                     }
    
                     if(flag)
    
                             cout<<"nnttSorry....No Such students; Try again !";               
    
               if(_getch())   //wait_for_any_input_via_keyboard
    
                      goto start;
    
                  break;
    
           case 4:               //Add_student_menu
    
                     stu[k].readperson();
    
                     stu[k].readstudent();
    
                         fout.open("student.dat", ios::out|ios::binary|ios::app);
    
                         fout.write((char*)&stu[k], sizeof(student));
    
                         cout<<"nnntttFile saving accomplsihed !Please Restart this program ";
    
                      fout.close();
    
                         fin.close();
    
                         cout<<"nnnnnn";
    
                         Sleep(2500);
    
                         goto start;
    
          
    
                         break;
    
           case 5:   // View_all_students_table
    
                  system("CLS");
    
                  int count, selection;
    
                  char answer;
    
                  answer='n';
    
                  count=0;
    
                  cout<<sys;
    
                  cout<<"tt************************************************";
    
               cout<<"nttNamettSextAgetRolltMarkn";
    
               cout<<"tt************************************************";
    
                  while (count<sys)
    
                  {
    
                         stu[count].GetDetailsTable();
    
                   count++;
    
                  }
    
                  cout<<"nnttDo you want to sort it now ? (y/n) :";
    
                  cin>>answer;
    
                  if(answer=='y'||answer=='Y')
    
          {     
    
                         cout<<"n Sort By :nt1. Marknttt2.Rollnttttt3.By Sexnn";
    
                      cout<<"Enter :";
    
                         cin>>selection;
    
                    switch(selection)
    
                      {
    
                     case 1: SortItOnMark();break;
    
                        case 2: SortItOnRoll();break;
    
                        case 3: SortBySex();break;
    
                      default :cout<<"nBad Input !";
    
                      }
    
                  }
    
                  else
    
                         goto start;
    
               cout<<"nnnn";system("pause");
    
                  goto start;
    
           case 6 : //Exit_Function
    
                  system("CLS");
    
                  fin.close();
    
                  fout.close();
    
                  cout<<"nnnttt BYE !!!!!!!!!!!!!!!!!!!!!";
    
                  Sleep(1000);   //wait_1_second_before_exiting
    
                  exit(0);
    
                  break;
    
    
    case 99 :
    
                   // File-reset_option_begins
    
                  char ans;
    
                  system("CLS");
    
                  cout<<" You have choosen to delete all the user data from this program !.nnCaution :You cannot back up your data !nnFor further reference make a copy of file (student.dat) from source folder !";
    
                  cout<<"nn Are you sure want to erase all (y/n)? :";
    
                  cin>>ans;
    
                  if (ans=='y'||ans=='Y')
    
                  {
    
            ofstream fout;
    
                  fout.open("student.dat", ios::out,ios::binary);
    
                  cout<<"nnna"<<"taa Task accomplished Successfully !";
    
                  }
    
                  else
    
                         cout<<"nn"<<"atTask aborted, Now returning to main menu";
    
                      Sleep(2500);
    
                         goto start;
    
                  //File_reset_accomplished 
    
    
           default : system("CLS");
    
                        cout<<"annntttBad input Recieved ! Try Again";
    
                        Sleep(1000);
    
                           goto start;
    
                           break;
    
    
    } //switch ended
    
            
    
    return;
    
    
    } // Main()_over
    
    
    void SortItOnRoll()   //Student_Details_table_sorted_on_mark
    
    {  
    
           high=60;
    
        int car=sys;
    
           cout<<"tt************************************************";
    
           cout<<"nttNamettSextAgetRolltMarkn";
    
           cout<<"tt************************************************n";
    
           int first=0, place;
    
           while(car)
    
           {first=0;
    
           for(int t=0; t<(high); ++t)
    
           {
    
                  if(first<=stu[t].getroll())
    
                  {
    
                         first=stu[t].getroll();
    
                      place=t;
    
                  }
    
           }
    
           stu[place].GetDetailsTable();
    
           stu[place]=stu[high];
    
           car--;
    
       }
    
    }          //Function_completed
    
    void SortItOnMark()   //Student_Details_table_sorted_on_mark
    
    {  
    
           high=60;
    
        int car=sys;
    
           cout<<"tt************************************************";
    
           cout<<"nttNamettSextAgetRolltMarkn";
    
           cout<<"tt************************************************n";
    
           int first=0, place;
    
           while(car)
    
           {first=0;
    
           for(int t=0; t<(high); ++t)
    
           {
    
                  if(first<=stu[t].getmark())
    
                  {
    
                         first=stu[t].getmark();
    
                      place=t;
    
                  }
    
           }
    
           stu[place].GetDetailsTable();
    
           stu[place]=stu[high];
    
           car--;
    
       }
    
    }          //Function_completed
    
    
    void SortBySex()   //Student_Details_table_sorted_on_Sex
    
    {  
    
           high=60;
    
        int car=sys;
    
           cout<<"tt************************************************";
    
           cout<<"nttNamettSextAgetRolltMarkn";
    
           cout<<"tt************************************************n";
    
           for(int t=0; t<sys; ++t)
    
           {
    
                  if(stu[t].GetSex()=='f'||stu[t].GetSex()=='F')
    
                  {
    
                         stu[t].GetDetailsTable();
    
                  }
    
                  else continue;
    
           }
    
           cout<<endl;
    
           for(int t=0; t<sys; ++t)
    
           {
    
                  if(stu[t].GetSex()=='m'||stu[t].GetSex()=='M')
    
                  {
    
                         stu[t].GetDetailsTable();
    
                  }
    
                  else continue;
    
           }
    
    
    }          //Function_completed
    ………………………………………………………………………………………………………………………………………………

    Download Source Now

    Screenshots

    MENU
    Student Table

    Suggested Read : C++ Library Management Program with Source Code