• 完美开篇 A + B


          程序设计是编写代码的核心,一个算法的好坏,很大程度上会影响一个完整程序的运行效率。所以,多多进行程序设计的练习是很有必要的。程序设计的练习,利用Online judge这类平台再好不过了,我就就近取材了,直接到了浙大的Online judge来练练吧。不知道能解多少题,以后就都记录在这里好了,祝自己好运,嘿嘿。

          A + B,就像Hello world一样有名了吧?几乎所有的Online judge的第一道题目都是这个,我也总喜欢用它先来配置自己的开发环境,第一篇,没什么好记录的,就把A + B拿出来说说事儿吧。顺道把Hello world 捎上。

    zhejiang university Online judge 1001 A + B

    #include<iostream>
    using namespace std;

    int main(void)
    {
        int a,b;
        while(cin>>a>>b)
        {
            cout<<a + b<<endl;
        }
        return 0;
    }

    反正也无聊的很,这代码肯定是不用解释的了。就顺道写个Hello world 面向对象版 14

    #include<iostream>
    #include<string>

    using namespace std;

    class CPP
    {
    public:
        CPP();
        CPP(string word);
        CPP(const CPP& cpp);
        CPP& operator=(const CPP& cpp);

        ~CPP();

        void Say();

        static void HelloWorld();
    private:
        string word;
    };

    CPP::CPP()
    {
        word = "Hello World !";
    }

    CPP::CPP(string word)
    {
        this->word = word;
    }

    CPP::CPP(const CPP& cpp)
    {
        this->word = cpp.word;
    }

    CPP& CPP::operator=(const CPP& cpp)
    {
        if(this == &cpp)
            return *this;
        this->word = cpp.word;
        return *this;
    }

    CPP::~CPP(){}

    void CPP::Say()
    {
        cout<<word;
    }

    void CPP::HelloWorld()
    {
        cout<<"Hello World !";
    }
    int main(void)
    {
        CPP::HelloWorld();//输出 HelloWorld!
        cout<<endl;

        CPP cpp;
        cpp.Say();//输出Hello World!
        cout<<endl;

        CPP cpp1("说点别的");
        cpp1.Say();//输出说点别的。
        cout<<endl;

        CPP cpp2(cpp1);
        cpp2.Say();//输出说点别的。
        cout<<endl;

        CPP cpp3("说点啥呢?");
        cpp2 = cpp3;
        cpp2.Say();//输出说点啥呢?

        getchar();
        return 0;
    }

    我这是自找麻烦!呵呵,算了,也算是复习一下面向对象最基本的概念吧。

  • 相关阅读:
    从属性文件中读取配置
    Page Object Manager
    在Selenium中使用JavaScriptExecutor处理Ajax调用?
    wait
    常用操作
    Selenium收藏官方网址
    PageObject样例
    解决办法-错误:Access denied for user 'root'@'localhost'
    Struts2中的OGNL详解
    用C++,调用浏览器打开一个网页
  • 原文地址:https://www.cnblogs.com/malloc/p/1670588.html
Copyright © 2020-2023  润新知