这个程序定义了多少个函数? [英] How many functions are defined in this program?

查看:112
本文介绍了这个程序定义了多少个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解释下面的问题吗?



除了main()函数外,这个程序还定义了多少个函数?

给出每个函数的原型?

给出每个函数的参数?





Can someone please help me to answer the following questions with explanation?

How many functions are defined in this program, besides the main() functions?
Give the prototype of each function?
Give the arguments of each function?


#include <iostream> 
#include <string>
using namespace std;

int addition (int, int );
int subtraction (int , int ); 
void directions();
void printResult(int , int , int , string);

int main ()
{   
    int x,y,r;   
    directions();    
    cout << "Please enter the first integer: ";    
    cin >> x;    
    cout << "Please enter the second integer: ";    
    cin >> y;  
    r = addition(x,y);  
    printResult(x,y,r,"+");
    r = subtraction(x,y);  
    printResult(x,y,r,"-");  
    system("pause");   
    return 0;
}

int addition (int a, int b)
{   
    int r;  
    r=a+b;   
    return (r);
} 

int subtraction (int a, int b)
{   
    int r;  
    r=a-b; 
    return (r);
}

void directions() 
{
    cout << "********************************************************" << endl << "Hello!" << endl
    << "This Program asks the user for two integers, then prints the sum and difference" << endl

    << "******************************************************" << endl << endl;
}

void printResult(int a, int b, int result, string operation)
{ 
    cout << a << " " << operation << " " << b << " = " << result << endl;
}

推荐答案

这可能是你的功课,你应该自己思考一下。



分析任何代码的第一步是让它易于阅读。

我为你做了那一步。

多少函数你现在看到了吗?



至于那些基本的C知识的原型和论据。



你可以在这里阅读有关原型的信息维基百科:函数原型 [ ^ ]

此页面还包含参数。
Well this is probably your homework and you should do some thinking yourself.

The first step in analyzing any code is to make it easy to read.
I did that step for you.
How many functions do you see now?

As for prototypes and arguments that is kind of basic C knowledge.

You can read about prototypes here Wikipedia: Function prototype[^]
This page also cover the arguments.


这篇关于这个程序定义了多少个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