zoukankan      html  css  js  c++  java
  • 2013第六周上机任务【项目1 程序改错】

    错误代码:

    #include<iostream>
    #include<stdlib.h>
    using namespace std;
    class C{
    private:
    	int x;
    public:
    	C(int x)  {this->x=x;}
    	int getX()  {return x;}
    };
    int main(){
        const C c(5);
    	cout<<c.getX();
    	return 0;
    }


    正确代码1:

    /* 
    * Copyright (c) 2013, 烟台大学计算机学院                     
    * All rights reserved.                     
    * 文件名称:test.cpp                     
    * 作者:樊露露                    
    * 完成日期:2013 年 4 月 5 日                     
    * 版本号:v1.0                   
    *                     
    * 输入描述:无                     
    * 问题描述:                  
    * 程序输出:
    * 问题分析:                    
    * 算法设计:略                     
    */         
    #include<iostream>
    #include<stdlib.h>
    using namespace std;
    class C{
    private:
    	int x;
    public:
    	C(int x)  {this->x=x;}
    	int getX() const {return x;}
    };
    int main(){
        const C c(5);
    	cout<<c.getX();
    	return 0;
    }
    


    正确代码2:

    /* 
    * Copyright (c) 2013, 烟台大学计算机学院                     
    * All rights reserved.                     
    * 文件名称:test.cpp                     
    * 作者:樊露露                    
    * 完成日期:2013 年 4 月 5 日                     
    * 版本号:v1.0                   
    *                     
    * 输入描述:无                     
    * 问题描述:                  
    * 程序输出:
    * 问题分析:                    
    * 算法设计:略                     
    */         
    #include<iostream>
    #include<stdlib.h>
    using namespace std;
    class C{
    private:
    	int x;
    public:
    	C(int x)  {this->x=x;}
    	int getX()  {return x;}
    };
    int main(){
        C c(5);
    	cout<<c.getX();
    	return 0;
    }
    


    输出结果:

  • 相关阅读:
    Qt之QFileSystemWatcher
    Qt之qSetMessagePattern
    物联网操作系统HelloX V1.80测试版发布
    CoreOS Linux available in China
    等火车
    HTTP 简介
    建造模式Builder
    MariaDB exists 学习
    javascript 中 typeof 的使用
    Java字符串null相加
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3000828.html
Copyright © 2011-2022 走看看