calculator assignment

832101215陈思晟 2023-10-08 18:17:23
The Link Your Classhttps://bbs.csdn.net/forums/ssynkqtd-04
The Link of Requirement of This Assignment
https://bbs.csdn.net/topics/617332156
The Aim of This AssignmentA calculator with a visual interface
MU STU ID and FZU STU ID21125163_832101215

code in github :Yvcherl/ee308: ee308 (github.com)

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning7

5

Estimate1015
Development3030
Analysis2020
Design Spec2020
Design Review105
Coding Standard55
Design2020
Coding7060
Code Review1510
Test1010
Reporting55
Test Repor55
Size Measurement1010
Postmortem and Process and Improvement Plan75
sum214200

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. 

...全文
46 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

176

社区成员

发帖
与我相关
我的任务
社区描述
梅努斯软件工程
软件工程 高校 福建省·福州市
社区管理员
  • LinQF39
  • Jcandc
  • chjinhuu
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