Apr 3, 2018 at 5:27pm UTC
My c++ source code keeps saying "expression preceding parenthesis of apparent call must have(pointer-to-) function type"
I have no clue what is going on or how to fix it please help :(
#include "stdafx.h"
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
class RECTANGLE
{
private: float Length, Width;
public: RECTANGLE();
float computeArea(float& area);
float computePerimeter(float& perimeter);
void displayAreaPer(float area, float perimeter);
~RECTANGLE() {}
};
class TRIANGLE
{
private: float sideA, sideB, sideC;
public: TRIANGLE();
float computePerimeter(float& perimeter);
float computeArea(float& area);
void displayAreaPer(float area, float perimeter);
~TRIANGLE() {}
};
class TRAPEZOID
{
private: float lowerBase, upperBase, height;
float leftSize, rightSide;
public: void readData();
void computeAreaPer(float &area, float& per);
void displayAreaPer(float area, float per);
};
int main()
{
float area, perimeter, per;
RECTANGLE t;
t.computeArea(area);
t.computePerimeter(perimeter);
t.displayAreaPer(area,perimeter);
TRIANGLE l;
area = l.computeArea(area);
l.computePerimeter(perimeter);
l.displayAreaPer(area, perimeter);
TRIANGLE D;
D.computeArea(area);
D.computePerimeter(per);
D.displayAreaPer(area, per);
system("Pause");
return 0;
}
RECTANGLE::RECTANGLE()
{
cout << "Enter the values of width and length of a rectangle: ";
cin >> Width >> Length;
}
float RECTANGLE::computeArea(float &area)
{
return area = Width * Length ;
}
float RECTANGLE::computePerimeter(float& perimeter)
{
return perimeter = (2 * Width) + (2 * Length);
}
void RECTANGLE::displayAreaPer(float area, float perimeter)
{
cout << fixed << setprecision(2);
cout << " Area= " << area << endl;
cout << " Perimeter= " << perimeter << endl;
}
TRIANGLE::TRIANGLE()
{
float sideA, sideB, sideC;
cout << "Enter the values of width and length of a triangle: ";
cin >> sideA >> sideB >> sideC;
}
float TRIANGLE::computeArea(float& area)
{
float sideA, sideB, sideC, p;
p = ((sideA + sideB + sideC) / 2);
return area = sqrt(p(p-sideA)(p-sideB)(p-sideC)); <-------------error here
}
float TRIANGLE::computePerimeter(float& perimeter)
{
float sideA, sideB, sideC;
return perimeter = (sideA + sideB + sideC);
}
void TRIANGLE::displayAreaPer(float area, float perimeter)
{
cout << fixed << setprecision(2);
cout << "Area= " << area << endl;
cout << "Perimeter= " << perimeter << endl;
}
void TRAPEZOID::readData()
{
float lowerBase, upperBase, height, leftSide, rightSide;
cout << "Enter the lowerBase, upperBase, and Height: ";
cin >> lowerBase >> upperBase >> height;
cout << "Enter the left and right sides: ";
cin >> leftSide >> rightSide;
}
void TRAPEZOID::computeAreaPer(float &area, float& per)
{
float lowerBase, upperBase, height, leftSide, rightSide;
area = ((lowerBase + upperBase) * height) / 2;
per = lowerBase + upperBase + leftSide + rightSide;
}
void TRAPEZOID::displayAreaPer(float area, float per)
{
cout << "Area= " << area << endl;
cout << "Preimeter= " << per << endl;
}
Last edited on Apr 3, 2018 at 5:31pm UTC
Apr 3, 2018 at 5:42pm UTC
return area = sqrt(p(p-sideA)(p-sideB)(p-sideC)); <-------------error here
Do you want to multiply each of them? If yes, you have to put a asterisc in between, that way:
return area = sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
Does that work? Or is it something else you want?
Last edited on Apr 3, 2018 at 5:42pm UTC