Posts

Write a C++ program using class to overload following binary operators

Write a C++ program using class to overload following binary operators (+,-,*,/). #include<iostream.h> #include<conio.h> class number { int a; public:void get();        void show();        number operator +(number);        number operator -(number);        number operator *(number);        number operator /(number); }; void number:: get() {  cout<<"\nenter value";  cin>>a;  }  void number:: show()  {  cout<<a;  }  number number::operator+(number n2)  {  number t;  t.a=a+n2.a;  return t;  }  number number::operator-(number n2)  {  number t;  t.a=a-n2.a;  return t;  }  number number::operator*(number n2)  {  number t;  t.a=a*n2.a;  return t;  }  number number::operator/(number n2) ...

Write Cpp program to represent bank account using member function

Define a class to represent a bank account which include following member data member:- 1)name 2)Account number 3)type of account 4)bal.amt member function: a.to assign initial value b.to deposit an account c.to withdraw an account d.to display name,account number and balance #include<conio.h> #include<iostream.h> #include<string.h> int w_amt; class bank { public:int acc_no,bal; char type[30],name[30]; public:void assign()        {        strcpy(name,"Vijay");        acc_no=111;        strcpy(type,"saving");        bal=12000;        }        void deposit()        {        int amt;        cout<<"\n Enter the amount which you want to deposi...

Cpp program to create class telephone to search no name and city

Create a class telephone containing name,telephone number and city as data members and write necessary member function for the following -search the telephone number with given name. -search the name with given telephone number -search all customer in a given city. #include<iostream.h> #include<conio.h> #include<string.h> class telephone { public:char name[30],city[30];        int tno; public:void get()        {        cout<<"enter name:-";        cin>>name;        cout<<"\nenter telephone number";        cin>>tno;        cout<<"\nenter city name:-";        cin>>city;        }        void search(int tnum)      ...

C++ Program to find tax of person salary

Consider the following class person class person { char name[20]; char addr[30]; float salary; int property; float tax; public:\\method }; calculate tax amount by checking salary and the property of the person for salary<5000         tax rate=0 for salary>=5000||<=10000    tax rate=14% of salary for salary>=10000        tax rate=16% of salary in this tax amount add following amt depending on the size of area in sqr.foot for 100 sqr.foot        amt=0 for>1000||<5000            amt=1000 for>5000||<=10000        amt=3000 #include<conio.h> #include<iostream.h> class person { char name[20],addr[30]; float sal,tax_amt; int prop; public:void accept();        void display(); }; void person::accept() { cout<<"\n En...

C++ program for medical shoppee

Create a class medical shoppe containing -medicine -qty -price medicine details are stored into file medical.txt. when any medicine has to be sold it is first searched into file. if found the quantity is decremented that much quantity to be sold. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<string.h> #include<iomanip.h> #include<stdlib.h> #include<stdio.h> class medical { public:char med[20];        int qty,price; public:void accept()        {        cout<<"\nenter the medicine name:-";        cin>>med;        cout<<"\nenter qty:-";        cin>>qty;        cout<<"enter price";        cin>>price;     ...

C++ program to accept and dispaly data using class date

Create a c++ class date which contain: -date -month -year write necessary member function to accept and display a data using << and >> operator #include<iostream.h> #include<conio.h> class date { int d,m,y; public:void accept()        {        cout<<"\nenter date:-";        cin>>d;        cout<<"\nenter month:-";        cin>>m;        cout<<"\nenter year:-";        cin>>y;        }        void display()        {        cout<<"\n\ndate:="<<d<<"-"<<m<<"-"<<y;        } }; int main() { date d; clrscr(); d.accept(); d.display(); getch(); ret...

write a c++ program to read distance from user. store it in the file and display it to the user.

Create a class  distance containing feet and inches as data member. write a c++ program to read distance from user. store it in the file  and display it to the user.  use operator overloading for the following  1.<<to write distance object in inches format to a file  2.>>to read inches from file. #include<iostream.h> #include<conio.h> #include<fstream.h> class distance {    int feet;    int inches;  public:  friend void operator <<(fstream &,distance &);  friend void operator >>(fstream &,distance &); }; void operator <<(fstream &fout,distance &d) { cout<<"\nEnter distance : "; cout<<"\n\nEnter feet : "; cin>>d.feet; cout<<"\n\nEnter inches : "; cin>>d.inches; int finches=(d.feet*12)+d.inches; fout<<finches<<"\n"; } void operator >>(fstream &fin,distance &d) { int finches; fin>>finches; d.inch...