Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

🎯 Objective

Design and implement a simple calculator using C++ classes. This project will help you understand the concept of classes, objects, and encapsulation in C++.

\uD83D\uDDD2 Requirements

  1. Create a class called Calculator with the following attributes:

    • first_number (double)

    • second_number (double)

  2. Add the following methods to the Calculator class:

    • A constructor to initialize the attributes.

    • Getters and setters for each attribute.

    • A method called add() to add the two numbers and return the result.

    • A method called subtract() to subtract the second number from the first number and return the result.

    • A method called multiply() to multiply the two numbers and return the result.

    • A method called divide() to divide the first number by the second number and return the result. Ensure that division by zero is handled appropriately.

  3. In the main() function, create a Calculator object and use the methods to perform various operations like addition, subtraction, multiplication, and division. Demonstrate the use of the Calculator class by simulating a simple calculator.

❗Note - your functions for add, subtract, multiple, and divide should not have any parameters❗

🚚 Deliverable

Upload the following:

  1. Full source code (.cpp files or .txt files)

  2. Screenshot of the Console with the code executing

  • No labels