谁会这个c++的题,希望哪个ds写一下。我目前主要没环境,所以就得完整一点。

编写自定义的头文件,在头文件中实现带参数的宏,其功能为求三角形面积。将头文件包含到自己的主程序中,并在主函数中实现三边的输入、宏的调用及输出其三角形面积的功能。

你可以参考一下,希望采纳支持一下博主
头文件 area.h

#pragma once
#include <math.h>
#define getArea(a, b, c) sqrt((a+b+c)/2 * ((a+b+c)/2 - a) * ((a+b+c)/2 - b) * ((a+b+c)/2 - c))

main函数

#include <iostream>
#include "area.h"
using namespace std;

int main()
{
    int a=0, b=0, c=0;
    cout << "请输入三角形的三边:" << endl;
    cin >> a >> b >> c;

    cout << "三角形面积是:" << getArea(a, b, c) << endl;

    return 0;
}

运行结果:

img

img


#define AREA(l,h) ((l)*(h)/2.0)
printf("%f",AREA(1*3,2*2));

(1)头文件:sanjiao.h

#ifndef _SANJIAO_HEAD
#define _SANJIAO_HEAD
#define area(a,h) (a*h/2.0)
#endif 

(2)源文件(.cpp):

#include<iostream>
#include<sanjiao.h>
using namespace std;
int main()
{
    float x, y,s;
    cout << "请输入三角形底和高:";
    cin>>x>>y;
    s = (double)area(x, y);
    cout<<s;
}