Pages

Saturday, April 4, 2015

Matrices Multiplication Using 2D Arrays In C++

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
//note that for multiplication the columns of first matrix should be equal to rows of second matrix.

//rows1=rows of first matrix and col1=column of first matrix and vice versa.

int rows1,col1,rows2,col2;
int array1[50][50],array2[50][50],product[50][50];
cout<<"Enter number of rows forfirstmatrix:";
cin>>rows1;
cout<<"\n   Enter number of columns for first matrix : ";
cin>>col1;
cout<<"\n   Entering values in first matrix :-";
cout<<endl;
for(int i=0;i<rows1;i++)
{
for(int j=0;j<col1;j++)
{
cout<<"\n   Enter value : ";
cin>>array1[i][j];
}
}
cout<<"\n   First matrix is :";
cout<<endl<<endl;
//"rowsFm" means rows of first matrix, "colFm" means cloumns of first matrix and vice versa.
for(int rowsFm=0;rowsFm<rows1;rowsFm++)
{
for(int colFm=0;colFm<col1;colFm++)
{
cout<<"\t"<<array1[rowsFm][colFm];
}
cout<<endl<<endl;
}
cout<<"\n   Enter number of rows for second matrix : ";
cin>>rows2;
cout<<"\n   Enter number of columns for second matrix : ";
cin>>col2;
cout<<"\n   Entering values in second matrix :-";
cout<<endl;
for(int k=0;k<rows2;k++)
{
for(int l=0;l<col2;l++)
{
cout<<"\n   Enter value :  ";
cin>>array2[k][l];
}
}
cout<<"\n   Second matrix is :";
cout<<endl<<endl;
for(int rowsSm=0;rowsSm<rows2;rowsSm++)
{
for(int colSm=0;colSm<col2;colSm++)
{
cout<<"\t"<<array2[rowsSm][colSm];
}
cout<<endl<<endl;
}
cout<<"\n   The product of matrices is :-";
cout<<endl<<endl;
if(col1==rows2)
{
for(int a=0;a<rows1;a++)
{
for(int b=0;b<col2;b++)
{
product[a][b]=0;
for(int c=0;c<rows2;c++)
{
product[a][b]=product[a][b]+array1[a][c]*array2[c][b];
}
}
}
for(int d=0;d<rows1;d++)
{
for(int e=0;e<col2;e++)
{
cout<<"\t"<<product[d][e];
}
cout<<endl<<endl;
}
}
else 
{
cout<<"\n   Product is not possible.";
}
getch();
}

Friday, April 3, 2015

How To Add Two complex Numbers Using C++ class

#include <iostream>
#include <conio.h>
using namespace std;
class complex
{
public :
int real, img;
};
int main()
{
complex a, b, c;
cout << "Enter a and b where a + ib is the first complex number.";

 cout << "\na = ";
 cin >> a.real;
cout << "b = "; cin >> a.img;
cout << "Enter c and d where c + id is the second complex number.";

 cout << "\nc = "; 
 cin >> b.real;
cout << "d = ";

 cin >> b.img;
c.real = a.real + b.real;
c.img = a.img + b.img;
if ( c.img >= 0 )
cout << "Sum of two complex numbers = " << c.real << " + " << c.img << "i"; 

 else
 cout << "Sum of two complex numbers = " << c.real << " " << c.img << "i";
 return 0; 
}

Friday, March 13, 2015

Selection Sorting in C++

#include<iostream>
#include<conio.h>
using namespace std;

void selectionSort(int numbers[], int array_size) //function for sorting

   int i, j, T, min; 
   for (i = 0; i < array_size; i++) 

      min = i; 
      for (j = i + 1; j < array_size; j++)
 { 
         if (numbers[j] < numbers[min])
 { 
            min = j; 

      } 
      T = numbers[min]; 
      numbers[min] = numbers[i]; 
      numbers[i] = T; 
 cout<<numbers[i]<<"  ";
 
    } 
   


void main()
{
int numbers[5]={5,3,1,2,4};
int b=5;

cout<<"selection sorting : ";
selectionSort(numbers,b);
cout<<"  ";

getch();
}

Wednesday, January 28, 2015

C++ class program to perform rational number arithmetic Operations using Operator Overloading

