zoukankan      html  css  js  c++  java
  • 完美开篇 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;
    }

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

  • 相关阅读:
    spring-AnnotationConfigApplicationContext源码阅读
    图解http pdf
    paasone的创新(2):separated langsysdemo ecosystem及demo driven debug
    Plan9:一个从0开始考虑分布式,分布appmodel的os设计
    terra++
    qtcling
    terracling:前端metalangsys后端uniform backend免编程binding生成式语言系统设想
    ubuntu touch: deepin pc os和deepin mobile os的天然融合
    windows版gbc:基于enginx的组件服务器系统paas,可用于mixed web与websocket game
    WinPE VirtIO云主机版 支持west263 阿里云aliyun 送精简win2k3镜像
  • 原文地址:https://www.cnblogs.com/malloc/p/1670588.html
Copyright © 2011-2022 走看看