• 0
I L Technology

برنامج يحسب مساحة ومحيط عدة اشكال .. يحوي إيرور تحتاج تصحيح c++

سؤال

السلام عليكم ورحمة الله وبركاته ..

لدي برنامج قمتُ بعمله في البداية بدون أن أضع فنكشنز ولكن طلبت مني الأستاذة أن أستخدم فنكشنز به

فبعد وضعها لم يتم البرنامج بشكل صحيح , ظهرت إيرور كثيرة

هل من تصحيح لها !!

جوزيتم خيراً مقدماً

هذا هو الكود :


#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;
}

تم تعديل بواسطه محمد عودة
تنسيق الكود.
0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

2 إجابة على هذا السؤال .

  • 0

أخى الكريم

يا لله حوالى 600 سطر من الكود وتريد اصلاح الخطأ.

  • قم بتنظيم اكوادك واضف لها التعليقات
  • قم بتوضيح الحد الفاصل بين الدالة الرئيسية والدوال الاخري
  • قم بالتأكد من ان كل قوس مقفع مفتحوح قد اغلقتة
  • راجع بنية if, else if من فضلك ..

هذة الملاحظات والاخطاء قد وجتها اثناء تطبيق التنسيق الآلى على اكواك فى بيئة netBeans وفقك الله

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

بعض المساحات لبعض الأشكال الهندسية غير صحيحة

الكود بعد التعديل

#include <iostream>
#include <conio.h> //for getch()
#include <cstring> // for strcmp()
#include <cmath> // for sqrt() && pow()
#define Max 20

using namespace std;


float x=0, a=0, b=0, c=0, h=0, l=0, w=0, r=0, d=0,L=0,S=0,H1=0,H2=0,X1=0,X2=0,X3=0,X4=0;
const float PI = 3.14; // pi=22/7 الثابتة
float CirAreaFun(float );// مساحة دائرة
float CirPerimeterFun(float);// محيط دائرة
float SquAreaFun(float );// مساحة مربع
float SquPerimeterFun(float );//محيط مربع
float RecAreaFun(float,float );//مساحة مستطيل
float RecPerimeterFun(float,float );//محيط مستطيل
float ParalAreaFun(float , float);//مساحة متوازي الأضلاع
float ParalPerimeterFun(float , float );//محيط متوازي الأضلاع
float RhomAreaFun(float , float ); // مساحة معين هندسي
float RhomPerimeterFun(float );// محيط معين هندسي
float TrapAreaFun(float , float ); //مساحة شبه منحرف
float TrapPerimeterFun(float , float, float , float); // محيط شبه منحرف
float PentAreaFun(float ,float );//مساحة خماسي منتظم
float PentPerimeterFun(float );//محيط حماسي منتظم
float HexaAreaFun(float ,float);// مساحة سداسي منتظم
float HexaPerimeterFun(float );// محيط سداسي منتظم
float TriaAreaFun(float ,float );// مساحة مثلث متسواي الأضلاع
float TriaPerimeterFun(float );//محيط مثلث متساوي الأضلاع

int main()

{
float z=sqrt((5-sqrt(5))*0.5) , zz=3*sqrt(3)*0.5;
char ch, exit[Max]="", shape[Max]=""; int log=0;
const char *ph="\n\n Enter your choice a , b or c \na. area\nb. perimeter\nc. another shape";
y:;
cout << "Welcome to our calculate area and perimeter shapes program!\n";
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 ";
cin >> shape ;

if (strcmp(shape,"1")==0)
{
z2:;
cout << ph;
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;


case 'c': goto z2; break ;
default: break;
}

}

else if (strcmp(shape,"2")==0)

{
z3:;
cout << ph;
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;
case 'c': goto z3; break ;
default: break;
}}


