C++ Programs using class and object

1. Write a simple C++ program using class and object.

    Solution:

    Output:

    Maruti is a car which has 4 wheels

    It has 2 doors

    Output:

    Roll Number: 1

    Name: Aakash Shah

    2. Write a program to add two numbers using class and objects.

    Solution:

    Output:

    Enter 2 numbers: 45 56

    Result: 101

    3. Write a C++ program to add and subtract two numbers using class.

    Solution:

    Output:

    Enter 2 numbers: 4 5

    Sum of 4 and 5 is: 9

    Enter 2 numbers: 6 3

    Difference of 6 and 3 is: 3

    4. Write a C++ program to multiply and divide two numbers using class.

    Solution:

    Output:

    Enter 2 numbers: 4 5

    Product of 4 and 5 is: 20

    Enter 2 numbers: 6 3

    Division of 6 and 3 is: 2

    5. Define a class student for the following specifications:

    Private members of the student are:

    Registration number, Age, Name and Address

    Public members of the student are:

    input reads registration number, name, age and address

    display prints the data

    Solution:

    Output:

    Enter data of students…

    1.Registration Number: 1001

    2.Name: Ankit

    3.Age: 20

    4.Address: Tinsukia

    Student data is:

    1.Registration Number: 1001

    2.Name: Ankit

    3.Age: 20

    4.Address: Tinsukia

    Leave a Comment