• 第一次课堂作业之Circle


    1.问题描述:

    Create a program that asks for the radius of a circle and prints the area of that circle, using cin and cout. The whole program should be divided into two source files (.cpp). Hand in the source files and the head files which you create.

    2.解题想法:

    题目本身不难,主要就是把函数定义在main.cpp的外面,还要拆成.h声明和.cpp实现,百度了一下问题也不大。看到群里的讨论,本来想写成类里面的函数的我又跑去看了书上的外部函数。然后这次作业刚开始没有把几个文件放在一个项目里,一直找不到哪里错了。。。

    3.最终代码:

    main.cpp:

    #include<iostream>
    using namespace std;
    int main()
    {
        extern double Area (double);
        double r;
        cin>>r;
        cout<<Area(r)<<endl;
        return 0;
    } 
    

    area.h

    #define area.h
    #define pai 3.14
    double Area(double);
    #endif
    

    area.cpp

    #include"area.h"
    extern double Area(double t)
    {
        return pai*t*t;
    }
    

    其实后来把'extern'、'#define area.h'和'#endif' 去掉再调试,结果还是一样。。。
    然后这是:GITHUB的链接

    4.测试样例:

  • 相关阅读:
    HDU
    Groundhog Build Home
    The Moving Points
    Problem I. Count
    Problem E. TeaTree
    树的启发式合并
    Special Segments of Permutation
    网络流24题
    2015-2016 Northwestern European Regional Contest (NWERC 2015)
    The 2018 ACM-ICPC Asia Beijing Regional Contest
  • 原文地址:https://www.cnblogs.com/mingyueanyao/p/5463843.html
Copyright © 2020-2023  润新知