ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for...

35
ة السعوديةكة العربيممل التعليم وزارة البدالعزيزير سطام بن عممعة ا جاعلــوم بـواديداب وال كليـــة ا الدواســـرKingdom of Saudi Arabia Ministry of Education Prince Sattam Bin Abdulaziz University College of Arts and Sciences, Wadi Addawasir ف غجابة ورقة اAnswer Paper Cover القسم|Department Computer Science اليومDay | Monday لتاريخ اDate | 81 - 40 - 8041 ختبار | فترة اExam Period صباحي مسائيختبار | زمن اExam Duration 2 Hours ف| فيهم الغق بماوراد ا عدNumber of Papers including cover 6 + 15 رذ المقر أستاTeacher| ح المصح د./Mujtaba Gulam Muqeeth التوقيعSignature | اسم عضويق لجنة التدقMember of review committee د./................................................ Dr. التوقيعSignature | الدراسيفصلر الختبا ا81 / 40 / 8041 لجامعيم العا ل1438/1437 Final Exam : Computer Programming - II First Semester | 1437 / 1438 معلومات خاصة ب الطالبStudent Information / لطالب/ـة اسم اStudent Name | لجامعي الرقم اID | رسمى المقر مCourse Title | Computer Programming – II ر ورمزه المقر رقمCourse Code| CS 104 رقم الشعبةSection Number | 0011 لدرجات توزيع اسؤال الQuestion العظمىFu llmark درجةلطالب اStudent Mark 8 ول ا2 لثاني ا4 الث الث0 الرابع5 لخامس ا6 ادس الس7 لسابع ا1 لثامن ا9 لتاسع ا84 لعاشر ا- سئلةت اموع درجا مجQuestions total - عمالت اموع درجا مجفصلية الCourse work - كلي/مائة درجة المجموع الTotal final mark 011 ختبارت ا بعض تعليمالطالبزي ا عزي، لطالبة /زتي ا عزيتي:لعناية با يجدر بك اار بشكل نظاميختب على أدائك ا حرصا فقط.زرققلم اابة تكون بال الكت راتختبام ال بنظاخ أو الشروع فيه أو ا الغش، يعرضكب.ئحة تأديب الط ه فيوص عليجزاء المنصل ل ع نهائي يمنختبار ومن يضبطعة ال في قاتف الجوالهار ا ا إحضا له محضر محاولةرقته ويحرف تسحب ورجوال سوتف ال ها معه غش . لخاصة حيثر أدواته ا طالب/ة إحضاى كل عل إتبادل يسمح ب نهطلبة.دوات بين ال ا يمنع الخروجعة من بدايةختبار قبل مضي نصف سا من ا نصف ساعة دخولخر أكثر منلب المتألطا يحق لختبار، و اختبار. الي كتابة: المجموع الك............................................................................................................................. ....................................................... Total final mark in letters: الختم

Transcript of ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for...

Page 1: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

المملكة العربية السعودية

وزارة التعليم

جامعة األمير سطام بن عبدالعزيز

كليـــة اآلداب والعلــوم بـوادي

الدواســـر

Kingdom of Saudi Arabia

Ministry of Education

Prince Sattam Bin Abdulaziz

University

College of Arts and Sciences,

Wadi Addawasir

ورقة اإلجابةغالف

Answer Paper Cover

Department Computer Scienceالقسم|

Day | Mondayاليوم

Date | 81-40-8041التاريخ

مسائي√صباحي Exam Period فترة االختبار | زمن االختبار |

Exam Duration 2 Hours

عدد األوراق بما فيهم الغالف|

Number of Papers including

cover

6 + 15

|Teacherأستاذ المقرر

المصحح Mujtaba Gulam د./

Muqeeth

................................................Dr.

| Signatureالتوقيع

لجنة التدقيقاسم عضو

Member of review

committee

د./

................................................Dr.

| Signatureالتوقيع

1438/1437للعام الجامعي 81/40/8041اختبار الفصل الدراسي

Final Exam : Computer Programming - II First Semester | 1437 / 1438

