Programming Language
Med term 2024
By
Mohamed Mahamoud
بسم اهلل الرمحن الرحيم
َ ع ۡقدَ ٗة من ل
ساني يَ ۡفقَ ُهواْ قَ ۡولي ۡ ي أ َ ۡمري َو
ُ ٱحلُ ۡل ٓ ص ۡدري َويَس ۡر ل ۡ َرب
َ ٱش َر ۡح لي
صدق هللا العظيم
اللهم علمنا ما ينفعنا وانفعنا مبا علمتنا وزدنا بك علما انك انت العليم احلكيم
1) Which statement will read an entire line of input into the following string object
string address;
A) cin << address; B) cin address:
C) getline(cin, address); D) cin.get(address);
2) This stream manipulator forces cout to print the digits in fixed- point notation.
A) setprecision(2) B) serw (2) C) fixed D) setfixed(2)
3) What is the value of number after the following statements execute?
int number = 10;
number += 5;
number -=2;
number *= 3;
A) 3 B) 30 C) 39 D) 2
4) In a nested loop, the………..loop goes through all its iterations for every single
iteration of the …….loop
A) near/far B) far/near C) inner/outer D) outer/inner
5) The causes a program to wait until information is typed at the keyboard and the
Enter key is pressed
A) Output stream B) cin object C) cout object D) Preprocessor
6) reads a line of input, including leading and embedded spaces, and stores it in a
stang object
A) cin get B) getline C) cin getline D) get
7) What is the value stored at x, given the statements:
int x;
x = 3/static_cast<int> (4.5 +6.4):
A) 0.3
B) 0
C)0.275229
D) 3.3
8) When a variable is assigned a number that is too large for us data type, it
A) underflows
B) overflows
C) reverses polarity
D) exceeds expectations
Q2. (10 marks) What is the output of the following code fragments? You must
write the exact output as if the computer prints it. If it is any type of error, write
the type of error (for example, run time error).
int i=4, value = 1; 24
while (i > 1)
{value *=i; i-- }
cout << value;
void fun(int & p, int s) { 41
cout << p; p = 1; }
int main() {
int k =4; fun(k, 3); cout << k;
void func(int &x, int & y) { 78
int t = x; 87
x=y;
y=t;
int main() {
int u=7, v = 8;
cout << u << " " << v << endl;
func(u,v);
cout << u << " " <<v << endl;
}
void dostuff(int parValue, int& parRef) parValue in call to dostuff = 100
{ parRef in call to dostuff = 222
parValue = 100;
cout <<"parValue in call to dostuff =
"<<parValue << endl;
parRet =222;
cout <<"parRef in call to dostuff = "
<<<parRef << endl;)
consider call, we assume is in a
complete and correct
int n1 = 1, n2 = 2;
doStuff (n1, n2);
int a = 8 , b = 10; 8910
switch (a) {
case 4: cout << 4;
case 5: cout << 5; break;
case 8: cout <<< 8;
case 9: cout << 9; break;
default ; b=30 ; break ;
}
cout << b;
Q3. (3 marks) Write a piece of C++ program that accept a positive number in a
range and outputs
pattern:
Input an Integer number (less than 10): 4 [Enter]
16 16 16 16
999
44
ولو هتعمله هرم هيكون كده
Q4. (3 marks) Write a C ++ function distance that calculates the distance between
two points ( x1,y1) and ( x2,y2). All numbers and return values should be of type
double. If the second point is not given, the function calculates the distance to the
origin.
Q5. (5 marks) Write a complete C++ program and a function that calculates the
roots of the quadratic equation by implementing a suitable function. The function
must check if the roots are real or complex numbers. You must use pass by
reference to return the roots from the function. To return the Type of the roots, you
can use bool or string return value, or pass by reference. Show how to use this
function in the main() function using good formatted output
عشان تجيب حلول المعادلة التربيعية هنستخدم القانون العام
−𝑏 ± √𝑏 2 − 4𝑎𝑐
2𝑎
يكون للمعادلة حلول تخيلية وان اكبر هات الحلول من0 𝑏 اقل من2 − 4𝑎𝑐 واذا كان
القانون اللي فوق
وقالكbool في السؤال قالك استخدم فانكشن
reference استخدم ال
Q6. (5 marks) Write a complete C++ program that declares two ID arrays (matl and
mat2) of Size 4x1 double elements, initialized at declaration. The program sums
each opposite elements in each atray and store the result in the first array
standard format
لو فيه حاجه مش فاهمها او وقفت معاك او أكون غلطت في حاجه ابعتلي دوس هنا
إن ُوفقت فهو من هللا وإن
ال ف مني ومن الشيطان
والحمد هللا رب العالمين