Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

PROGRAM OF CONSTRUCTOR OVERLOADING





Hello Friends!!!!!! Today I am Going to learn about the constructor oveloading. Overloading of a constructor means that we use more than one constructor in a single program.A program is given below which shows you concept of constructor overloading......

So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM OF CONSTRUCTOR OVERLOADING

#include
#include
class distance
{
int feet;
float inches;
public:
distance()
{
feet=0;
inches=0;
}
distance(int ft, float in)
{
feet=ft;
inches=in;
}
void get_dist()
{
cout<<"Enter feet :";
cin>>feet;
cout<<"Enter Inches :";
cin>>inches;
}
void show_dist()
{
cout< }
void add_dist(distance,distance);
};
void distance :: add_dist(distance d2,distance d3)
{
inches=d2.inches+d3.inches;
feet=0;
if(inches>=12.0)
{
inches-=12.0;
feet++;
}
feet+=d2.feet+d3.feet;
}
void main()
{
clrscr();
distance d1,d3;
distance d2(11,7.56);
d1.get_dist();
d3.add_dist(d1,d2);
cout<<"\n d1=";
d1.show_dist();
cout<<"\n d2=";
d2.show_dist();
cout<<"\n d3=";
d3.show_dist();
getch();
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO ILLUSTRATE THE CONCEPT OF OPREATOR OVELOADING





Hello Friends!!!! Today I am going to learn about the concept of operator overloading using a simple vector program. In this program we have a class vector and a multiply operator to use and oveload.

So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM TO ILLUSTRATE THE CONCEPT OF OPREATOR OVELOADING

#include
#include
const size=3;
class vector
{
int v[size];
public:
vector();
vector(int *x);
friend vector operator * (int a, vector b);
friend vector operator * (vector b, int a);
friend istream & operator >>(istream &,vector &);
friend ostream & operator <<(ostream &, vector &);
};
vector :: vector()
{
for(int i=0;i v[i]=0;
}
vector :: vector(int *x)
{
for(int i=0;i v[i]=x[i];
}
vector operator * (int a,vector b)
{
vector c;
for(int i=0;i c.v[i]=a*b.v[i];
return c;
}
vector operator *(vector b, int a)
{
vector c;
for(int i=0;i c.v[i]=b.v[i]*a;
return c;
}
istream & operator >> (istream &din, vector &b)
{
for(int i=0;i din>>b.v[i];
return(din);
}
ostream & operator << (ostream &dout, vector &b)
{
for(int i=0;i dout< return(dout);
}
int x[size]={2,4,6};
void main()
{
clrscr();
vector m;
vector n=x;
cout<<"Enter Elements of vector m"<<"\n";
cin>>m;
cout<<"\n";
cout<<"m="< vector p,q;
p=2*m;
q=n*2;
cout<<"\n";
cout<<"p="< cout<<"q="< getch();
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM IN WHICH WE USE ALL THREE CONSTRUCTOR





Hello Friends!!!!! Today I am going to learn how to use all three constructor in a single program.In this program we make three constructor and use them

So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM IN WHICH WE USE ALL THREE CONSTRUCTOR

#include
#include
class demo
{
int x,y;
public:
demo()
{
x=0;
y=0;
}
demo(int a, int b)
{
x=a;
y=b;
}
demo(demo &c)
{
x=c.x;
y=c.y;
}
void display()
{
cout<<"value of x"< cout<<"value of y"< }};
void main()
{
clrscr();
demo d1,d2(10,15);
d1.display();
d2.display();
demo d3=d2;
d3.display();
getch();
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO RAISE A POWER OF A NUMBER




Hello Friends!!! Today I am going to learn program for raising a power of a number to N.Here N is any +ve number. So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM TO RAISE A POWER OF A NUMBER

#include
#include
double power(int p=2, double n);
int main()
{
double n, r;
int pow;
char c;
clrscr();
cout<<"enter the number \n";
cin>>n;
do
{
cout<<"Do u Want to enter the Power (Y/N) ?";
cin>>c;
if(c=='y')
{
cout<<"enter the power to be raised ";
cin>>pow;
r=power(pow,n);
}
else
{
if(c=='n')
{
r=power(pow,n);
}
else
{
cout<<"Invalid Choice ";
}
}
while(c!='y' && c!='n')
cout< getch();
return 0;
}
double power(int p, double n)
{
double r=1;
int i;
if(p<0 data-blogger-escaped-br=""> {
r=1/power(-p,n);
}
else
{
for(i=1;i<=p;i++)
r=r*n;
}
}
return 0;
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO SWAP TWO NUMBERS USING FRIEND FUNCTION



Hello Friends!!!!! Today I am going to Learn a program to swap of two numbers using friend function in C++. In this program we have two classes and a friend function which is friendly with both classes.
So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

///////////* Write a program to Swap two numbers using Friend Function */////////////

#include
#include
class robot;
class angel
{
int x;
public:
void indata(int a)
{
x=a;
}
void display()
{
cout< }
friend void swap(angel &,robot &);
};
class robot
{
int y;
public:
void indata(int a)
{
y=a;
}
void display()
{
cout< }
friend void swap(angel &,robot &);
};
void swap(angel & c,robot & d)
{
int temp=c.x;
c.x=d.y;
d.y=temp;
}
void main()
{
clrscr();
angel n;
robot r;
n.indata(100);
r.indata(200);
cout<<"values before swapping"<<"\n";
n.display();
r.display();
swap(n,r);
cout<<"after swaping"<<"\n";
n.display();
r.display();
getch();
}
I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO ILLUSTRATE THE CONCEPT OF VIRTUAL FUCTION USING BASE CLASS POINTERS



Hello Friends!!!!! Today I am going to make a program to show the concept of Virtual Function using base class pointers. In this program we make a function iam().Here is Program given Below.....
SO Let's Start=>

//Name : Mayank Sharma//
//Roll No : 1101026//
//CSE(4th Sem)

// WAP to Show the concept of Virtual Function Using Pointer //

#include
#include
class A
{
int a,b;
public:
void getdata()
{
cout<<"enter the value of a and b"<<"\n";
cin>>a>>b;
}
void putdata()
{
cout<<"value of a and b is"< }};
class B : public A
{
int x,y;
public:
void getdata()
{
cout<<"enter the value of x and y"<<"\n";
cin>>x>>y;
}
void putdata()
{
cout< }};
int main()
{
A a;
B b;
clrscr();
a.getdata();
a.putdata();
b.getdata();
b.putdata();
return 0;
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

"KAUN BANEGA CROREPATI" GAME IN C++



Hello Friends!!!! Today I have made a simple Game in C++. The name of Game is Kaun Banega Crorepati If you Want to Play then first download from Given link below.....
I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..



Download Project

PROGRAM TO SHOW THE DETAILS OF STUDETS OF CSE CLASS



Hello Friends !!!! Today I am going to tell about the program of array of objects in C++.We make a program to show the details of students of CSE class using array of object in C++.

So here is program=>


//Name : Mayank Sharma
//Roll No : 26
//C.S.E(4th Sem)

// Write a Program To Show the Details of Student of CSE class. //

#include
#include
class stud
{
char name[30];
float age;
public:
void getdata()
{
cout<<"enter name"<<"\n";
cin>>name;
cout<<"age"<<"\n";
cin>>age;
}
void putdata()
{
cout<<"name"< cout<<"age"< }};
const int size=5;
int main()
{
clrscr();
stud s[size];
for(int i=1;i<=size;i++)
{
cout<<"details of Students"<<"\n";
s[i].getdata();
}
cout<<"\n";
for(i=1;i<=size;i++)
{
cout<<"\n student";
s[i].putdata();
}
getch();

}

Output of program :
student 1 :
name
Mayank
age
19
student 2 : name
Kapil
age
19
student 3 : name
Vishal
age
20
student 4 : name
Lalit
age
19
student 5 : name
Kasish
age
19

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM FOR SHOW THE WORKING OF A TOOLBOOTH



Hello Friends !!!! Today I am going to tell about the simple program of Toolbooth. In this program we show the working of a toolbooth.Create a class of Toolbooth and show the working of Toolbooth using constructor in C++.
So here is Program=>

//Name : Mayank Sharma
//Roll No : 26
//C.S.E(4th Sem)

// Write a Program To Show the Working of Toolbooth //

#include
#include
const char ESC=27;
const double toll=0.5;
class tollbooth
{
int totalcars;
double totalcash;
public:
tollbooth() :totalcars(0),totalcash(0.0)
{}
void payingcar()
{
totalcars++;totalcash+=toll;
}
void nonpaycars()
{
totalcars++;
}
void display()
{
cout<<"\n cars="< cout<<"\n cash="< }};
int main()
{
tollbooth b1;
char c;
clrscr();
cout<<"\n Press 0 for paying cars";
cout<<"\n Press 1 for nonpaying cars";
cout<<"\n Press ESC for exit"< do
{
c=getche();
if(c=='0')
b1.payingcar();
if(c=='1')
b1.nonpaycars();
}while(c !=ESC);
b1.display();
getch();
return 0;
}

Output of program is :
Press 0 for paying cars
Press 1 for nonpaying cars
Press ESC for exit
00
cars=3
cash=1.5


I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO ADD CO_ORDINATE OF X AND Y USING STRUCTURE



Hello Friends !!!! Today I am going to tell about the simple program of structure in c++.Program to add Two co-ordinate using structure in C++.In this Program we add first co-ordinate of X to the first Co-ordinate of Y and second to second.
So here is Program=>
//Name : Mayank Sharma
//Roll No : 26
//C.S.E(4th Sem)

// Write a Program To Add Co-ordinates //

#include
#include
struct add
{
int x;
int y;
};
void main()
{
clrscr();
add p1,p2,p3;
cout<<"Co-ordinate of p1 is :"<<"\n";
cin>>p1.x>>p1.y;
cout<<"co-ordinate of p2 is :"<<"\n";
cin>>p2.x>>p2.y;
p3.x=p1.x+p2.x;
p3.y=p1.y+p2.y;
cout<<"co-ordinate of X after sum is :"<<"\n"< cout<<"co-ordinate of y after sum is :"<<"\n"< getch();
}

Output of program is :
Co-ordinate of p1 is :
13
14
co-ordinate of p2 is :
20
30
co-ordinate of X after sum is :
33
co-ordinate of y after sum is :
44

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO SHOW THE PHONE NUMBERS USING STRUCTURE IN C++



Hello Friends !!!! Today I am going to tell about the simple program of structure in c++.Program to show phone number.This program show you two numbers in this way 123(111)-7562 Look like this.One phone number input directly and other input by user and then show in same manner.
So the Program is Here=>.
//Name : Mayank Sharma
//Roll No : 26
//C.S.E(4th Sem)

// Write a Program To show and input a Complete Phone Number //

#include
#include
struct phone
{
char areacode[10];
char exchangecode[10];
char pincode[10];
} p1;
void main()
{
clrscr();
phone p1={"222","456","7800"};
cout<<"My phone no is :"<<"\n\n";
cout< cout<<"Enter your phone Number"<<"\n\n";
cin>>p1.areacode>>p1.exchangecode>>p1.pincode;
cout<<"Your phone number is :"<<"\n\n"< getch();
}


//Output Of This Program ://


My phone no is :
222(456)-7800
Enter your phone Number
212
345
3400
Your phone number is :
212(345)-3400

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

PROGRAM TO PRINT A WORD HELLO IN C LANGUAGE


Hello Friends !!! Today I am going to tell about First program of C language.Which is given below...
#include
#include
void main()
{ clrscr();
printf("Hello");
getch();
}
I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below...

PROGRAM TO FIND A FACTORIAL IN C


Hello Friends !!! Now I am tell about the c program that how to find a factorial by using c program given below...
#include
#include
void main()
{
int n,i,fact=1;
clrscr();
printf("enter a number");
scanf("%d",&n);
for(i=1;i<=5;i++)
{
fact=fact*i;
}
printf("%d",fact);
getch();
}

I think this post will help you.
Thanks !!!!
If any query about this post then post your comment below..I will help you 100% surely..

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites