• 课程作业2


    作业二

    题目

    编写一个程序,要求根据给定的圆的半径求圆的面积,并将求得的结果打印出来。
    要求:
    输入输出采用cin和cout。
    建立一个工程,将程序写成两个.cpp和一个.h的形式。
    要求程序必须要对变量的定义和各个函数模块进行注释。
    变量命名符合命名规范。参考命名规范文档。
    提交一篇博客。博客内容为:github链接以及对文件分离的感想。

    GitHub地址

    // main.cpp
    #include "iostream"
    #include "Cal.h"
    using namespace  std;
    int main()
    {
    	double r,s;
    	cout<<"Please enter the radius of the circle:"<<endl;
    	cin>>r;
    	while (r<0)
    	{
    		cout<<"Your inout is wrong,the radius can not be nagative"<<endl;
    		cout<<"Please enter the radius of the circle:"<<endl;
    		cin>>r;
    	}
    	s = calculate(r);
    	cout<<"The area of the circle is:"<<s<<endl;
    	return 0;
    }
    
    //Cal.h
    #pragma once
    double calculate(double r);
    
    //Cal.cpp
    #include "Cal.h"
    #include "iostream"
    const double Pi = 3.1415;
    
    double calculate(double r)
    {
    	return r*r*Pi;
    }
    

    对文件分离的感想

    在程序较小时,没必要用到文件分离。然而在文件较大的时候就是很有必要的。
    1.使得文件后期更加容易维护,以及进一步的开发
    2.便于多人的合作开发
    3.每个文件中代码量较少一些,不会全在一个文件中会看蒙了...

  • 相关阅读:
    cocos2d 多点触摸
    mac 下安装node.js
    黑鹰破解笔记(2)
    OD使用心得笔记二
    淘宝店开始进行审核
    黑鹰破解笔记(1)
    Lisp笔记1
    OD使用心得笔记一
    怒马
    近段时间的web开发
  • 原文地址:https://www.cnblogs.com/darkexisted/p/6776270.html
Copyright © 2020-2023  润新知