الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة بسيطة في حل هذا البرنامج !

بدأه THE HERO في 15 ديسمبر 2008 · 3 رد · 510 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

انا عندي مشكلة بسيطة في حل هذا البرنامج وان شاء الله اجد الاجابة عندكم

هذا هو السؤال

Write one function that receives the length L and the width W of a rectangle and returns back the perimeter and the area of the rectangle.

(Do not use cout inside the function).

- perimeter = (length + width) * 2

- area = length * width

You have to determine the adequate prototype of the function

المطلوب عمل فنكشن بدون ما استخدم داخلها سي اوت

انا عملت البرنامج بس المشكلة اللي واجهتني كيف اطلع ناتج المحيط والمساحة بدون سي اوت

استخدمت الريترن ولكن الريترن يطلع اما المساحة او المحيط

والبرنامج يطلب مني اخراج المساحة والمحيط معاَ

وهذا هو حلي

#include <iostream>
using namespace std;</SPAN></DIV> <DIV> </DIV> <DIV><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">int fun(int,int);</SPAN></DIV> <DIV> </DIV> <DIV><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">main () 
{
	int l,w;
	
	cout<<"enter length and width :\n"
   ; cin>>l>>w;
	
	cout<<"the perimeter and area : "<<fun(l,w);</SPAN></DIV> <DIV> </DIV><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"> <DIV>
	 getchar();
	 getchar();
}</DIV> <DIV> </DIV> <DIV>int fun(int l , int w)
{
	int pre,area;
	
	pre=(l+w)*2;
	area=l*w;
	
	return pre;
	
}

#2

هذه فكرة للحل:

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct d
  5. {
  6. int area;
  7. int perimeter ;
  8. };
  9.  
  10. d rectangle(int L,int W)
  11. {
  12. d f;
  13. f.area=L*W;
  14. f.perimeter=(L+W)*2;
  15. return f ;
  16. }
  17. int main(int argc, char *argv[])
  18. {
  19.  
  20.  
  21. cout<< rectangle(3,2).area<<endl;
  22. cout<< rectangle(3,2).perimeter<<endl;
  23.  
  24. cin.get();
  25. return 0;
  26. }
  27.  

tvquran_6.gif

#3

هذه طريقة اخرى :

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void rectangle(int& L,int& W)
  5. {
  6. int area=0;
  7. int perimeter=0 ;
  8. area=L*W;
  9. perimeter=(L+W)*2;
  10. L=area;
  11. W=perimeter;
  12. }
  13. int main(int argc, char *argv[])
  14. {
  15.  
  16. int L=3;
  17. int W=2;
  18. rectangle(L,W);
  19. cout<<L <<endl;
  20. cout<< W<<endl;
  21.  
  22. cin.get();
  23. return 0;
  24. }
  25.  

tvquran_6.gif

#4

يعطيكـ العآفيهـ اخوي فهد ماقصرت :)

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…