Skip to content

Commit

Permalink
UPD: readme updated. Added some pics and gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
drveles committed Jul 6, 2024
1 parent 5eeeb72 commit e13a803
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 183 deletions.
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# School 21 License
MIT License

Copyright (c) 2024 Frolov Vasilii (drveles)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
159 changes: 68 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,73 @@
# SmartCalc v2.0
# Calculator
Описание на русском [тут](./README_RUS.md).

Implementation of SmartCalc v2.0.
School 21 project. Functions for calculations are written in C++ language. The QT library (C++) is responsible for the visual part.

The russian version of the task can be found in the repository.
1. [MVC Model](#mvc-model)
2. [Frontend](#frontend)
3. [Backend](#backend)
4. [Installation and testing](#installation-and-testing)
5. [Technical assignment](#technical-assignment)

## Contents

1. [Chapter I](#chapter-i) \
1.1. [Introduction](#introduction)
2. [Chapter II](#chapter-ii) \
2.1. [Information](#information)
3. [Chapter III](#chapter-iii) \
3.1. [Part 1](#part-1-implementation-of-smartcalc-v20) \
3.2. [Part 2](#part-2-bonus-credit-calculator) \
3.3. [Part 3](#part-3-bonus-deposit-calculator)
## MVC Model
![Alt text](misc/images/MVC-Process.png)

***Model-View-Controller*** means dividing a program into components.

## Chapter I
*Model* - is responsible for checking and working with data. The model has no visualization.

![smartcalcv2.0](misc/images/smartcalcv2.0.PNG)
*VIew* - Presents the result of the model to the user.

Planet Earth, 20 August 1983.
*Controller* - The link between the view and the model. Passes requests from the user to the model, returns the result of the request.

Chris has put a paper cup of coffee on the table beside you, and that wakes you up.
This separation allows you to easily replace the model of one type with another (for example, in another programming language) or connect another visualization. It is also possible to connect several user interfaces to one logical part.

*"Pure black Americano, I hear you like it. It'll help you wake up."*
## Frontend
### Mathematical operations

*"Oh yes, I really need it, thank you. Where were we?"* you asked as you sipped your hot coffee.
Use the buttons to compose a mathematical expression that will be sent by the controller to the calculation function when you press ` = `

*"Have you finished the basic logic for the calculator?"*
![math](./misc/math.gif)

*"Ah, it's still a work in progress. The meeting with Steve is tomorrow?"*
### Plotting

*"That's right. If we can show him some basic arithmetic operations with a refactored program structure, I think he'll like it.*
In the `X` input box, you can enter any number to substitute into the formula.
The graph will be centered on the given X and the Y obtained from it.
You can change the scale of the graph if necessary.

For more than a week now, you've been spending your evenings helping Chris Espinosa rewrite an object-oriented calculator. His latest version, using the standard structured approach, turned out not to be flexible and extensible enough for Steve Jobs, who was bursting with ideas. So you and Chris decided to try the emerging object-oriented programming paradigm in the young C++ language to solve these problems. Of course, learning new technologies caused some... difficulties, but there is hope that it will not be necessary to completely rewrite the calculator for the eighth time.
![graph](./misc/graph.gif)

*"Well, let's speed things up."*
## Backend

*"By the way, I met a developer from Norway the other day: Torkve or Trykve, I can't remember.* \
*Anyway, he told me about a scheme for organising data and application logic that allows us to change some components very flexibly and quickly. For example, we can completely separate the interface from the rest of the code, you know? And if Steve doesn't like something in the interface, it can be changed quickly and safely. We wouldn't even have to rewrite the tests for the rest of the logic."*
1. The controller passes a string with a mathematical expression to the model.
1. The string entered by the user is checked for correctness.
2. Conversion from the infix entry (`3 + 3`) to the inverse Polish entry (`3 3 +`) is performed using the algorithm "sorting station".
3. Using the algorithm of calculation by the inverse Polish notation - we get the result of the entered expression.
4. Return the result of the calculation to the controller.

## Installation and testing
### Building an application

*"Sounds like exactly what we need! I'm all ears."*
Assembly is performed using Makefile with the following purposes:

## Introduction
`install` - install the application in the directory above.

In this project, you'll need to implement an extended version of the standard calculator in C++ using the object-oriented programming paradigm, implementing the same functions as the application previously developed in the SmartCalc v1.0 project. In addition to basic arithmetic operations such as add/subtract and multiply/divide, the calculator needs to be able to calculate arithmetic expressions by following the order, as well as some mathematical functions (sine, cosine, logarithm, etc.). Besides calculating expressions, it should also support the use of the variable _x_ and the graphing of the corresponding function. As for other improvements, you could consider a credit and deposit calculator.
`uninstall` - remove the application from the directory above.

`dvi` - open the documentation.

## Chapter II
### Testing

## Information
Functions for calculations are covered by unit tests.

Note that you should use *Dijkstra's algorithm* to translate expressions into *reverse Polish notation* to implement the calculator. You can find all the necessary information in the SmartCalc v1.0 project description to refresh your knowledge.
`test` - run tests of the functions.

### MVC pattern
`leaks` - check the code under test for leaks.

The Model-View-Controller (MVC) pattern is a scheme for separating application modules into three macro components: a model that contains the business logic, a view that is a UI form for interacting with the program, and a controller that modifies the model by user action.
`gcov_report` - see code coverage by tests.

The concept of MVC was introduced in 1978 by Trygve Reenskaug, who was working on the Smalltalk programming language at Xerox PARC. Later, Steve Burbeck implemented the pattern in Smalltalk-80.
The final version of the MVC concept was published in Technology Object in 1988. The MVC pattern continued to evolve, giving rise to variants such as HMVC, MVA, MVVM.

The primary need for this pattern stems from developers' desire to separate the business logic of the program from the views, making it easier to replace views and reuse logic once implemented in other environments. Having a model separate from the view, and a controller to interact with it, allows you to reuse or modify code you have already written more efficiently.

The model stores and accesses the main data, performs operations on requests defined by the business logic of the program, i.e. it is responsible for the part of the program that handles all the algorithms and information processing. These models, modified by the controller, affect the display of information on the user interface. The model in this programme should be the class library that performs the calculations. This library must provide all the necessary classes and methods to perform them. And this is the business logic of the program, because it provides the means to solve the problem.

A controller is a thin macro component that performs model modifications. It is used to generate requests to the model. In code, it looks like a kind of "facade" for the model, that is, a set of methods that already work directly with the model. It is called thin because the ideal controller contains no additional logic other than calling one or more methods of the model. The controller acts as a link between the interface and the model. This allows the model to be completely encapsulated from the representation. This separation is helpful in that it allows the view code to know nothing about the model code and to address only the controller, whose interface of the provided functions is unlikely to change much. The model, on the other hand, can change significantly, and if you "move" to other algorithms, technologies, or even programming languages in the model, only a small piece of code in the controller directly related to the model needs to be changed. Otherwise, it would probably be necessary to rewrite a significant part of the interface code, as it would depend very much on the implementation of the model. So when the user interacts with the interface, they call controller methods that modify the model.

The view contains all the code associated with the programme interface. An ideal interface code should not contain any business logic. It just provides the form for interacting with the user.

![](misc/images/MVC-Process.png)


## Chapter III

## Part 1. Implementation of SmartCalc v2.0

You need to implement the SmartCalc v2.0:
## Technical assignment

- The program must be developed in C++ language of C++17 standard;
- The program code must be located in the src folder;
Expand All @@ -102,42 +93,28 @@ You need to implement the SmartCalc v2.0:
- Verifiable accuracy of the fractional part is at least to 7 decimal places;
- Users must be able to enter up to 255 characters;
- Bracketed arithmetic expressions in infix notation must support the following arithmetic operations and mathematical functions:
- **Arithmetic operators**:
| Operator name | Infix notation <br /> (Classic) | Prefix notation <br /> (Polish notation) | Postfix notation <br /> (Reverse Polish notation) |
| --------- | ------ | ------ | ------ |
| Brackets | (a + b) | (+ a b) | a b + |
| Addition | a + b | + a b | a b + |
| Subtraction | a - b | - a b | a b - |
| Multiplication | a * b | * a b | a b * |
| Division | a / b | / a b | a b \ |
| Power | a ^ b | ^ a b | a b ^ |
| Modulus | a mod b | mod a b | a b mod |
| Unary plus | +a | +a | a+ |
| Unary minus | -a | -a | a- |
>Note that the multiplication operator contains the obligatory sign `*`. Processing an expression with the omitted `*` sign is optional and is left to the developer's decision.
- **Functions**:
| Function description | Function |
| ------ | ------ |
| Computes cosine | cos(x) |
| Computes sine | sin(x) |
| Computes tangent | tan(x) |
| Computes arc cosine | acos(x) |
| Computes arc sine | asin(x) |
| Computes arc tangent | atan(x) |
| Computes square root | sqrt(x) |
| Computes natural logarithm | ln(x) |
| Computes common logarithm | log(x) |

## Part 2. Bonus. Credit calculator

Provide a special mode "credit calculator" (you can take banki.ru and calcus.ru as an example):
- Input: total credit amount, term, interest rate, type (annuity, differentiated);
- Output: monthly payment, overpayment on credit, total payment.

## Part 3. Bonus. Deposit calculator

Provide a special mode "deposit profitability calculator" (you can take banki.ru and calcus.ru as an example):
- Input: deposit amount, deposit term, interest rate, tax rate, periodicity of payments, capitalization of interest, replenishments list, partial withdrawals list;
- Output: accrued interest, tax amount, deposit amount by the end of the term.

💡 [Tap here](https://forms.yandex.ru/cloud/64181abec769f101d44293de/) **to leave your feedback on the project**. Product Team really tries to make your educational experience better.
- **Arithmetic operators**:
| Operator name | Infix notation <br /> (Classic) | Prefix notation <br /> (Polish notation) | Postfix notation <br /> (Reverse Polish notation) |
| --------- | ------ | ------ | ------ |
| Brackets | (a + b) | (+ a b) | a b + |
| Addition | a + b | + a b | a b + |
| Subtraction | a - b | - a b | a b - |
| Multiplication | a * b | * a b | a b * |
| Division | a / b | / a b | a b \ |
| Power | a ^ b | ^ a b | a b ^ |
| Modulus | a mod b | mod a b | a b mod |
| Unary plus | +a | +a | a+ |
| Unary minus | -a | -a | a- |
>Note that the multiplication operator contains the obligatory sign `*`. Processing an expression with the omitted `*` sign is optional and is left to the developer's decision.
- **Functions**:
| Function description | Function |
| ------ | ------ |
| Computes cosine | cos(x) |
| Computes sine | sin(x) |
| Computes tangent | tan(x) |
| Computes arc cosine | acos(x) |
| Computes arc sine | asin(x) |
| Computes arc tangent | atan(x) |
| Computes square root | sqrt(x) |
| Computes natural logarithm | ln(x) |
| Computes common logarithm | log(x) |
Loading

0 comments on commit e13a803

Please sign in to comment.