Erle Robotics C++ GitBook

Exercises: Classes

Exercise 1

Write a class having two private variables and one member function which will return the area of the rectangle.


Exercise 2

Write a program and input two integers in main and pass them to default constructor of the class. Show the result of the additon of two numbers.


Exercise 3

Write a c++ class called 'student' with

Data members:

name(char type),

marks1,marks2 (integer type)

The program asks the user to enter name and marks. Then calc_media() calculates the media note and disp() display name and total media mark on screen in different lines.


Exercise 4

Perform addition operation on complex data using class and object. The program should ask for real and imaginary part of two complex numbers, and display the real and imaginary parts of their sum.