إمتحان سي بلس بلس C++ من كلية الدراسات العليا مع الإجابة

مفهوم – المتقدمين إلى دبلومة الحاسب الآلي في كلية الدراسات العليا للبحوث الإحصائية (جامعة القاهرة)، يجب عليهم أن يجتازوا إختباري لغة سي بلس بلس بجانب الرياضة.

نستعرض خلال هذه المقالة بعض أسئلة أحد إمتحانات السنوات السابقة مع الإجابة الصحيحة لكل سؤال.

بالتأكيد تتغير صياغة الأسئلة في كل عام عن الآخر، ولكن تبقى طبيعة الأسئلة واحدة في جميع الإختبارات.

السؤال الأول:

Question 1: (15 points)
Write a C++ program that accepts 100 numbers then puts the odd numbers in an array and the even numbers in another array. Finally, for each array display the entered numbers followed by their count, summation and average.

Answer:

#include <iostream>

int main()
{
int odd[50], even[50];
int x, count_odd=0,count_even=0,sum_even=0 , sum_odd=0;
for(int i=0;i<100;i++)
{
cout<<”enter number”;
cin>>x;
if(x%2==0)
{
even[count_even]=x;
count_even++;
sum_even+=x;
}
else
{
odd(count_odd)=x;
sum_odd+=x;
count_odd++;
}
}
cout<<”the elements of the even array are : “;
for (int i=0;i<cout_even;i++)
{cout<<even[i];}
cout<<”the summation of even is “ << sum_even;
cout<<”the average of even is “ << sum_even/count_even;
cout<<”the elements of the odd array are : “;
for (int k=0;k<cout_odd;k++)
{cout<<odd[i];}
cout<<”the summation of odd is ‘<<sum_odd;
cout<<”the average of odd is “ << sum_odd/count_odd;
system(“pause”);
return 0;
}

السؤال الثاني:

Question 2: (15 points)

Write a C++ program that accepts a number and displays its factorial (Note that: factorial (x)=x*(x-1)*(x-2)*(x-3) …*3*2*1).

int main()
{
int x,fact=1;
cout<<”enter number”;
cin>>x;
for(int i=1; i<=x;i++)
fact*=x;
cout<<”the factorial of “ <<x<<” is “ << fact;

return 0;
}

السؤال الثالث:

Question 3: (15 points)
Write a program using nested loops to create the following pattern:

Answer:

int main()
{

for(int i=5;i>0;i–) // i for line
{for(int j=1;j<=i;j++) // j for *
cout<<“*”;

cout<<endl;}
for(int i=2;i<=5;i++)
{for(int j=1;j<=i;j++)
cout<<“*”;

cout<<endl;}

return 0;
}

السؤال الرابع:

Question 4: (10 points)

Mark (true ) or (false) ahead of each statement

Comments cause the computer to print the text between the /* */ on the screen when the program is executed. ( X )

A C++ program that accepts three values for three variables must contain three statements using cin and the stream extraction operator. ( X )

The break statement in C++ is used to go to the beginning of the control structure. ( X )

A flowchart is a useful tool to represent a problem and not a solution. ( X )

For loop in C++ can replace do\while loop ( √ )
The Break statement can be used to exit either a Switch Case or a loop ( √ )

A variable is a name associated with a particular memory location to store data of a specific data type. ( √ )

C++ considers the variables empCount and Empcount to be identical. ( X )

The arithmetic operators *, /, + and % all have the same level of precedence. (X )

The initialize expression and increment expression are optional in the loop expression of a for loop. ( √ )

شاركها

اترك تعليقاً