/ Student Information الطالبخاصة بمعلومات

Studentاسم الطالب/ـة

Name | | ID الرقم الجامعي

Courseمسمى المقرر

Title |

Computer Programming – II رقم المقرر ورمزهCourse

Code|

CS 104

Sectionرقم الشعبة

Number | 0011

توزيع الدرجات السؤال

Question Fuالعظمى

llmark الطالبدرجة

Student Mark

األول 8

الثاني 2

الثالث 4

الرابع 0

الخامس 5

السادس 6

السابع 7

الثامن 1

التاسع 9

العاشر 84

- مجموع درجات األسئلة

Questions total

- مجموع درجات األعمال

الفصلية

Course work

- المجموع الكلي/مائة درجة

Total final mark 011

بعض تعليمات االختبار

عزيزتي الطالبة / ،عزيزي الطالب

حرصا على أدائك االختبار بشكل نظامي يجدر بك العناية باآلتي:

.الكتابة تكون بالقلم األزرق فقط

يعرضك ،الغش أو الشروع فيه أو اإلخالل بنظام االختبارات

للجزاء المنصوص عليه في الئحة تأديب الطالب.

ا إحضار الهاتف الجوال في قاعة االختبار ومن يضبط يمنع نهائي

معه هاتف الجوال سوف تسحب ورقته ويحرر له محضر محاولة

غش .

نه ال يسمح بتبادل إعلى كل طالب/ة إحضار أدواته الخاصة حيث

األدوات بين الطلبة.

من االختبار قبل مضي نصف ساعة من بداية يمنع الخروج

االختبار، وال يحق للطالب المتأخر أكثر من نصف ساعة دخول

االختبار.

Total final....................................................................................................................................................................................المجموع الكلي كتابة:

mark in letters:

الختم

Page 2: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

1 | P a g e

Part A: (Knowledge Base Questions) [10*1.5=15M]

1. List few Operators available in C++ programming language?

2. Declare variable integer, float, char, and string and assign values in these data types?

3. Name few OOPS principles or concepts?

4. Outline C++ execution steps?

5. Write the C++ program to read and print the data using arrays?

6. State the following statements true or false

a. If no function used in program then default function is main ( ) [ True/False]

b. cout and cin functions are supported by #include<conio.h> [ True/False]

c. Templates used in C programming language [True/False]

7. Discriminate between function overloading and function overriding?

8. Label the below instructions for the given below program?

class student

{

int no;

public:

void getdata()

void printdata()

}; int main( )

{ student s1

s1.getdata ( );

s2.printdata( );

getch(); return 0;}

ز بن عبد العزي األمير سطام جامعة كلية اآلداب والعلـوم بوادي الدواسر

قســـم علوم الحاسب

النهائياالختبار للعام الجامعي االولللفصل الدراسي 1438/1437

CS 104 Computer Programming II :شعبةالزمن: ساعتان 0011

:المستوى 3

درجة 01الدرجة العظمي:

هـ 1003/ 10/ 01التاريخ:

Page 3: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

2 | P a g e

9. Choose the correct answer for given below questions

i. Which constructors will be used to define the values of only one object data

members [ ]

a. Simple Constructors

b. Copy constructors

c. Default constructors

d. Parameterized constructors

ii. Which principle of O.O.P can be used to allocate the memory at program

Runtime [ ]

a. Static polymorphism

b. Dynamic polymorphism

c. Inheritance

d. Streams

iii. Which Method of O.O.P the object of base class can override the member

Functions of derived class [ ]

a. Virtual functions

b. Dynamic polymorphism

c. Parameterized constructors

d. None of the above

10. List types of exception handling in C++ language?

PART B: Interpersonal Skills & Responsibility [3*3=9M]

11. Modify the below program in C++ programming language using classes and objects

#include<stdio.h>

int main(){

int num,r,reverse=0;

Page 4: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

3 | P a g e

printf("Enter any number: ");

scanf("%d",&num);

while(num){

r=num%10;

reverse=reverse*10+r;

num=num/10;

}

printf("Reversed of number: %d",reverse);

return 0;

}

