Looking for NEET / JEE Coaching? Enquire Now
You must Sign In to post a response.
  • Category: Programming

    Basic program using concept of class, object using C++.

    Preparing for C++ exam and facing doubt in writing a program? Wondering about how to write a basic program using class and objects? Scroll through this page for solutions from our ISC experts.

    Following is a question that was asked in the question paper of B.E. Mechanical Engineering (June/July 2017)conducted by Bangalore University, for subject Object Oriented Programming(2K11 Scheme)(ME-601), Semester-VI

    This question is asked for 10 marks and hence requires some explanation. Please let me know the solution.

    Q) Define class and object. Write a class containing two data items length and breadth and three functions getdata(), displaydata() and area(). Write a main program which declare the object and uses the member functions of the class. [10 Marks]
  • Answers

    1 Answers found.
  • Class and object are very basic and important concepts of Object Oriented Programming.
    Class :- Class is a user defied data type which behaves like built in data type of programming language. Class consists of member variables and member functions. Member functions which operates on member variables of the class. Member variables and member functions are wrapped in a single unit called as class and this wrapping up of data and function is called as encapsulation.
    Object:- As every data type has its own variables of that type, class is also having variable of type class which are commonly known as objects. So object is the run time entity of type class. Object occupies storage in the memory.

    Below is the program which is prepared by using above mentioned basic concepts of Object Oriented Programming.
    Please include and header files before declaration of class.

    class sample
    float l,b,a;
    void getdata(void)
    cout<<"Enter length and breadth of rectangle in centimeter\n";
    void displaydata(void)
    cout<<"\nLength of reactangle is "< cout<<"\nBreadth of rectangle is "< a=l*b;
    void area(void)
    cout<<"\nArea of rectangle is "< }
    void main(void)
    class sample s;


    Delete Attachment

  • Sign In to post your comments