当前位置:网站首页>Human computer interaction software based on C language
Human computer interaction software based on C language
2022-07-26 08:38:00 【biyezuopin】
be based on C Language implementation of human-computer interaction software
Task overview
On the basis of data structure theory , Advance complexity 、 Full-featured 、 Programming with friendly interaction , Complete the algorithm realization problem and the comprehensive answer problem respectively .
Overview of content implementation
send C++ Qt The framework completes the graphic performance of the correlation graph algorithm in the algorithm implementation problem .
Make the sound clear UI frame SwiftUI Complete the comprehensive answer : Subway transfer system .



Algorithm implementation design description
subject
- The formula of adjacency matrix determines a graph , complete :
- Build and display its adjacent linked list ;
- Traversal with recursion and recursive depth first , Show traversal results , And display the stack at any time 、 situation ;
- First traverse the progress of the graph , Show traversal results , And show the queue at any time 、 situation .
software function
The software function is divided into two parts , Interaction and algorithm functions . Interaction embodies the operation that enables the software to advance from time to time ; The algorithm function reflects the real value of the software . The interaction adopts
C++ Qt frame , Algorithm functions adopt C++14, Make quantity C++ characteristic .
User interaction
First , Software has flexible boundaries , Almost all the visible elements in the painting can be dragged by the user logo , Make the user change the painting according to the demand .


secondly , The software has menu items for users to operate , The cutting operation is in the menu item , There are no more redundant options , So that households almost do not need any learning costs .

Last , There are rich shortcut keys in the menu , Simplify the operation of the software .( The operation of putting and shrinking can also make Ctrl/Command + The roller goes in , Experience naturally .)
Algorithm function
The software has fulfilled the requirements in function realization , Display the adjacency list corresponding to the directed graph in real time , And completed the depth ( Recursion and recursion )、 The result of degree first traversal is obvious , At the same time
Fruit and stack 、 Queue information . Animation effects are included in the display process , Render the displayed image in real time .

design idea
The design body of the program is divided into three blocks . First, the design and implementation of the algorithm book , Including all the required internal algorithm implementation , And the internal data structure , It doesn't contain any graphic circles ; The second is the design of graphic display , It represents graphic display , Does not contain any algorithm ; Finally, it's the whole of
close , Realize the synchronization of graphics and internal data structure . The design idea follows a design pattern
(Design Pattern): MVC(Model View Controller)[1].
Model
Data structure and algorithm model adopt C++ To write , Quanshi C++ Features such as templates
(template),auto, Range for loop 、C++11 Smart pointer to , The data structure of the basic standard library is as follows std::vector, The data structure of level-1 standard library is as follows std::deque、 std::unordered_set.
Definition of graph , It is a vertex storage Value Template of type value :
template<typename Value> struct Graph;
The code is easy to understand 、 There are detailed notes , More clear thinking , cut C++ Relevant knowledge can be found in
- Examination 《C++ Primer》[2] And officials [3]. Algorithm design reference 《 Introduction to algorithms 》[4]. The whole model is divided into two pieces :
- Graph.h: The data structure of graphs ,
- GraphAlgorithms.h: Depth first traversal isometric Algorithm .
The data structure of graph contains all graph operations , Such as adding vertices . Graph algorithm returns traversal results through graph operation 、 The result of each update of the stack or queue , For view display . The result type is SearchResult, Is to define the type , Be able to express the information required by all views :
struct SearchResult {
// It records the subscript order of some traversal .
std::vector<int> indexOrder; // The stack is recorded 、 Real time information of the queue .
std::vector<std::deque<int>> containerCondition;
};
By subscript order and stack 、 Real time information of the queue , It's easy to return to the view layer for rendering .
View
The view layer makes Qt As a development framework , Mainly transported Qt Of Graphics View
Framework[5], The framework can achieve the combination of components . In the program , The idea of graphic display is combination . Adjacency table is displayed by top-down links about each vertex , In this way, the whole view can be regarded as a combination of many vertex chains , It achieves the effect of building views from to .


Also for stacks and queues , It can be seen as a combination of many vertices , And add a frame .
The advantage of adopting the idea of combination in the whole program lies in the repetition of components , The vertices in the program are 4 In modules, the complex : The display of the graph 、 The display of adjacency table 、 Ergodic result 、 Real time update of stack or queue . So come , The graph of can be divided into individual parts , Reduce the burden of thinking and writing code .
Controller
The controller is the hub for coordinating views and models , With the controller, the separation and synchronization of view and model can be achieved . Its main task has two points . First, make Qt The classes in the model are encapsulated again , The organization is then provided to the view layer display . The second is the synchronization of model and view , For example, after you choose to clear vertices , The controller is responsible for clearing the vertices of the view layer , At the same time, clear the vertices of the model layer .
void clearGraph() {
if (isAnimating) {
QMessageBox::warning(this, " operation failed ", " Please wait for the animation to finish ");
return;
}
model.reset();
graphObject.reset();
adjointListGraph.resetFromRaw({});
}

