在我的计算机科学课上,我们正在制作一个程序,要求测量 4 个等腰梯形的高度、底部和顶部,计算周长并确定哪个具有最大周长。我的程序还没有完成,但我收到错误消息,指出没有匹配的函数可以调用 askInput
、calcPerimeter
和 findMax
.这是上下文的代码(抱歉,如果答案很明显,或者我的代码很草率,这是我参加的第一门编程课)。
#include <iostream>
#include <string>
using namespace std;
void intro();
void askInput();
double calcPerimeter();
double findMax();
double highest;
int main()
{
intro();
double t1, b1, h1, p1; //Top, bottom, height, and perimiter of first trapezoid
double t2, b2, h2, p2,
t3, b3, h3, p3,
t4, b4, h4, p4; //other four trapezoids
double max; //largest perimeter
askInput(t1, b1, h1, "first");
askInput(t2, b2, h2, "second");
askInput(t3, b3, h3, "third");
askInput(t4, b4, h4, "fourth");
p1 = calcPerimeter(t1, b1, h1);
p2 = calcPerimeter(t2, b2, h2);
p3 = calcPerimeter(t3, b3, h3);
p4 = calcPerimeter(t4, b4, h4);
max = findMax(p1, p2, p3, p4);
cout << "Results" << endl;
cout << "\tFirst: \tTop:" << t1 << "\tBottom: " << b1 << "\tHeight: " << h1 << "\tPerimeter: " << p1 << endl;
cout << "\tSecond: \tTop:" << t2 << "\tBottom: " << b2 << "\tHeight: " << h2 << "\tPerimeter: " << p2 << endl;
cout << "\tThird: \tTop:" << t3 << "\tBottom: " << b3 << "\tHeight: " << h3 << "\tPerimeter: " << p3 << endl;
cout << "\tFourth: \tTop:" << t4 << "\tBottom: " << b4 << "\tHeight: " << h4 << "\tPerimeter: " << p4 << endl;
cout << endl << "\tLargest Perimeter: " << highest << endl;
system("pause");
return 0;
}
void intro()
{
cout << "Lab G: Trapezoid with largest perimeter" << endl;
cout << "---------------------------------------" << endl; \
cout << "This program will calculate the perimeter of four trapezoids." << endl;
cout << "You will have to enter the top, bottom, and height of each trapezoid." << endl;
cout << "The program will then find the trapezoid with the largest perimeter and output it." << endl;
}
void askInput(double &top, double &bottom, double &height, string whichT)
{
cout << "Enter values for the " << whichT << " trapezoid." << endl;
cout << "\tTop: ";
cin >> top;
cout << "\tBottom: ";
cin >> bottom;
cout << "\tHeight: ";
cin >> height;
}
double calcPerimeter(double top, double bottom, double height)
{
double answer;
//some calculations
return answer;
}
double findMax(double a, double b, double c, double d)
{
double highest;
highest = a;
if (b > highest)
{
highest = b;
}
if (c > highest)
{
highest = c;
}
if (d > highest)
{
highest = d;
}
return highest;
}
最佳答案
声明中的函数签名必须与实现中的签名匹配。这意味着声明必须包含所有需要的函数参数类型。
void askInput(double &top, double &bottom, double &height, string whichT);
double calcPerimeter(double top, double bottom, double height);
double findMax(double a, double b, double c, double d);
关于调用时出现 C++ 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32900903/