12. Justify (Name) the given below Fig 1.1(a) and Fig 1.1(b) which type of Inheritances?

A B C

D

Fig. 1.1(a)

A

Fig. 1.1(b) B C D

Page 5: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

4 | P a g e

13. Write the C++ program for given below Fig.1.2 virtual functions?

Fig.1.2

PART C: Cognitive skills [2*4.5=9M]

14. Design the C++ program for the given below Fig.1.3

Fig.1.3

class A

Int a;

void display( )

class B

Int a;

void display( )

class A

Int a;

float b;

void function1( )

void function1(int, int);

void function1(int,int,float)

S1

S2

S1

Page 6: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

5 | P a g e

15. Write the C++ program for the given below fig.1.4

A B

C

D E Fig.1.4

PART D: Communication, Information Technology & programming skills [2*3.5=7M]

16. Demonstrate the use of templates with an example program?

17. Assess the errors for the following given below program and re write correct one

#include <iostream>

#include <fstream.h>

#include<conio.h>

using namespace standard;

void main()

{ float num1 = 11;

char num2 = 22;

string num3 = 33;

ofstream outFi;

outFile.open("data.txt");

if (outFile.pass())

S1

Page 7: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

6 | P a g e

{

cin << "Error opening \"data.txt.\" for output.\n";

return 1;

}

outFile << num1 << endl << num2 << endl << num3 << endl;

cout << num1 << endl << num2 << endl << num3 << "\n\n";

cout << "The data has been written to the file.\n\n";

outFile.close(); }

------Wish U Best of Luck------

Course Instructor Supervisor of Department Lecturer: Mujthaba Gulam Muqeeth Dr. Abdalla Al Ameen Signature: ……………. Signature: …………….

Page 8: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 9: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 10: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 11: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 12: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 13: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 14: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 15: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 16: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 17: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 18: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 19: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 20: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 21: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 22: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

START FROM HERE

QUESTION NO. PART

MARKS Page 2 Total

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

Page 23: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

1 | P a g e

Part A: (Knowledge Base Questions) [10*1.5=15M]

1. List few Operators available in C++ programming language?

Answer: Operators available in C++ Programming Language

• Arithmetic operators ( +, -, *, /, % )

• Assignment (=)

• Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)

• Increase and decrease (++, --)

• Relational and equality operators (==,! =, >, <, >=, <= )

• Logical operators ( !, &&, || )

• Conditional operator ( ? )

• Bitwise Operators ( &, |, ^, ~, <<, >> )

• Standard input and Output (cout,cin)

2. Declare variable integer, float, char, and string and assign values in these data types?

Answer: int a=10; float b=10.5; char a=’A’; char a[20]=”Hello”;

3. Name few OOPS principles or concepts?

Answer: O.O.P. Principles

o Classes and Object (Abstarct)

o Constructors & Destructors

o Inheritances

o Polymorphism

o Message passing

o Templates

o Virtual Functions and so on.

4. Outline C++ execution steps?

Answer: C++ Execution steps

• Open the editor

ز بن عبد العزي األمير سطام جامعة كلية اآلداب والعلـوم بوادي الدواسر

قســـم علوم الحاسب

النهائياالختبار للفصل الدراسي االول للعام الجامعي 1438/1437

CS 104 Computer Programming II :شعبةالزمن: ساعتان 1100

:المستوى 3

درجة 04الدرجة العظمي:

هـ 1803/ 40/ 81التاريخ: Main Key Paper

Page 24: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

2 | P a g e

• Execute the program

• Save with .cpp extension

• Compile the program for errors

• Filename. Class will be created (if no errors)

• Run the .class file

5. Write the C++ program to read and print the data using arrays?

Answer:

//Program using arrays

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

int i,a[10];

cout<<"Enter the value of n";

cin>>n;

cout<<endl<<"Enter the values";

for(i=0;i<n;i++)

{

cin>>a[i];

}

cout<<endl<<"The elements are ";

for(i=0;i<n;i++)

{

cout<<endl<<a[i];

}

getch();