#include<stdio.h>          
 #include<iostream.h>
 #include<conio.h>
 class rational
 {
                 int numer;
                 int denom;
                 public:
                 void getdata()
                 {
                                 cout<<"\n enter the numerator part of the rational no.";
                                 cin>>numer;
                                 cout<<"\n enter the denominator part of the rational no.";
                                 cin>>denom;
                 }
                 void operator+(rational);
                 void operator-(rational);
                 void operator *(rational);
                 void operator /(rational);
 };
 void rational ::operator+(rational c1)
 {
                 rational temp;
                 temp.numer=(numer*c1.denom)+(c1.numer*denom);
                 temp.denom=denom*c1.denom;
                 cout<<"\nrational no. after addition";
                 cout<<"\n numerator="<<temp.numer<<"\n denominator ="<<temp.denom;
 }
 void raional ::operator -(rational c1)
 {
                 rational temp;
                 temp.numer=(numer*c1.denom)-(c1.numer*denom);
                 temp.denom=denom*c1.denom;
                 cout<<"\n rational no. after subtraction";
                 cout<<"\n numerator="<<temp.numer<,"\n denominator ="<<temp.denom;
 }
 void rational ::operator (rational c1)
 {
                 rational temp;
                 temp.numer=numer*c1.numer;
                 temp.denom=denom*c1.denom;
                 cout<<"\n rational no. after multiplication";
                 cout <<"\n numerator="<temp.numer<<"\n denominator ="<< temp.denom;
 }
 void rational :: operator /(rational c1)
 {
                 rational temp;
                 temp.numer= numer*c1.denom;
                 temp.denom=c1.numer*denom;
                 cout<<"\n rational no. after division";
                 cout <<"\n numerator="<<temp.numer<<"\n denominator ="<<temp.denom;
 }
 void main()
 {
                 clrscr();
                 rational c1, c2;
                 int n;
                 do
                 {
                                 cout<<"\n 1.Input data for rational no. ";
                                 cout<<"\n 2. Addition of rational no. ";
                                 cout<<"\n 3. Subtraction of rational no. ";
                                 cout<<"\n 4. Multiplication of rational no.";
                                 cout<<\n  5. Division of rational no. ";
                                 cout<<"\n 6. Quit";
                                 cout<<"\n Enter your choice";
                                 cin>>n;
                                 switch(n)
                                 {
                                                 case 1:
                                                 cout<<endl<<"\n enter the data for first rational no.";
                                                 c1.getdata();
                                                 cout<<endl<<"\n enter the data for second rational no. ";
                                                 c2.getdata ();
                                                 clrscr();
                                                 break;
                                                 case 2;
                                                 c1+c2;
                                                 getch();
                                                 clrscr();
                                                 break;
                                                 case 3;
                                                 c1-c2;
                                                 getch();
                                                 clrscr();
                                                 case 4:
                                                 c1*c2;
                                                 getch();
                                                 clrscr();
                                                 break;
                                                 case 5:
                                                 c1/c2;
                                                 getch();
                                                 clrscr();
                                                 break;
                                                 case 6:
                                                 exit(1);
                                                 break;
                                 }
                 } while (n!=6);
                 getch();
 }


Thursday, January 1, 2015

Operator Overloading in C++ to add,substract,multiply and divide two Complex Numbers

Operator Overloading is a technique of polymorphism by which an operator(+,- etc) can be used to do different types of operations. eg:+ can be used to add two integers say a and b using sum=a+b similarly two floating point numbers say fa,fb by fs=fa+fb. In this example +,-,*,- operators are overloaded to add,subtract, multiply and divide two complex numbers. 

