Saturday, 31 August 2013

Program Over Flow- Using C++ Language

#include<iostream.h>
#include<conio.h>
class Distance{
private:
int feet;
int inches;
public:
Distance(){
feet=0;
inches=0;
}
Distance(int f, int i)
{
feet=f;
inches=i;
}
void display()
{
cout<<"f:"<<feet <<"i:"<<inches;
}
Distance operator--()
{
feet=--feet;
inches=--inches;
return Distance(feet,inches);
}

};
void main(void)
{

Distance D1(11,10);
//Distance D(-10,-12);
--D1;
D1.display();

//D.display();
getch();
}

Program Electricity Bill in C++ Language

#include<iostream.h>
#include<conio.h>
class bill{ public:
char name;
int units;
float tbill;
float tbill1,tbill2,tbill3;
void input(){

cout<<"Enter the name:\t";
cin>>name;
cout<<"Enter the units:\t";
cin>>units;
}
void output()
{
switch(units)
{
case 100:
{tbill1=units*0.6;
cout<<"Total bill=\t"<<tbill1;
}
case 200:
{tbill2=units*0.8;
cout<<"Total bill:\t"<<tbill2;
}
case 300:
{tbill3=units*0.9;
cout<<"Total bill:\t"<<tbill3;
}

float tbill()
 {
 return tbill1+tbill2+tbill3;
  }
}}
};
void main(void)
{
bill n;

n.input();
n.output();
tbill=n.tbill;

cout<<"Over all bill:\t"<<tbill;
getch();
}