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

كود برنامج بالبوينتر مع محاولآتي ..

بدأه ريموو .. في 29 مايو 2009 · 5 رد · 820 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

هذا هو السؤال ..

Write a C++ program that reads a group of numbers from the user (maximum 50 integers) and places them in an array of type double. These numbers represent the lengths in inches. Once the numbers are stored in the array, your program should provide a function that converts the length in inches to centimeters then print them.

In main define :

- Array size as const variable with value of 50.

- An array numbers using the const variable.

- n variable use to save the numbers of element in an array. Make sure that n is a positive number <= 50.

- A pointer Ptr that points to the first element in the Array numbers.

Global functions:

- ReadArray (double* Nptr, int n): that reads n elements from the user.

- Centimize (double* ptrd, int n): that converts the length in inches to centimeters.

- PrintArray (const double *Nptr, int n): that prints n elements of an array.

وهذا الكود اللي سويته ..

#include <iostream>

using namespace std;

//==========================================

double ReadArray (double* Nptr, int n):

{

cout<<" How many numbers would you like to enter? \n";

cin >> n ;

while !=( n >=1 && n <=50){

cout<< " you Enter an Valide number .. Please Re Enter it again :";

cin >> n ;

}

return n ;

}

//==========================================

void Centimize (double* ptrd, int n)

{

* ptrd *= 2.54 ;

}

//==========================================

PrintArray (const double *Nptr, int n){

cout<< *Nptr ; }

//==========================================

int main(){

int Array size =50 ;

double a[Array size] ;

int *p ;

int n;

ReadArray (double* Nptr, int n) ;

Centimize (double* ptrd, int n);

PrintArray (const double *Nptr, int n) ;

return 0;

}

إيش الخطأ اللي عندي وياليت أحد يصححه لي ..

تم تعديل هذه المشاركة بواسطة ريموو .. في 29 مايو 2009 في 12:51

#2

السلام عليكم

الداله ReadArray اساسا لم تقرأ اى بيانات غير عدد العناصر

والداله Centimize كان ينقصها اللوب

وبعض الأخطاء الأخرى

#include <iostream>
using namespace std;

//==========================================
double ReadArray (double* Nptr, int& n)
{
cout<<" How many numbers would you like to enter? \n";
cin >> n;
while ( n <1 || n >50){
cout<< " you Enter an Valide number .. Please Re Enter it again :";
cin >> n;
}
for (int i=0;i<n;i++)
{
	cout<<"Enter num"<<i+1<<"  :  ";
	cin>>Nptr;
}
return n;
}


//==========================================
void Centimize (double* ptrd, int n)
{
	for (int i=0;i<n;i++)
	{
		ptrd*=2.54;
	}
}

//==========================================

void PrintArray (const double *Nptr, int n){

	for (int i=0;i<n;i++)
	{
		cout<<Nptr<<"  ";
	}
	cout<<endl;
 }

//==========================================

int main()
{
const int Arraysize =50;
double a[Arraysize];
int n;

ReadArray (a,n);
Centimize (a,n);
PrintArray (a,n);
return 0;
}

طبعا حجم المصفوفه يجب ان يكون const

فى امان الله

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#3

جزاك الله كل خير اخي ..

لكني حابه افهم اخطائي كي اتعلم ..

في الدالة

ReadArray

انا فقط قرآت من اليوز لكن ماوضعتها في الـ

Array

وفي الداله

Centimize

لماذا وضعت اللوب ..

وفي الداله

PrintArray

اخطأت في اني لما اجعلها لوب لكي تقرأ كل عنصر في المصفوفه

واخطأت في الداله الرئيسيه في اني لم اجعل حجم المصفوفه ثابت ..

جزاك الله كل خير يا اخي وسدد الله خطاك ..

#4

فى الداله Centimize

يجب وضع اللوب حتى يتم تحويل كل عناصر المصفوفه

وكمان فى الداله main

لاحظى طريقة استدعاء الدوال

تحياتى

عفوا تم تكرار المشاركه أرجوا من الإداره حذفها

تم تعديل هذه المشاركة بواسطة amin_mu123 في 29 مايو 2009 في 17:44

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#5

فى الداله Centimize

يجب وضع اللوب حتى يتم تحويل كل عناصر المصفوفه

وكمان فى الداله main

لاحظى طريقة استدعاء الدوال

تحياتى

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#6

جزاك الله كل خير اخي ..

اسعدك الله في الدنيا والاخرة ..

شكرا ً لك ..

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

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

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

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

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