An Overview

All the necessary study material for b-tech students.

What we have to offer you.

Codes,Syllabus,Study material,Lab manuals,Assignments and many more . . .

Surfing becomes easy.

You can have any material from our website and post your valuable comments for further improvement.

Get the latest techno news

Get yourself updated with this fast changing dynamic world and all the changes in b-tech pattern.

All the best resources for you.

We have done our level best to provide you with the best of the degree and thus this site is devoted to b-tech exclusively.

Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

17 November 2011

Length program using classes.

#include<iostream.h>
#include<conio.h>
class db;
class dm
 {
  float mt;
  int cm;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };
  class db
  {
  int feet;
  float inches;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };   void dm :: getdata(void)
  {
  clrscr();
  cout<<"\t\tDM GETDATA FUNCTION\n\n";
  cout<<"Enter Values for metres :-";
  cin>>mt;
  cout<<"Enter Values for centimetres:-";
  cin>>cm;
  }
  void dm :: display(void)
  {
  cout<<"\n\nThe value of distance in metres is"<<mt;
  cout<<"\nThe value of distance in Centimetres is "<<cm;
  }
  void db ::getdata(void)
  {
  clrscr();
  cout<<"\t\tDB GETDATA FUNCTION\n\n";
  cout<<"\n\nEnter Values forn feet:-";
  cin>>feet;
  cout<<"Enter Values for inches:-";
  cin>>inches;
  }
  void db :: display(void)
  {
  cout<<"\n\nThe value of distance in feet is "<<feet;
  cout<<"\nThe value of distance in inches is"<<inches;
  }
  dm add(dm a,db b)
  {
  dm temp;
  temp.cm=a.cm+(b.feet*30)+((b.inches*30)/12.0);
  temp.mt=a.mt+(temp.cm% 100);
  temp.cm=temp.cm-((temp.cm% 100)*100);
  return(temp);
  }
  void main()
  {
  dm a;
  a.getdata();
  db b;
  b.getdata();
  clrscr();
  cout<<"\n\t\tAFTER CONVERSION AND THEIR ADDITION IS PERFORMED\n";
  //extra variable of type dm to display result of adding two different types of distance
  dm extra;
  extra=add(a,b);
  extra.display();
  getch();
  }

 

A class program to display ages of father,daughter and son.

#include<iostream.h>
#include<conio.h>
class father
{
  protected:
   int age;
  public:
   father(int x)
   {
     age=x;
   }
   virtual void iam()
   {
     cout<<"I AM THE FATHER, my age is "<<age;
   }
};
class son:public father
{
  public:
   son(int s):father(s)
   {
     age=s;
   }
   void iam()
   {
     cout<<"I am son, my age is "<<age;
   }
};
class daughter:public father
{
  public:
   daughter(int d):father(d)
   {
     age=d;
   }
   void iam()
   {
     cout<<"I am daughter, my age is "<<age;
   }
};
void main()
{
  father f1(45),*ptr;
  son s1(20);
  daughter d1(18);
  clrscr();
  cout<<"ptr point the base class father obj\n";
   ptr=&f1;
   ptr->iam();
  cout<<"\n\nptr point the class son obj\n";
   ptr=&s1;
   ptr->iam();
  cout<<"\n\nptr point the class daughter obj\n";
   ptr=&d1;
   ptr->iam();
  getch();
}

14 November 2011

A simple class program in C++

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class student
{
private:
int age;
char name[10];
public:
void getdata()
{
cin>>name;
cin>>age;
}
void putdata()
{
cout<<"Your name is "<<name;
cout<<"Your age is "<<age;
}
};
void main()
{
student st;
st.getdata();
st.putdata();
clrscr();



getch();
}