QTday1作业

自由发挥一个应用程序的登录界面,使用ui界面实现,基本功能都需要实现

cpp 复制代码
#include "mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(400,560);
    QLabel *lab = new QLabel(this);
    lab->resize(400,150);
    QMovie *mv =new QMovie("D:/缓存/pictrue/pictrue/qq2.gif");
    lab->setMovie(mv);
    mv->start();
    lab->setScaledContents(true);

    QLabel *lab3 = new QLabel(this);
    lab3->move(160,130);
    lab3->resize(60,60);
    lab3->setPixmap(QPixmap("D:/缓存/pictrue/pictrue/qq.png"));
    lab3->setScaledContents(true);
    lab3->setStyleSheet("border-radius:50px");

    QLabel *lab1 = new QLabel(this);
    lab1->move(80,250);
    lab1->resize(50,20);
    lab1->setText("账号");
    lab1->setStyleSheet("background-color:yellow");
    QLabel *lab2 = new QLabel(this);
    lab2->move(80,300);
    lab2->resize(50,20);
    lab2->setText("密码");
    lab2->setStyleSheet("background-color:yellow");


    QLineEdit *edit2 = new QLineEdit(this);
    edit2->move(130,250);
    edit2->setPlaceholderText("QQ号码/手机/邮箱");
    QLineEdit *edit1 = new QLineEdit(this);
    edit1->setEchoMode(QLineEdit::Password);
    edit1->move(130,300);
    edit1->setPlaceholderText("密码");


    //登录/取消按钮
    QPushButton *btn1 = new QPushButton("登录",this);
    btn1->move(100,400);
    btn1->resize(60,40);

    QPushButton *btn2 = new QPushButton("取消",this);
    //移动
    btn2->move(220,400);
    btn2->resize(60,40);


}

MyWidget::~MyWidget()
{
}

考试编程题

cpp 复制代码
#include <iostream>
#include <cstring>

class MyString {
private:
    char* data;
    size_t len;
public:
    MyString() : data(nullptr), len(0) {}
    MyString(const char* str)
    {
        if (str == nullptr)
        {
            data = nullptr;
            len = 0;
        } else
        {
            len = strlen(str);
            data = new char[len + 1];
            strcpy(data, str);
        }
    }
    MyString(const MyString &other)
    {
        len = other.len;
        if (other.data == nullptr)
        {
            data = nullptr;
        } else
        {
            data = new char[len + 1];
            strcpy(data, other.data);
        }
    }
    ~MyString()
    {
        delete[] data;
    }

    MyString& operator=(const MyString& other)
    {
        if (this != &other)
        {
            delete[] data;
            len = other.len;
            if (other.data == nullptr)
            {
                data = nullptr;
            } else
            {
                data = new char[len + 1];
                strcpy(data, other.data);
            }
        }
        return *this;
    }

    size_t getLength() const
    {
        return len;
    }

    MyString operator+(const MyString& other) const
    {
        MyString temp;
        temp.len = len + other.len;
        if (temp.len == 0)
        {
            temp.data = nullptr;
            return temp;
        }

        temp.data = new char[temp.len + 1];
        if (data != nullptr)
        {
            strcpy(temp.data, data);
        }
        if (other.data != nullptr)
        {
            strcat(temp.data, other.data);
        }
        return temp;
    }

    bool operator>(const MyString& other) const
    {
        if (data == nullptr && other.data == nullptr)
        {
            return false;
        } else if (data == nullptr)
        {
            return false;
        } else if (other.data == nullptr)
        {
            return true;
        }
        return strcmp(data, other.data) > 0;
    }

    friend std::ostream &operator<<(std::ostream& os, const MyString &str)
    {
        if (str.data != nullptr)
        {
            os << str.data;
        }
        return os;
    }

    friend std::istream& operator>>(std::istream &is, MyString &str)
    {
        char buffer[1024];
        is >> buffer;
        delete[] str.data;
        str.len = strlen(buffer);
        if (str.len == 0)
        {
            str.data = nullptr;
        } else
        {
            str.data = new char[str.len + 1];
            strcpy(str.data, buffer);
        }
        return is;
    }
};

int main() {
    MyString s1("Hello");
    std::cout << "s1: " << s1 << " len: " << s1.getLength() << std::endl;

    MyString s2 = s1;
    std::cout << "s2: " << s2 << std::endl;

    MyString s3;
    s3 = s1;
    std::cout << "s3: " << s3 << std::endl;

    MyString s4 = s1 + MyString(" World");
    std::cout << "s4 : " << s4 << " len: " << s4.getLength() << std::endl;

    std::cout << "s1 > s4? " << (s1 > s4 ? "Yes" : "No") << std::endl;

    MyString s5;
    std::cout << "please s5: ";
    std::cin >> s5;
    std::cout << "s5: " << s5 << " len: " << s5.getLength() << std::endl;

    return 0;
}

思维导图

相关推荐
H Journey1 小时前
C++之 CMake、CMakeLists.txt、Makefile
开发语言·c++·makefile·cmake
研究点啥好呢5 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
_dindong5 小时前
cf1091div2 C.Grid Covering(数论)
c++·算法
沫璃染墨5 小时前
C++ string 从入门到精通:构造、迭代器、容量接口全解析
c语言·开发语言·c++
6Hzlia6 小时前
【Hot 100 刷题计划】 LeetCode 17. 电话号码的字母组合 | C++ 回溯算法经典模板
c++·算法·leetcode
计算机安禾6 小时前
【数据结构与算法】第36篇:排序大总结:稳定性、时间复杂度与适用场景
c语言·数据结构·c++·算法·链表·线性回归·visual studio
unicrom_深圳市由你创科技6 小时前
做虚拟示波器这种实时波形显示的上位机,用什么语言?
c++·python·c#
无限进步_7 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio
C++ 老炮儿的技术栈7 小时前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt
橘颂TA7 小时前
【笔试】算法的暴力美学——牛客 NC213140 :除2!
c++·算法·结构与算法