Posts

Showing posts from March, 2017

How to programmatically compile code using C# compiler

How to programmatically compile code using C# compiler Create a new Visual C# .NET Windows application. Form1 is created by default. Add a  Button  control to Form1, and then change its  Text  property to  Build . Add another  Button  control to Form1, and then change its  Text  property to  Run . Add two  TextBox  controls to Form1, set the  Multiline property  for both controls to  True , and then size these controls so that you can paste multiple lines of text into each one. In the code editor, open the Form1.cs source file. In the  Form1  class, Write button click handler(In Ex Pgm) In Form1.cs, locate the Form1 constructor. After the call to InitializeComponent in the Form1 constructor, add the following code to wire the button click handler to both buttons that you added to Form1. Run the project. After Form1 loads, click the  Build  button. Notice that you get a compiler error. Next, copy the following text into the textbox, replacing any existing text: using S

Operator Overloading in C++

Operator Overloading in C++ In C++, we can make operators to work for user defined classes. For example, we can overload an operator ‘+’ in a class like String so that we can concatenate two strings by just using +. Other example classes where arithmetic operators may be overloaded are Complex Number, Fractional Number, Big Integer, etc. A simple and complete example #include<iostream> using namespace std;   class Complex { private :      int real, imag; public :      Complex( int r = 0, int i =0)  {real = r;   imag = i;}             // This is automatically called when '+' is used with      // between two Complex objects      Complex operator + (Complex const &obj) {           Complex res;           res.real = real + obj.real;           res.imag = imag + obj.imag;           return res;      }      void print() { cout << real << " + i" << imag << endl; } };   int main()