#include<iostream.h> 
 #include<conio.h> 
 class complex 
 { 
 int a,b; 
 public: 
 void read() 
 { 
 cout<<"\n\nEnter the REAL PART : "; 
 cin>>a; 
 cout<<"\n\nEnter the IMAGINARY PART : "; 
 cin>>b; 
 } 
 complex operator +(complex c2) 
 { 
 complex c3; 
 c3.a=a+c2.a; 
 c3.b=b+c2.b; 
 return c3; 
 } 
 complex operator -(complex c2) 
 { 
 complex c3; 
 c3.a=a-c2.a; 
 c3.b=b-c2.b; 
 return c3; 
 } 
 complex operator *(complex c2) 
 { 
 complex c3; 
 c3.a=(a*c2.a)-(b*c2.b); 
 c3.b=(b*c2.a)+(a*c2.b); 
 return c3; 
 } 
 complex operator /(complex c2) 
 { 
 complex c3; 
 c3.a=((a*c2.a)+(b*c2.b))/((c2.a*c2.a)+(c2.b*c2.b)); 
 c3.b=((b*c2.a)-(a*c2.b))/((c2.a*c2.a)+(c2.b*c2.b)); 
 return c3; 
 } 
 void display() 
 { 
 cout<<a<<"+"<<b<<"i"; 
 } 
 }; 
 void main() 
 { 
 complex c1,c2,c3; 
 int choice,cont; 
 do 
 { 
 clrscr(); 
 cout<<"\t\tCOMPLEX NUMBERS\n\n1.ADDITION\n\n2.SUBTRACTION\n\n3.MULTIPLICATION\n\n4.DIVISION"; 
 cout<<"\n\nEnter your choice : "; 
 cin>>choice; 
 if(choice==1||choice==2||choice==3||choice==4) 
 { 
 cout<<"\n\nEnter the First Complex Number"; 
 c1.read(); 
 cout<<"\n\nEnter the Second Complex Number"; 
 c2.read(); 
 } 
 switch(choice) 
 { 
 case 1     : c3=c1+c2; 
            cout<<"\n\nSUM = "; 
            c3.display(); 
            break; 
 case 2     : c3=c1-c2; 
            cout<<"\n\nResult = "; 
            c3.display(); 
            break; 
 case 3 : c3=c1*c2; 
            cout<<"\n\nPRODUCT = "; 
            c3.display(); 
            break; 
 case 4     : c3=c1/c2; 
            cout<<"\n\nQOUTIENT = "; 
            c3.display(); 
            break; 
 default     : cout<<"\n\nUndefined Choice"; 
 } 
 cout<<"\n\nDo You Want to Continue?(1-Y,0-N)"; 
 cin>>cont; 
 }while(cont==1); 
 getch(); 
 }  




Monday, December 29, 2014

“Smart” Software Can Be Tricked into Seeing What Isn’t There


A technique called deep learning has enabled Google and other companies to make breakthroughs  in getting computers to understand the content of photos. Now researchers at Cornell University and the University of Wyoming have shown how to make images that fool such software into seeing things that aren’t there.The researchers can create images that appear to a human as scrambled nonsense or simple geometric patterns, but are identified by the software as an everyday object such as a school bus. The trick images offer new insight into the differences between how real brains and the simple simulated neurons used in deep learning process images.Researchers typically train deep learning software to recognize something of interest—say, a guitar—by showing it millions of pictures of guitars, each time telling the computer “This is a guitar.” After a while, the software can identify guitars in images it has never seen before, assigning its answer a confidence rating. It might give a guitar displayed alone on a white background a high confidence rating, and a guitar seen in the background of a grainy cluttered picture a lower confidence rating  (see “10 Breakthrough Technologies 2013: Deep Learning”).That approach has valuable applications such as facial recognition, or using software to process security or traffic camera footage, for example to measure traffic flows or spot suspicious activity.But although the mathematical functions used to create an artificial neural network are understood individually, how they work together to decipher images is unknown. “We understand that they work, just not how they work,” says Jeff Clune, an assistant professor of computer science at the University of Wyoming. “They can learn to do things that we can’t even learn to do ourselves.”To shed new light on how these networks operate, Clune’s group used a neural network called AlexNet that has achieved impressive results in image recognition. They operated it in reverse, asking a version of the software with no knowledge of guitars to create a picture of one, by generating random pixels across an image.The researchers asked a second version of the network that had been trained to spot guitars to rate the images made by the first network. That confidence rating was used by the first network to refine its next attempt to create a guitar image. After thousands of rounds of this between the two pieces of software, the first network could make an image that the second network recognized as a guitar with 99 percent confidence.However, to a human, those “guitar” images looked like colored TV static or simple patterns. Clune says this shows that the software is not interested in piecing together structural details like strings or a fretboard, as a human trying to identify something might be. Instead, the software seems to be looking at specific distance or color relationships between pixels, or overall color and texture.Ryan Adams, an assistant computer science professor at Harvard, says the results aren’t  completely surprising. The fact that large areas of the trick images look like seas of static probably stems from the way networks are fed training images. The object of interest is usually only a small part of the photo, and the rest is unimportant.Adams also points out that Clune’s research shows humans and artificial neural networks do have some things in common. Humans have been thinking they see everyday objects in random patterns—such as the stars—for millennia.

Friday, December 26, 2014

How to Create Text Boxes Dynamically


Output Screenshot:



int cleft=1; //for the position of TextBoxes .

we need to create a button handler to create textboxes because we are creating a function AddNewTextBox from class TextBox.

private void createButton_Click(object sender, EventArgs e)
{
AddNewTextBox();
}

public TextBox AddNewTextbox()
{
TextBox txt=new TextBox();
this.Controls.Add(txt);
txt.Top=cleft*25;
txt.Left=100;
txt.Text="TextBox" + this.cleft.ToString();
cleft=cleft+1;
return txt;

}