zoukankan      html  css  js  c++  java
  • 课程作业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.每个文件中代码量较少一些,不会全在一个文件中会看蒙了...

  • 相关阅读:
    STM32 USART整理说明(转)
    C++ 如何初始化静态类成员
    scp、sftp和ftps
    PostGIS介绍
    string.h和strings.h的区别
    linux编程中的段错误
    Linux中的man命令
    undefinded reference to 'pthread_create'问题
    多核编程框架
    与ComboBox有相似行为的下拉控件的实现
  • 原文地址:https://www.cnblogs.com/darkexisted/p/6776270.html
Copyright © 2011-2022 走看看