When the user clicks to clear the vertex, the above code triggers . Code into 3 It's about reset,model.reset() Delete all vertices in the model ,
graphObject.reset() Delete the vertices in the display , Update the view , Finally, the code clears the adjacency table view . In this way, the model and view are synchronized .
Logical structure and physical structure
Next we will discuss Model The data structure of the Chinese graph model , About View and Controller The result table of can refer to the source code .
The vertices
template<typename Value> struct Graph<Value>::Vertex {
private:
friend struct Graph<Value>;
Value value;
// Adjacency list , Circular references are not generated , Automatically destroy with smart pointer ,
// `std::unordered_set<int>` Represents the subscript of the vertex in the graph instead of the value std::shared_ptr<std::unordered_set<int>> adjointList;
// ...
}
Each vertex contains the value it needs to store , This defines it as a template type Value. meanwhile , Because the whole graph adopts the formula of adjacency matrix to store , Every vertex will have a derived adjacency table , Here, the adjacency table is defined as a smart pointer to the ordered set .
The function of the smart pointer is to destroy the variables created in the heap according to the index count [2], Avoid memory leaks . The order set adopts the hash storage formula, so that the element is inserted and deleted only to O(1).( May refer to cppreference Chinese vs std::unordered_set Introduction to [2]) The function of this set is to store the subscripts of the adjacent vertices in the graph structure .( See below )
chart
/// Value should be hashable template<typename Value>
struct Graph {
private:
// `Graph<Value>::Vertex`, Defined below .
struct Vertex;
std::vector<Vertex> vertices;
// The mapping of each vertex value to its subscript .
std::unordered_map<Value, int> valueToIndex;
// ...
}
Figure is a template type , It can be of any type hashable To instantiate . There are two parts stored . First, the vertex vector[2], It is a linear table stored in sequence , You can dynamically insert and delete elements . Next is an order mapping , It maps from a given vertex value to its position in vector Subscript in , To optimize the direct pass value ( Subscript ) To figure out how to operate ( The operation of this should be based entirely on subscripts ).
The dynamic array formed by vertices and the adjacency table linked by each vertex , The data structure of a digraph can be a complete table .
Development platform
summary
operating system :macOS Mojave 10.14.6
Programming language :C++14
Development framework :Qt 5.13.0
compiler :clang-1001.0.46.4
IDE:CLion 2019.2(Build with CMake) Transportation environment the above environment can directly transport executable parts . If the above environment, you may need to recompile the whole project , It needs to be equipped with Qt Environment and holding C++14 And can compile Qt The compiler of the library is as MinGW、Clang. The analysis of the operation results of the system shows that at first I used Qt Creator As a development tool , Its advantage is that the environment is configured , Open to make , And integrated Qt Designer Then the production industry . However, its code improvement and community friendliness are not as good as Jetbrains Developed CLion.CLion The code function of allows me to guess the code function according to the description , During the development process, the frequency of reading files is reduced .

To configure CLion Also only needs CMake Code connection Qt Class library , Defecation . The only thing is not external Qt Designer Waiting will be more annoying , But the overall experience is good .
debugging
There are two kinds of debugging section , One is to view variable information by setting breakpoints , The second is through std::cout、qDebug Statements in CLion Integrated console output .

Version control system
In this development, the version control system Git[6] To save the history of the code . At the same time, make the code hosting platform GitHub Will the whole Git The warehouse is stored in the network platform , Make code “ There are traces to follow ”.
Git There are two , The most traditional way is through Mac Band Terminal, meanwhile CLion It is also integrated. Git And the console can make .


边栏推荐
- Fluent uses protobuf
- Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)
- Use of room database in kotlin
- Inaccurate problem of flutter fijkplayer seekto
- 【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
- 2022年全国职业院校技能大赛“网络安全”竞赛试题文件上传渗透测试答案Flag
- Oracle 19C OCP 1z0-083 question bank (7-12)
- memorandum...
- Two ways to monitor the change of user points
- Seq2seq and attention model learning notes
猜你喜欢

日常一记(11)--word公式输入任意矩阵

【FreeSwitch开发实践】自定义模块创建与使用
![[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)](/img/25/475c91d7e673fda3930e5a69be0f28.png)
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)

Kotlin function

Kotlin operator

MySQL 8.0 OCP (1z0-908) has a Chinese exam

Memory management based on C language - Simulation of dynamic partition allocation

Xshell batch send command to multiple sessions

Sub Chocolate & paint area

Bee guitar score high octave and low octave
随机推荐
Flutter upgrade 2.10
Memory management - dynamic partition allocation simulation
MySQL 8.0 OCP 1z0-908 certification examination question bank 1
六、品达通用权限系统__pd-tools-log
Basic music theory rhythm connection problem, very important
Kotlin function
Install HR schema, example, and Scott schema on Oracle and MySQL
If Yi Lijing spits about programmers
OSPF summary
Redis advanced
Dear teachers, how can sqlserver get DDL in flinkcdc?
Use of room database in kotlin
Vscode utility shortcut
Add in the registry right click to open in vscode
Spark SQL common date functions
Awk operation
Oracle 19C OCP 1z0-083 question bank (1-6)
Prefix infix suffix expression (written conversion)
Sub Chocolate & paint area
KV database based on raft consensus protocol