السلام عليكم ورحمة الله وبركاته ..
لدي برنامج قمتُ بعمله في البداية بدون أن أضع فنكشنز ولكن طلبت مني الأستاذة أن أستخدم فنكشنز به
فبعد وضعها لم يتم البرنامج بشكل صحيح , ظهرت إيرور كثيرة
هل من تصحيح لها !!
جوزيتم خيراً مقدماً
هذا هو الكود :
#include <iostream>
#include <conio.h>
using namespace std;
int shape;
float x, a, b, c, h, l, w, r, d, PI = 3.14;
char ch, exit;
float CirAreaFun(float R);
float CirPerimeterFun(float D);
float SquAreaFun(float X);
float SquPerimeterFun(float X);
float RecAreaFun(float W);
float RecPerimeterFun(float W);
float ParalAreaFun(float B, float H);
float ParalPerimeterFun(float B, float H);
float RhomAreaFun(float X, float W);
float RhomPerimeterFun(float X);
float TrapAreaFun(float X, float H);
float TrapPerimeterFun(float X, float A, float B, float C);
float PentAreaFun(float X);
float PentPerimeterFun(float X);
float HexaAreaFun(float X);
float HexaPerimeterFun(float X);
float TriaAreaFun(float X);
float TriaPerimeterFun(float X);
void main()
{
cout << "Welcome to our calculate area and perimeter shapes program!\n";
do
{
cout << "\n***************************************";
cout << "\n* Enter your choice 1,2,3,4,5 or 6 ";
cout << "\n* 1. Circle ";
cout << "\n* 2. Square ";
cout << "\n* 3. Rectangle ";
cout << "\n* 4. Parallelogram ";
cout << "\n* 5. Rhombus ";
cout << "\n* 6. Trapezoid ";
cout << "\n* 7. Pentagon ";
cout << "\n* 8. Hexagon ";
cout << "\n* 9. Triangle ";
cout << "\n* 10. Exit ";
cout << "\n***************************************\n ";
if (shape == 1)
{
do
{
cout << "\n\n Enter your choice a , b or c ";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n enter the radius of ther circle \n";
cin >> r;
cout << "\nthe area of this circle =" << CirAreaFun(r);
}
break;
case 'b':
{
cout << "\n enter the diameter and PI of the circle\n";
cin >> d;
cout << "\nthe perimeter of this circle=" << CirPerimeterFun(d);
}
break;
}
}
while (ch != 'c');
}
else if (shape == 2)
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimiter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the lengh of" << "the. square \n";
cin >> x;
cout << "\n the area of this square=" << SquAreaFun(x);
}
break;
case 'b':
{
cout << "\n Enter the lengh of" << "the. square \n";
cin >> x;
cout << "\n the perimeter of this square=" << SquPerimeterFun(x);
}
break;
}
}
while (ch != 'c');
}
else if (shape == 3)
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n enter the length and the width of the rectangle \n";
cin >> l >> w;
cout << "\n the area of this rectangle \n" << RecAreaFun(w);
}
break;
case 'b':
{
cout << "enter the length and the width of the rectangle\n";
cin >> l >> w;
cout << "\n the perimeter of this rectangle =" << RecPerimeterFun;
}
break;
}
}
while (ch != 'c');
}
else if (shape == 4)
{
do
{
cout << "\n\n Enter your choice a , b or c ";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n enter the base and height of parallelogram \n";
cin >> b >> h;
cout << "\nthe area of this parallelogram =" << ParalAreaFun(b, h);
}
break;
case 'b':
{
cout << "\n enter the height and base of the parallelogram\n";
cin >> b >> h;
cout << "\nthe perimeter of this parallelogram=" << ParalPerimeterFun(b, h);
}
break;
}
}
while (ch != 'c');
}
else if (Shape == 5)
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the length of two diameters of the Rhombus\n";
cin >> x >> w;
cout << "\nthe area of this Rhombus =" << RhomAreaFun(x, w);
}
break;
case 'b':
{
cout << "\n enter the length of diameters of the Rhombus\n";
cin >> x;
cout << "\n the perimeter of this Rhombus=" << RhomPerimeterFun(x);
}
break;
}
}
while (ch != 'c');
}
else if (shape == 6)
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the length of two diameters of the trapezoid and height \n";
cin >> x >> x >> h;
cout << "\nthe area of this trapezoid =" << TrapAreaFun(x, h);
}
break;
case 'b':
{
cout << "\n enter the length of four diameters of the trapezoid\n";
cin >> x >> a >> b >> c;
cout << "\n the perimeter of this trapezoid=" << TrapPerimeterFun(x, a, b, c);
}
break;
}
}
while (ch != 'c');
}
else if (shape == '7')
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the length of the side \n";
cin >> x;
cout << "\nthe area of this Pentagon =" << PentAreaFun(x);
}
break;
case 'b':
{
cout << "\n enter the length of the side\n";
cin >> x;
cout << "\n the perimeter of this Pentagon=" << PentPerimeterFun(x);
}
}
while (ch != 'c');
}
else if (shape == 8);
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the length of side of the hexagon\n";
cin >> x;
cout << "\nthe area of this Hexagon =" << HexaAreaFun(x);
}
break;
case 'b':
{
cout << "\n enter the length of side of the hexagon\n";
cin >> x;
cout << "\n the perimeter of this Hexagon=" << HexaPerimeterFun(x);
}
break;
}
}
while (ch != 'c');
}
else if (shape == 9)
{
do
{
cout << "\n\n Enter your choice a, b or c";
cout << "\n a. area";
cout << "\n b. perimeter";
cout << "\n c. another shape";
cin >> ch;
switch (ch)
{
case 'a':
{
cout << "\n Enter the side length of the triangle\n";
cin >> x;
cout << "\nthe area of triangle =" << TriaAreaFun(x);
}
break;
case 'b':
{
cout << "\n enter the side length of triangle\n";
cin >> x;
cout << "\n the perimeter of this triangle=" << TriaPerimeterFun(x);
}
break;
}
}
while (ch != 'c');
}
else (shape == 10);
{
cout << "\n to exit to DOS press any key";
cout << "\nif you don't want to exit type (n)";
cin >> exit;
if (exit == 'n')
shape = 0;
}
}
while (shape != 10);
}
}
float CirAreaFun(float R)
{
return R * R*PI;
}
float CirPerimeterFun(float D)
{
return PI*D;
}
float SquAreaFun(float X)
{
return X*X;
}
float SquPerimeterFun(float X)
{
return 4 * X;
}
float RecAreaFun(float W)
{
return 1 * W;
}
float RecPerimeterFun(float W)
{
return (l + W)*2;
}
float ParalAreaFun(float B, float H)
{
return B*H;
}
float ParalPerimeterFun(float B, float H)
{
return 2 * (B + H);
}
float RhomAreaFun(float X, float W)
{
return 0.5 * X*W;
}
float RhomPerimeterFun(float X)
{
return 4 * X;
}
float TrapAreaFun(float X, float H)
{
return 0.5 * (X + X) * H;
}
float TrapPerimeterFun(float X, float A, float B, float C)
{
return X + A + B + C;
}
float PentAreaFun(float X)
{
return 5 * (X * X) / (4 * tan(PI / 5));
}
float PentPerimeterFun(float X)
{
return 5 * X;
}
float HexaAreaFun(float X)
{
return 0.5 * (3 * 1.73205)*(X * X);
}
float HexaPerimeterFun(float X)
{
return 6 * X;
}
float TriaAreaFun(float X)
{
return ((X * X)*1.73205) / 4;
}
float TriaPerimeterFun(float X)
{
return 3 * X;
}
