C#ODE Studio

C#ODE Studio, our own enterprise is now 1 year old and I am very thankful to all of you for encouraging me toward my ‘symphony’.

Thanks Prof. Varun Sir and Vivek for encouraging me beyond the world’s word towards my enthusiasm, and support from all of you guys are also really appreciable.

Thanks to all admins for keeping it up with zest and love.

Thank you all for keep supporting us through out ups and downs in our path and STAT!! as well….. hahaha 😉

-On the first anniversary of our blog

MATRIX USING EXCEPTION HANDELING

Question – WAP TO MULTIPLY TWO MATRIX, GET ROW AND COLUMN FROM USER FOR BOTH MATRIX. IF DIMENSION OF MATRIX ARE NOT SAME THEN RAISE EXCEPTION AND TERMINATE PROGRAM –

#include<iostream.h>
#include<conio.h>
using namespace std;
int main()
{
    try
    {
        int a[10][10],b[10][10],c[10][10],m,n,o,p,i,j;
        line:
            cout<<"Enter number of rows of A: ";
        cin>>m;
        cout<<"Enter number of coloumns of A: ";
        cin>>n;
        cout<<endl<<"Enter elements of matrix A: "<<endl;
        for(i=0;i<m;i++)
           {
            for(j=0;j<n;j++)
            {
                cout<<"Enter element a"<<i+1<<j+1<<": ";
                cin>>a[i][j];
            }
        }
        cout<<endl<<"Enter number of rows of B: ";
        cin>>o;
        cout<<"Enter number of coloumns of B: ";
        cin>>p;
        cout<<endl<<"Enter elements of matrix B: "<<endl;
        for(i=0;i<o;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<"Enter element b"<<i+1<<j+1<<": ";
                cin>>b[i][j];
            }
        }
        cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                cout<<a[i][j]<<" ";
            }
            cout<<endl<<endl;
           }
           cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
        for(i=0;i<o;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<b[i][j]<<" ";
            }
               cout<<endl<<endl;
           }
           if(m!=p || n!=o)
                   throw m;
           for(i=0;i<m;i++)
           {
              for(j=0;j<p;j++)
            {
                c[i][j]=0;
                 for(int k=0;k<n;k++)
                 {
                    c[i][j]=c[i][j]+a[i][k]*b[k][j];
                 }
              }
        }
        cout<<endl<<"Matrix A * Matrix B = Matrix C: "<<endl<<endl;
        for(i=0;i<m;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<c[i][j]<<" ";
             }
            cout<<endl<<endl;
         }
      }
      catch(int x)
      {
          cout<<"\n\nMULTIPLICATION NOT POSSIBLE : DIMENSION OF MATRICES ARE NOT SAME";
    }
    cout<<"\n\nProgramming @C#ODE STUDIO";
    getch();
}

mul_mat_1

EXCEPTION RAISED

mul_mat_2

OPERATOR OVERLOADING (JOINING TWO CLASS);

QUE- DETERMINE A CLASS OF TIME WITH CONSTRUCTOR AND ADD TWO OBJECT TO THAT, DEFINE A OPERATOR OVERLOAD FN WHICH ADD THE DATA MEMBERS OF THE CLASS AND STORE IN THIRD OBJECT AS RETURNED VALUE; ALSO DISPLAY THE DATA;

Ans-

#include<conio.h>
#include<iostream.h>
class time
{

int hr,min;
public:
time() //constructor with no arguments

{

hr=0;
min=0;

}
time(int a, int b) //constructor with arguments
{

hr=a;
min=b;

}
/*the argument in below fn is the argument which i was transfer
there. the operator is suppose to call in the left operand
as it is t4=t2+t3 then operator is called by t2 and the t3 is transfered as
arguments;*/

time operator +(time t) //operator overloading fn.
{

time t1;
t1.hr=hr+t.hr;
t1.min=min+t.min;
return t1;

}
int display()
{

cout<<“\nHOUR IS:”<<hr;
cout<<“\nMIN IS:”<<min;

}

};
int main()
{

class time t2(4,5),t3(6,7),t4;
t4=t2+t3;
cout<<“\n\nCLASS T2:”<<endl;
t2.display();
cout<<“\n\nCLASS T3:”<<endl;
t3.display();
cout<<“\n\nCLASS T4 <i.e. t2+t3>:”<<endl;
t4.display();
cout<<“\n\nPROGRAMMING AT C#ODE STUDIO”;
getch();

+operat
}

NUMBER PALINDROME;

QUESTION- WAP to find the reverse of a number and check whether it is palindrome or not;

ANSWER;

#include<stdio.h>
#include<conio.h>
int main()
{
int n,r,n1,rev=0;
printf(“\nINPUT YOUR NUMBER: “);
scanf(“%d”, &n);
for(n1=n; n1!=0; n1=n1/10)
{
r = n1%10;
rev = rev*10+r;
}
printf(“\nVALUE IN REVERSE ORDER: %d\n”,rev);
if(rev==n)
printf(“\n %d : Palindrome.”, n);
else
printf(“\n %d : NOT Palindrome.”, n);
printf(“\n\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

no_pali

POINTERS(CALL BY VALUE)

QUE- WAP TO CALL A FUNC FROM VALUE

ANS-

#include<iostream.h>
#include<conio.h>
void swaping(int , int );
int main()
{
int n1,n2;
cout<<“Enter first number n1 :”;
cin>>n1;
cout<<“\nEnter second number n2 :”;
cin>>n2;
cout<<“\nValues before swapping:”;
cout<<“\n n1=”<<n1<<” \n n2=”<<n2;
swaping(n1,n2);
cout<<“\n\nPROGRAMMING @C#ODE STUDIO”;
getch();
return 0;
}
void swaping(int x, int y)
{
  int z;
  z=x;
  x=y;
  y=z;
  cout<<“\nValues after swapping:”;
cout<<“\n n1=”<<x<<” \n n2=”<<y;
}

point_val

Memory Allocation;

 

The concept of malloc, realloc and calloc is to allocation of memory at run time. Means when program runs it ask for the memory size of given array whether it is array of structure, array of character or any other.

It will use just after the variable declaration of the array or any where in fn.

“malloc”- Malloc is used for memory allocation at written above; syntax is-(pointer to variable)malloc(no.*sizeof(variable));

eg:-

struct user

    {

        char name[10];

        char pass[15];

        char email[26];

    }*u;

    int n;

    printf(“\nINPUT NO. OF USERS:”);

    scanf(“%d”,&n);

    u=(struct user*)malloc(n*sizeof(struct user));

“calloc”- Calloc is used for same as malloc but it also initialized the variables with zero;

“realloc”- Realloc is used to allocate extra memory or extend the memory of a given variable

  it ask for the no. and then it subtract the memory which is already allocated and then the remaining memory is allocated to the array.

                 syntax- (pointer to variable)realloc(variable to structure,no.*sizeof(variable)); 

eg:-

    printf(“\nTOTAL NO. OF RECORDS:”);

    scanf(“%d”,&k);

    u=(struct user*)realloc(u,k*sizeof(struct user));

it check for current size of the variable u and then it will subtract memory from current requirement after which it allocate memory to array;

Notification:

HI EVERYONE!!!   Smile

THE SEASONS OF EXAMS ARE ABOVE HEAD AND ALL THE STUDENT OF CSE ARE SEEKING FOR PROGRAMS SO GUYS JUST WAIT. YOU WILL GET ALL THE IMPORTANT PROGRAMS FOR CSE104 ON THIS BLOG ONLY….

BE PREPARED

ALL THE BEST       Thumbs up

                                                                                   FROM-  TANMAY BARANWAL