else if (strcmp(shape,"3")==0)
{
z4:;
cout << ph;
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(l,w);

break;

case 'b':

cout << "enter the length and the width of the rectangle\n";
cin >> l;
cin >> w;
cout << "\n the perimeter of this rectangle =" << RecPerimeterFun(l,w);

break;
case 'c': goto z4; break ;
default: break;

}}


else if (strcmp(shape,"4")==0)
{
z5:;
cout << ph;
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 length of the largest and smallest side of parallelogram\n";

cin >> L >> S;

cout << "\nthe perimeter of this parallelogram=" << ParalPerimeterFun(L, S);



break;

case 'c': goto z5; break ;
default: break;

}

}


else if (strcmp(shape,"5")==0)
{
z6:;
cout << ph;

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;

case 'c': goto z6; break ;
default: break;

}

}

else if (strcmp(shape,"6")==0)
{
z7:;
cout << ph;

cin >> ch;

switch (ch)

{

case 'a':

cout << "\n Enter the length of two Bases of the trapezoid \n";

cin >> H1 >> H2 ;

cout << "\nthe area of this trapezoid =" << TrapAreaFun(H1,H2);
break;

case 'b':

cout << "\n enter the length of four diameters of the trapezoid\n";

cin >> X1 >> X2 >> X3 >> X4;

cout << "\n the perimeter of this trapezoid=" << TrapPerimeterFun(X1, X2,X3, X4);


break;

case 'c': goto z7; break ;
default: break;

}

}


else if (strcmp(shape,"7")==0)
{
z8:;
cout << ph;

cin >> ch;

switch (ch)

{

case 'a':

cout << "\n Enter Radius of the circle surrounding \n";

cin >> r;

cout << "\nthe area of this Pentagon =" << PentAreaFun(r,z);


break;

case 'b':

cout << "\n enter the length of the side\n";

cin >> x;

cout << "\n the perimeter of this Pentagon=" << PentPerimeterFun(x);

case 'c': goto z8; break ;
default: break;
}

}


else if (strcmp(shape,"8")==0)
{
z9:;
cout << ph;

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,zz);

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;

case 'c': goto z9; break ;
default: break;

}

}


else if (strcmp(shape,"9")==0)
{
z10:;
cout << ph;

cin >> ch;

switch (ch)

{

case 'a':

cout << "\n Enter the base and Height of the triangle\n";

cin >> b >> h;

cout << "\nthe area of triangle =" << TriaAreaFun(b,h);


break;

case 'b':

cout << "\n enter the side length of triangle\n";

cin >> x;

cout << "\n the perimeter of this triangle=" << TriaPerimeterFun(x);


break;

case 'c': goto z10; break ;
default: break;

}

}


else if (strcmp(shape,"10")==0)

{

cout << "\n to exit to DOS press any key";

cout << "\nif you don't want to exit type (n)";

cin >> exit;

if(strcmp(exit,"n")!=0) return 0;

}

else goto y;

if(log==0) goto y;

getch();//freeze screen until keypres
return 0;
}



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 l,float W)
{
return (l*W);
}

float RecPerimeterFun(float L,float W)
{
return ((l + W)*2);
}

float ParalAreaFun(float B, float H)
{
return (B*H);
}

float ParalPerimeterFun(float L, float S)
{
return (2*(L + S));
}

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 * (H1 +H2));
}

float TrapPerimeterFun(float X1, float X2, float X3, float X4)
{
return (X1 + X2 + X3 + X4);
}

float PentAreaFun(float r,float z)
{

return (r*z);
}

float PentPerimeterFun(float X)
{
return (5 * X);
}

float HexaAreaFun(float X,float zz)
{
return zz*(pow(X,2));
}

float HexaPerimeterFun(float X)
{
return (6 * X);
}

float TriaAreaFun(float b,float h)
{
return (b*h*0.5);
}

float TriaPerimeterFun(float X)
{
return (3*X);
}

و نسأل الله لنا ولك التوفيق

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

  • يستعرض القسم حالياً   0 members

    لا يوجد أعضاء مسجلين يشاهدون هذه الصفحة .