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

هل حلولى صحيحه؟

بدأه سرمد الليل في 21 مايو 2010 · 8 رد · 1,307 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السوال الاول :

Find the error in each of the following segments and correct it.

a)

int * number ;

cout<< number <<endl ;

*numberb)

b)

double *realptr ;

long *integerptr ;

integerptr = realptr ;

*integerptr = * realptr ;

d)

int *x , y ;

x = y ;

*x=y;

d)

char s[] = "this is a character array" ;

for ( ; *s != '\0' ; s++)

cout<< *s ;

for ( int *s; *s != '\0' ; *s++)

________________________________________________________________________

السوال الثانى :

Write a program that reads and stores integer numbers in the 2-D array of 10 rows and 20 columns. Then the program uses the function reverseDiagonal to reverse both the diagonals of the array.

محاولتى :

#include<iostream>

using namespace std;

void reverseDiagonal (int [][]);

int main()

{ int a[10];

int a;

cout<<"Enter 10 integers:"<<endl;

reverseDiagonal (a);

cin>>a

cout<<endl<<"The array contains:"<<endl;

for(int j=0;j<10;j++)

cout<<"a["<<j<<"] = "<<a[j]<<endl;

return 0}

void reverseDiagonal (int a[][])

{for(int c=0;c<10;c++)

for(int r=0;r<20;r++)

a=[c][r];}

________________________________________________________

وماهو حل هذا السوال لاننى حاولت كثير ولم استطع ايجاد الحل

Write a C++ program that ask user to enter the number in decimal then convert it to the binary and vise versa .

Be sure that your program have the following :

1- Recursive function that convert from binary to decimal.

2- Validate function that check if the binary number entered by the user contain only 0s and 1s .

How Convert from binary to decimal :

To convert binary into decimal is very simple and can be done as shown below:

Say we want to convert the 4 bit value 1001 into a decimal value, we can use a formula like that below:

128 64 32 16 8 4 2 1

1 0 0 1

As you can see, we have placed the numbers 1, 2, 4, 8, 16, 32, 64, 128 (powers of two) in reverse numerical order, and then written the binary value below.

To convert, you simply take a value from the top row wherever there is a 1 below, and then add the values together.

For instance, in our example we would have 8 + 1 = 9 .

Because we know binary is base 2 then the above could be written as:

1*23 + 0*22 + 0*21 + 1*20 = 9 .

#2

مااافى احد يرد؟؟؟

#3

السلام عليكم

سأحاول أن أساعدك على قلة علمي، لذلك قد يكون هناك أخطاء في حلي:

a)

int * number ;

cout<< number <<endl ;

*number

أظن أن الخطأ فعلياً هو أنك قمت بتعريف مؤشر، وتريد أن تطبع العنوان الذي يشير إليه، مع أنك لم تحدد عنواناً لهذا المؤشر ليشير إليه.

b)

double *realptr ;

long *integerptr ;

integerptr = realptr ;

*integerptr = * realptr ;

أظن المشكلة هنا هي ذاتها، فلا يوجد عنوان صالح يشير إليه المؤشر realptr، وأظن أن هناك مشكلة أخرى وهي أننا نسند realptr إلى integerptr مع أن أولهما double وثانيهما long.

d)

int *x , y ;

x = y ;

*x=y;

حلك صحيح جزئياً هنا، ففعلاً يجب وضع المعامل * قبل x في هذه الحالة، لكن المشكلة أيضاً وكسابقاتها أنه لم يتم تحديد عنوان لـx ليضع القيمة فيه، بالإضافة إلى أنه لم يتم تحديد قيمة y.

d)

char s[] = "this is a character array" ;

for ( ; *s != '\0' ; s++)

cout<< *s ;

for ( int *s; *s != '\0' ; *s++)

هذا لست متأكداً منه، لكن أظن التصحيح يكون كالتالي (أرجو أن يصحح أحد لي في حال خطئي):

for (char *i= s; *i != '\0'; i++)
cout<< *i;

وهذا لنقوم بالانتقال بين محارف الجملة الموضوعة في s.

أرجو أن ينظر أحد الخبراء لأنني لا أضمن صحة حلولي.

بالنسبة للتمارين التالية سأحاول فيها ثم أضع حلي.

بالتوفيق

تم تعديل هذه المشاركة بواسطة Abboodd في 21 مايو 2010 في 14:41

هذه الجملة خاطئة  :wacko: 


#4

ماااحد يرد على بليززززززززززز ردو ضرورى

#5

هذا للسؤال الاخير دوال التحويل:

#include<iostream>
#include<string>
using namespace std;


int bin(int n){
if(n)return n%2+bin(n/2)*10;
return 0;

}
int dec(int n,int i=0)
{
if(n%10>1) return -1;
if (n>0) 
return n%10*pow(2.0,i)+dec(n/=10,i+=1);
else 
return 1;
} 



int main(){
cout<<dec(101001)<<endl;
cout<<bin(12)<<endl;


}

السؤال الاول طبق الاكواد في الكمبايلر وحاول تفهم الاخطأ الامر ليس بالصعب

tvquran_6.gif

#6

والسوال الثانى هل ماهو الخطا فى حلى

#7

؟؟؟؟؟؟؟؟؟؟

#8

بالنسبة للسؤال الثاني : هذا تصحيح الكود:

#include<iostream>
#include<cstdlib>
using namespace std;


const int rows =10;
const int columns=20;

void reverseDiagonal (int [][columns]);

int main()

{
int arr[rows][columns];

for(int r=0;r<rows;r++){
for(int c=0;c<columns;c++){
//cout<<"["<<r<<"]["<<c<<"]=";cin>>arr[r][c]; //for enter user
//arr[r][c]=rand()%9+1; 	//for random
}}
for(int r=0;r<rows;r++){
for(int c=0;c<columns;c++){
cout<<arr[r][c]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<endl;
reverseDiagonal(arr);

for(int r=0;r<rows;r++){
for(int c=0;c<columns;c++){
cout<<arr[r][c]<<" ";
}
cout<<endl;
}

cin.get();

return 0;
}


void reverseDiagonal (int a[][columns]){
int t1[10];
int t2[10];
int i=0,j=0,p1,p2;
for(int r=0;r<rows;r++){
for(int c=0;c<columns;c++){
if((r==c))t1[i++]=a[r][c];
if((r==19-c))t2[j++]=a[r][c];
}
}

i=0;j=0;
for(int s=0;s<5;s++){
p1=t1;
t1=t1[9-s];
t1[9-s]=p1;
p2=t2;
t2=t2[9-s];
t2[9-s]=p2;
}

for(int r=0;r<rows;r++){
for(int c=0;c<columns;c++){
if((r==c)) a[r][c]=t1[i++];
if((r==19-c)) a[r][c]=t2[j++];
}
}


}
tvquran_6.gif

#9

جزاك الله خير

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