如何通过主函数调用2个子函数(一个是输入矩形的边长,一个是计算它的面积)来实现求矩形的面积(用C++来实现)

来源:百度知道 编辑:UC知道 时间:2024/05/24 05:52:45
最好能把程序写下来,我实在想不出来,希望大家能帮帮我!

假设有这两个子函数:
void GetLength(double& width,double& height)
{
cout<<"长 宽";
cin>>width>>height;
}
double Area(const double& width,const double& height);
{
return width*height;
}
子函数的实现只是一个示例,可任意改写
主函数里这样调用:
double a,b;
GetLength(a,b);
cout<<"面积: "<<Area(a,b)<<endl;

//input函数输入矩形的边长(长和宽),area函数求矩形的面积。

#include<iostream.h>

void input(double &l,double &w)
{
cout<<"Please input the lenghth:";
cin>>l;
cout<<"\n"<<"Please input the width:";
cin>>w;
return;
};

double area(double l, double w)
{
double a=l*w;
return a;
}

void main()
{

double l, w, rea;
input(l,w);
rea=area(l,w);
cout<<"The area of the rectangular is:"<<rea<<"&