Search This Blog

Sunday, December 29, 2013

Static data type function

#include <iostream>
using namespace std;
class student
{
    char name[30];
    int roll;
    int marks;
    static int batch;
    static char faculty[50];
public:
    void input();
    void display();

};
int student::batch=2069;
char student::faculty[50]="electronics and communication";
void student::input()
{
    cout<<endl<<"please enter your name  ";
    cin>>name;
    cout<<endl<<"please enter you roll  ";
    cin>>roll;
    cout<<endl<<"please emter your mark  ";
    cin>>marks;
}
void student::display()
{
    cout<<endl<<name;
    cout<<endl<<roll;
    cout<<endl<<marks;
    cout<<endl<<batch;
    cout<<endl<<faculty;
}
int main()
{
    student s[5];
    cout<<endl<<"STUDENT RECORDS"<<endl;
    for(int i=0;i<5;i++)
    {
        s[i].input();
    }
    for(int i=0;i<5;i++)
    {
        s[i].display();
    }
    return 0;
}

Working of friend function

#include <iostream>
using namespace std;
class array
{
    int a[10];
public:
    void input();
    friend float average(array);
};
void array::input()
{
    for(int i=0;i<10;i++)
    {
        cin>>a[i];
    }
}
float average(array a1)
{
    float sum=0;
    for(int i=0;i<10;i++)
    {
        sum=sum+a1.a[i];
    }
    return (sum/10);
}
int main()
{
    array a1;
    cout<<endl<<"enter 10 elements of an array";
    a1.input();
    float avg;
    avg=average(a1);
    cout<<endl<<avg;
    return 0;
}

Monday, December 23, 2013

Objects as function arguements

#include <iostream>
using namespace std;
class time
{
    int hour, minute, second;
public:
    void input()
    {
        cin>>hour>>minute>>second;
    }
    void display()
    {
        cout<<hour<<" hour ";
        cout<<minute<<" minute and ";
        cout<<second<<" seconds"<<endl;
    }
    void add(time t1,time t2)
    {
        second=t1.second+t2.second;
        minute=t1.minute+t2.minute+second/60;
        second=second%60;
        hour=t1.hour+t2.hour+minute/60;
        minute=minute%60;

    }
};
int  main()
{
    time t1, t2, t3;
    cout<<" enter start time : ";
    t1.input();
    cout<<" enter end time : ";
    t2.input();
    t3.add(t1,t2);
    t3.display();
    return 0;
}

Array of an object

#include <iostream>
using namespace std;
class student
{
    int roll;
    char name[15];
    int marks[5];
public:
    void input();
    void display();
};
void student :: input()
{
    cout<<"please enter your name ";
    cin>>name;
    cout<<endl<<"now enter your roll no";
    cin>>roll;
    cout<<endl<<"now enter your marks"<<endl;
    for(int i=0;i<5;i++)
    {
        cin>>marks[i];
    }

}
void student :: display()
{
    cout<<"\n name "<<name<<endl;
    cout<<"\n roll no "<<roll<<endl;
    cout<<"\n marks \n --------------------------------------------- "<<endl;
    for(int i=0;i<5;i++)
    {
        cout<<marks[i]<<"   ";
    }
    cout<<" \n -------------------------------------------- \n";
}
int main()
{
    student s[5];
    cout<<"enter student record \n";
    cout<<"----------------------------------- \n";
    for(int i=0;i<5;i++)
    {
        s[i].input();
    }
    for(int i=0;i<5;i++)
    {
        s[i].display();
    }
    return 0;

}

Working of friend function

#include <iostream>
using namespace std;
class array
{
    int a[10];
public:
    void input();
    friend float average(array);
};
void array::input()
{
    for(int i=0;i<10;i++)
    {
        cin>>a[i];
    }
}
float average(array a1)
{
    float sum=0;
    for(int i=0;i<10;i++)
    {
        sum=sum+a1.a[i];
    }
    return (sum/10);
}
int main()
{
    array a1;
    cout<<endl<<"enter 10 elements of an array";
    a1.input();
    float avg;
    avg=average(a1);
    cout<<endl<<avg;
    return 0;
}

Monday, November 25, 2013

Vector Analysis day 1

Electromagnetics is the study of electric and magnetic fields and their interaction with the environment.
There are three types of coordinate system

1) Rectangular coordinate system:

It is represented as P(x,y,z). its unit vector is ax, ay, az. the vector is represented as A=Axax+Ayay+Azaz.
For differential volume dv=dxdydz.

2) Cylindrical Coordinate System:

The three coordinates (ρ, φ, z) of a point P are defined as:

*The radial distance ρ is the Euclidean distance from the z axis to the point P.
*The azimuth φ is the angle between the reference direction on the chosen plane and the line from         the origin to the projection of P on the plane.
*The height z is the signed distance from the chosen plane to the point P.

The volume element is


The surface element in a surface 



             





3) spherical coordinate system:
Spherical coordinates is represented as P(r, θ, φ) as often used in mathematics: radial distance r, azimuthal angle θ, and polar angle φ. The meanings of θ and φ have been swapped compared to the physics conventi
Any spherical coordinate triplet (r, θ, φ) specifies a single point of three-dimensional space. On the other hand, every point has infinitely many equivalent spherical coordinates. One can add or subtract any number of full turns to either angular measure without changing the angles themselves, and therefore without changing the point. It is also convenient, in many contexts, to allow negative radial distances, with the convention that (−r, θ, φ) is equivalent to (r, θ + 180°, φ) for any r, θ, and φ. Moreover, (r, −θ, φ) is equivalent to (r, θ, φ + 180°)on.
Its volume element is: 




dot products of unit vector in spherical and rectangular coordinate system.


                   ar                   aθ                aφ
ax          sinθcosφ        cosθcosφ        -sinφ
ay          sinθsinφ         cosθsinφ          cosφ
az           cosθ                 -sinθ                 0

















Thursday, November 21, 2013

Introduction to C++

Day 1 Object Oriented Programming

Some Features:

* Emphasis on the data rather than the procedure.
* Programs are divided into what are called objects
* Data structures are designed such that they characterize the object.
* Functions that operate on the data of an object are tied together in data structure.
* Data is hidden and cannot be accessed by external functions.
* Objects may communicate with each other through functions.
* New data and function can be easily added whenever necessary.
* Follows Bottom up approach in program design.

Basic concept of Object Oriented Programming:

* Object
* Classes
* Data Abstraction
* Encapsulation
* Inheritance
* Polymorphism
* Dynamic binding
* Message passing
* Templates
* File Handling