return 0;

}

Page 25: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

3 | P a g e

6. State the following statements true or false

a. If no function used in program then default function is main ( ) [ True]

b. cout and cin functions are supported by #include<conio.h> [False]

c. Templates used in C programming language [False]

7. Discriminate between function overloading and function overriding?

Answer: Function overloading is an example of static polymorphism. In this same function

name is used for different functions but parameters are different. Function overriding is an

example of dynamic polymorphism. In this same function name is used for different

functions even the parameters are also same.

8. Label the below instructions for the given below program?

class student // Class name student

{

int no; // Data members

public: // Access specifiers

void getdata() // Member functions

void printdata() //Member functions

}; int main( ) // Main program

{ student s1 // s1 object created for class student

s1.getdata ( ); //s1 invoke with member functions getdata()

s2.printdata( ); //s1 invoke with member functions printdata()

getch(); return 0;}

9. Choose the correct given below questions

i. Which constructors will be used to define the values of only one object data

members [ a ]

a. Simple Constructors

b. Copy constructors

c. Default constructors

d. Parameterized constructors

ii. Which principle of O.O.P can be used to allocate the memory at program

Page 26: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

4 | P a g e

Runtime [ a ]

a. Static polymorphism

b. Dynamic polymorphism

c. Inheritance

d. Streams

iii. Which Method of O.O.P the object of base class can override the member

Functions of derived class [ a ]

a. Virtual functions

b. Dynamic polymorphism

c. Parameterized constructors

d. None of the above

10. List types of exception handling in C++ language?

Answer: Arithmetic exceptions, array index bound of exceptions and so on.

PART B: Interpersonal Skills & Responsibility [3*3=9M]

11. Modify the below program in C++ programming language using classes and objects

#include<stdio.h>

int main(){

int num,r,reverse=0;

printf("Enter any number: ");

scanf("%d",&num);

while(num){

r=num%10;

reverse=reverse*10+r;

num=num/10;

}

printf("Reversed of number: %d",reverse); return 0; }

Page 27: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

5 | P a g e

C++Program

#include<iosteam>

#include<conio.h>

using namespace std;

class rev

{

int num,r,reverse=0;

public:

void getdata();

void printdata(void);

};

void rev::getdata()

{

cout<<endl<<"Enter the

number";

cin>>num;

while(num){

r=num%10;

reverse=reverse*10+r;

num=num/10;

}

}

void rev::printdata()

{

cout<<endl<<"reverse

number="<<reverse;

}

int main(){

rev s1;

s1.getdata();

s1.printdata(); getch();

return 0;

}

12. Justify (Name) the given below Fig 1.1(a) and Fig 1.1(b) which type of Inheritances?

A B C

D Multiple Inheritance

Fig. 1.1(a)

Page 28: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

6 | P a g e

A

Fig. 1.1(b) B C D Hierarchical Inheritances

13. Write the C++ program for given below Fig.1.2 virtual functions?

Fig.1.2

#include<iostream>

#include<conio.h>

using namespace std;

class A

{

public:

void display()

{

cout<<"Base class function";

}

};

class B:public A

{

public:

int display()

{

class A

Int a;

void display( )

class B

Int a;

void display( )

S1

S2

Page 29: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

7 | P a g e

cout<<endl<<"Derived class function";

}

};

int main()

{

A * s1;

B s2;

s1.display();

s1=&s2;

s1.display();

getch();

return 0;

}

PART C: Cognitive skills [2*4.5=9M]

14. Design the C++ program for the given below Fig.1.3

Fig.1.3

Answer: Function Overloading: This concept is an example of static polymorphism. Here same

function name is used for different functions but different parameters are different.

#include<iostream>

#include<conio.h>

using namespace std;

//Program on fucntion overloading

class A

{

int a;

float c;

public:

void function1(void);

void function1(int,int);

void function1(int,int,float);

};

void A::function1(void)

class A

Int a,b;

float f;

void display( )

void display(int, int);

void display(int,int,float)

S1

Page 30: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

8 | P a g e

{

cout<<endl<<"No parameters";

}

