Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Calculator based on C language MFC

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the C language MFC basis of how to achieve calculators, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Based on MFC calculator (base point)

Mainly in the implementation of MFC calculator encountered in the process of some problems, and some supplementary knowledge.

Requirements: present the process of calculator operation.

Idea: use two queues, one to store the input string (expression), and one to store the results.

Name them queue1 and myqueue, respectively, and queue the strings from left to right.

But after deducing according to my own way of thinking, I found that if the person who enters the queue is 1: 23, and if the next character is "+", then the result of 23 is first calculated into the myqueue, and 1 is still stored in queue1, but after the next "+" is entered into queue1, the queue1 contains 1, and finally the elements in myqueue are combined with queue1, and the final display in the edit box text is: 1: 1, 6

If the next operator is "*", the string in the queue is output directly.

Type conversions are involved in the implementation, such as converting CString to floating-point types.

At present, it has not been implemented, mainly because I am not familiar with the basic syntax and do not know how to use it.

First summarize some of the problems encountered in the previous period of time, and solutions.

Basic point

Queue:

Stack,queue, while the map function mapping library is a mapping from char to int, which implements the definition of priority.

Compare () in C++: pouring in to make comparisons between strings and substrings.

Getline (): reads the entire line, including leading and embedded spaces, and stores it in a string object.

Length=strlen (): traversing strings

Strlen (): you can do a counter that scans from a location in memory until the first string Terminator'\ 0' is encountered, and returns the calculator value.

Bool type to judge: true,falsef are: right and wrong, right and wrong, positive and negative

Atof (): converts characters to floating-point numbers

About file operations:

Ofstream (): write operation

Ofstream fout: a collection of file operations in C++SIT, including all commonly used file operations: inserters, extractors

Fout.open ("txt", ios::out): open file stream

Ifstream (): read operation, from hard disk to memory

Fstream (): read and write simultaneously

Ios:in, the file is opened as an input. # series article catalogue

Thank you for reading this article carefully. I hope the article "how to realize Calculator in C language MFC" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report