当前位置:网站首页>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 .
边栏推荐
- Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
- Prefix infix suffix expression (written conversion)
- 利用模m的原根存在性判断以及求解
- Mysql8 one master one slave +mycat2 read write separation
- Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
- 基于Raft共识协议的KV数据库
- I am 35 years old.
- Beauty naked chat for a while, naked chat over the crematorium!
- 为什么要在时钟输出上预留电容的工位?
- 22-07-14 personal training match 2 competition experience
猜你喜欢
Leetcode and query question summary
22-07-12 personal training match 1 competition experience
【FreeSwitch开发实践】自定义模块创建与使用
Xshell batch send command to multiple sessions
QSS add resource file of QT
Kotlin program control
vscode 实用快捷键
2022-7-9 personal qualifying 6 competition experience
How to safely delete a useless activity in Android studio
B title: razlika priority queue approach
随机推荐
Matplotlib learning notes
Memory management - dynamic partition allocation simulation
【C语言】程序员筑基功法——《函数栈帧的创建与销毁》
2022年全国职业院校技能大赛“网络安全”竞赛试题文件上传渗透测试答案Flag
Shell homework the next day
If Yi Lijing spits about programmers
Alphabetic string
请问flink sql client 在sink表,有什么办法增大写出速率吗。通过sink表的同步时
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
Summary of common skills
Kotlin data type
Kotlin operator
Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
2022年收益率最高的理财产品是哪个?
Inaccurate problem of flutter fijkplayer seekto
Mysql8 one master one slave +mycat2 read write separation
Awk operation
为什么要在时钟输出上预留电容的工位?
Mysql/mariadb (Galera multi master mode) cluster construction
A little awesome, 130000 a month+