void A::function1(int x,int y)

{

a=x;

b=y;

cout<<endl<<"a="<<a;

cout<<endl<<"b="<<b;

}

void A::function1(int x,int y, float z)

{

a=x;

b=y;

f=z;

cout<<endl<<"a="<<a;

cout<<endl<<"b="<<b;

cout<<endl<<"f="<<f;

}

//main program

int main() Output:

{

A s1; No parameters

s1.function1(); a=10

s1.function1(10,20); b=20

s1.function1(10,20,20.5); a=10

getch(); b=20

return 0; c=20.5

}

15. Write the C++ program for the given below fig.1.4

Page 31: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

9 | P a g e

A B

C

D E Fig.1.4

Program

//Program on Hybrid inheritance

#include<iostream>

#include<conio.h>

using namespace std;

class A

{

public:

int a;

public:

void getdata1(void)

{

cout<<endl<<"Enter the value of a";

cin>>a;

}

void printdata1(void)

{

cout<<endl<<"The value of A="<<a;

}

};

//Class B

class B

{

public:

int b;

public:

void getdata2(void)

{

cout<<endl<<"Enter the value of b";

cin>>b;

}

void printdata2(void)

S1

Page 32: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

10 | P a g e

{

cout<<endl<<"The value of B="<<b;

}

};

//Class C

class C:public A,B

{

public:

int c;

public:

void getdata3(void)

{

cout<<endl<<"Enter the value of c";

cin>>c;

}

void printdata3(void)

{

cout<<endl<<a<<endl<<b<<"The value of C="<<c;

}

};

class D:public c

{

public:

int d;

public:

void getdata4(void)

{

cout<<endl<<"Enter the value of d";

cin>>d;

}

void printdata4(void)

{

cout<<endl<<a<<endl<<b<<endl<<c<<"The value of D="<<d;

}

};

class E:public c

{

public:

int e;

public:

void getdata5(void)

{

cout<<endl<<"Enter the value of d";

cin>>d;

}

void printdata5(void)

{

Page 33: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

11 | P a g e

cout<<endl<<a<<endl<<b<<endl<<c<<"The value of E="<<e;

}

};

int main()

{

C s1;

D s2;

E s3;

s1.getdata1();

s1.printdata1();

s1.getdata2();

s1.printdata2();

s1.getdata3();

s1.printdata3();

getch();

return 0;

}

PART D: Communication, Information Technology & programming skills [2*3.5=7M]

16. Demonstrate the use of templates with an example program?

Answer:

//Program on templates

#include<iostream>

#include<conio.h>

using namespace std;

template <class T>

T sum(T n1,T n2)

{

T n3;

n3=n1+n2;

cout<<endl<<"A="<<n1<<"B="<<n2<<"Sum ="<<n3;

}

int main()

{

int a,b;

cout<<endl<<"Enter the value of A,B";;

cin>>a>>b;

Page 34: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

12 | P a g e

sum(a,b);

float c,d;

cout<<endl<<"Enter the value of C,D";;

cin>>c>>d;

sum(c,d);

getch();

return 0;

}

17. Assess the errors for the following given below program and re write correct one

#include <iostream>

#include <fstream.h>

#include<conio.h>

using namespace std;

int main()

{ int num1 = 11;

int num2 = 22;

int num3 = 33;

ofstream outFile;

outFile.open("data.txt");

if (outFile.fail())

{

cout << "Error opening \"data.txt.\" for output.\n";

return ;

}

outFile << num1 << endl << num2 << endl << num3 << endl;

cout << num1 << endl << num2 << endl << num3 << "\n\n";

Page 35: ةيدوعسلا ةيبرعلا ةكلمملا · 2 | P a g e 9. Choose the correct answer for given below questions i. Which constructors will be used to define the values of only

13 | P a g e

cout << "The data has been written to the file.\n\n";

outFile.close(); }

Course Instructor Supervisor of Department Lecturer: Mujthaba Gulam Muqeeth Dr. Abdalla Al Ameen Signature: ……………. Signature: …………….