Prog2 _ Mid1

advertisement
‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعــة‬
‫كلية العلوم بالزلفي‬
‫قسم علوم الحاسب والمعلومات‬
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Collage of Science at Al-Zulfi
Computer & Information Dept.
1st midterm exam - Second Semester 1435-1436H
Course Name: Programming Lang.(2)
Time Allowed: 90 minutes
- Course Code: CSI 221 -
Section: 215
)2( ‫امتحان النصف فصلي األول لمادة برمجة‬
Date: Sun. 24/ 05/ 1436 H  14 / 03 / 2015 G.
Number of Pages: 5
Student's Name:......................................................................................................
Student's ID: ............................................................................................................
Instruction:
1. Write your name and your academic identification number fully and clearly.
2. Use blue or black pen to answer, pencils only for drawing.
3. Books and notes are not allowed.
4. Students are not allowed to leave before the lapse of 30 minutes from the beginning
of the exam.
Learning Outcomes
Knowledge
1.1
1.2
a2
1.3
Cognitive Skills
1.4
a3
2.1
2.2
b1
b2
Question
Outcome covered
1
a2,a3
2
b1,b2
3
2.3
Communication, Information
Technology, Numerical
Interpersonal Skills
2.4
3.1
3.2
3.3
3.4
c3
Correction
Verification
c3
Total
4.1
4.2
4.3
d1
Faculty Member
Course
coordinator
Dr. Wael Khedr
Revision Committee
Name
Final Mark :
Signature
/ 15
Marks:……………………………………………………………………………
2 ‫نموذج‬
1
Question(1) : Multiple Choice Questions------------------------------------[5 marks]
1. A structure brings together a group of
a. items of the same data type.
b. related data items.
c. integers with user-defined names.
d. variables.
2.
char functionA( void );
a. It does not receive any arguments and return character value.
b. It does receive any argument and return character value.
c. It does not return a value.
d. All of the above
3. A function parameter is
a. a variable in the function that receives a value from the calling program.
b. a way that functions resist accepting the calling program’s values.
c. a value sent to the function by the calling program.
d. a value returned by the function to the calling program.
4. When an argument is passed by reference '&'
a.
b.
c.
d.
the function cannot access the argument’s value.
a temporary variable is created in the calling program to hold the argument’s value.
the function accesses the argument’s original value in the calling program.
variable is created in the function to hold the argument’s value.
5. Overloaded functions
a. are a group of same function with the different type and number arguments.
b. all have the same number and types of arguments.
c. make life simpler for programmers.
d. are a group of same function with the same type and number arguments
6. A local variables exist for
a.
b.
c.
d.
7.
the life of a program but are visible only in their own functions.
the life of a program but are visible only in their overloaded functions.
only while the function in which they are defined is executing.
the life of a program.
A constructor function can specify the return type:
a. int.
b. string.
c. void.
d. cannot specify a return type.
2
8.
Let int x = y= z=0;
y = z++;
x = ++z;
cout << x << y << z;
a. 2 0 2
b. 2 2 2
c. 0 2 0
d. 0 1 2
9.
Let int x = 3 , y=5;
cout << ( x < y ? x : y );
a.
b.
c.
d.
3
5
5:3
3:5
10. How many times will the following loop print hello?
i = 1;
while ( ++i < = 10 )
cout << "hello";
a. 0
b. 9
c. 10
d. An infinite number of times.
3
Question(2) : ---------------------------------------------------------------------------------- [ 5 Marks]
A) Write a function Time_in_Sec( ) that can return the total number of seconds represented by
structure time( hour, minute , second) as argument variable?
Totalsecs = hour*3600 + minute*60 + second.
Answer:
B) Write a function SortXY( ) that can receive two integer variable and return the first argument is
lowest and second is the largest?
Answer:
4
Question(3) : Write the outputs of executing this program
[ 5 Marks]
#include <iostream>
using namespace std;
float Getavg(float);
int main()
{
float data=1, avg;
while( data != 0 )
{
cout << “Enter a number: “;
cin >> data;
avg = Getavg(data);
cout << “New average is “ << avg << endl;
}
return 0;
}
//-------------------------------------------------------------float Getavg(float newdata)
{
static float total = 0;
static int count = 0;
count++;
total += newdata;
return total / count;
}
The outputs are:
5
Download