Erle Robotics C++ GitBook

Exercises: Advanced II

Exercise 1

Write a program that enumerate some auto's brands. Then create a variable called my_car_brand and make it equal to one of them. Print a message saying hello to the user.

Solution

Exercise 2

Write a simple program:

  • read() is a function that ask for a name and returns a string containing the name.
  • in the main() you should ask for the name and write a hello message.

Solution

Exercise 3

Create a clas called Rectangle.It should contain a constructor for width and height, a function that returns the area and a friend fucntion that duplicate the rectangle's dimensions. In the main, creaate a rectangle instance, duplicate it and print out the area.

Solution

Exercise 4

Create a class called Box with a variable: width of type double. Inside the class define a constructor and a friend that prints the width value(printWidth). In the main() define a Box instance, set values and call printWidth.

Solution