zoukankan      html  css  js  c++  java
  • 圆面积

    github链接https://github.com/leijing000/object-oriented/tree/master/Circle

    一、题目描述:

    Create a program that asks for the radius of a circle and prints the area of that circle .
    Use 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 .

    二、代码实现(包含一个头文件和两个源文件)

    • Circle.h(声明函数,#define)
    #define pi 3.1415
    double calculate(double radius);
    
    • function.cpp(实现函数功能)
    #include"Circle.h"
    double calculate(double radius)
    {
        double area;
        area = pi*radius*radius;
        return area;
    }
    
    • main.cpp(计算圆的面积,调用函数)
    #include"Circle.h"
    #include<iostream>
    using namespace std;
    int main()
    {
        double area;
        double radius;
    
        cout << "Please enter the radius of the circle:";
        cin >> radius;
    
        area = calculate(radius);
    
        cout << "The area of the circle is: " << area << endl;
    
        return 0;
    }
    

    三、遇到的一些问题:

    • 出现这个问题的原因是我在define 后面加了分号,将分号去掉就可以了。

    • 写的过程中还出现了重定义的问题,我将在头文件中定义的变量放到了main.cpp里定义就可以了。

  • 相关阅读:
    第33周二
    第33周一
    第32周日
    第32周六
    RichTextBox 右键显示 ContextMenuTrip
    关于 Head First SQL 中文版
    linux进程通信之共享内存
    chroot 与 jail
    SQL基础--&gt; 约束(CONSTRAINT)
    MessageDigest简单介绍
  • 原文地址:https://www.cnblogs.com/leijing/p/5463889.html
Copyright © 2011-2022 走看看