176
社区成员




The Link Your Class | https://bbs.csdn.net/forums/ssynkqtd-04 | |
---|---|---|
The Link of Requirement of This Assignment |
| |
The Aim of This Assignment | A calculator with a visual interface | |
MU STU ID and FZU STU ID | 21125163_832101215 |
code in github :Yvcherl/ee308: ee308 (github.com)
Personal Software Process Stages | Estimated Time(minutes) | Actual Time(minutes) |
Planning | 7 |
5 |
Estimate | 10 | 15 |
Development | 30 | 30 |
Analysis | 20 | 20 |
Design Spec | 20 | 20 |
Design Review | 10 | 5 |
Coding Standard | 5 | 5 |
Design | 20 | 20 |
Coding | 70 | 60 |
Code Review | 15 | 10 |
Test | 10 | 10 |
Reporting | 5 | 5 |
Test Repor | 5 | 5 |
Size Measurement | 10 | 10 |
Postmortem and Process and Improvement Plan | 7 | 5 |
sum | 214 | 200 |
1. Problem description
In this programming job, we need to create a simple calculator application with a graphical user interface. Calculators should be able to perform basic arithmetic operations, such as addition, subtraction, multiplication, and division. The user should be able to enter numbers and operators by clicking a button and see the results on the calculator's display.
2. How to solve the problem
Before we start writing code, we need to consider the following problem solving ideas:
What programming languages and frameworks are used? For this project, we will choose to use the Qt framework because it provides a powerful graphical user interface library and is well cross-platform.
How to organize the code? We will adopt the MVC (model-View-Controller) design pattern to separate the user interface, computational logic, and data.
How do I handle user input? We will create an event handler for each button and store the numbers and operators entered by the user in the variable to perform the calculation.
3. Design and implementation process
3.1. Code organization
We organized the code into the following major sections:
User interface design: Use Qt's graphic designer to create a calculator user interface.
Computational logic: Implements the core functions of the calculator, including processing numeric inputs, operators, and performing calculations.
Event handling: Create event handlers for each button so that users can interact with the calculator.
3.2
4. Code description
void MainWindow::on_pushButton_equal_clicked()
{
switch (choose)
{
case 1:
result+=S.toFloat()+process.toFloat();
sum=result;
Sresult=QString("%1").arg(result);
ui->textEdit_show->setText(Sresult);
break;
case 2:
result+=S.toFloat()-process.toFloat();
sum=result;
Sresult=QString("%1").arg(result);
ui->textEdit_show->setText(Sresult);
break;
case 3:
if(sum==0)
{
result=1;
}
else
{
result=sum;
}
if(S.toFloat()*process.toFloat()!=0)
{
result*=S.toFloat()*process.toFloat();
qDebug()<<result<<""<<sum;
}
else
{
result*=(S.toFloat()+process.toFloat());
qDebug()<<result<<""<<sum;
}
sum=result;
Sresult=QString("%1").arg(result);
ui->textEdit_show->setText(Sresult);
break;
case 4:
if(process.toFloat()==0)
{
ui->textEdit_show->setText("system error!");
QTimer::singleShot(1000,this,SLOT(on_pushButton_clear_clicked()));
break;
}
if(sum==0)
{
result=1;
}
else
{
result=sum;
}
if(S.toFloat()/process.toFloat()!=0)
{
result=S.toFloat()/process.toFloat();
qDebug()<<result<<""<<sum;
}
else
{
result/=(S.toFloat()+process.toFloat());
qDebug()<<result<<""<<sum;
}
sum=result;
Sresult=QString("%1").arg(result);
ui->textEdit_show->setText(Sresult);
break;
}
sum=result;
stat=-1;
choose=0;
S="";
process="";
}
5
6 Summarize
By doing this programming assignment, I learned how to use the Qt framework to create applications with graphical user interfaces and implement basic calculator functions. This project has helped me improve my event handling and user interface design skills. I also learned how to organize code to make it easy to maintain and extend. Overall, this assignment was a valuable learning experience for me.