Examination for the Second Term - Academic Year H Mid-Term. Name of student: ID: Sr. No.

Similar documents
Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

In this chapter you will learn:

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

C++ PROGRAMMING SKILLS Part 2 Programming Structures

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

Number: Name-Surname :... Group:...

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

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

REPETITION CONTROL STRUCTURE LOGO

CSCE Practice Midterm. Data Types

A SHORT COURSE ON C++

Computer Programming : C++

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

A Freshman C++ Programming Course

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

Chapter 2 - Control Structures

Object Oriented Pragramming (22316)

CSCE Practice Midterm. Data Types

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Basic Source Character Set for C++ Language:

6.096 Introduction to C++ January (IAP) 2009

Introduction to Programming

C++ Programming: From Problem Analysis to Program Design, Third Edition

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Al-Albayt University Computer Science Department. C++ Programming 1 (901131) Coordinator: Dr. Ashraf Al-Ou n

Arrays. Week 4. Assylbek Jumagaliyev

Functions. Introduction :

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Chapter 2 - Control Structures

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

Downloaded from

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

DELHI PUBLIC SCHOOL TAPI

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Fundamentals of Structured Programming

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Scientific Computing

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

A First Program - Greeting.cpp

UNIT- 3 Introduction to C++

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

BRAIN INTERNATIONAL SCHOOL. Term-I Class XI Sub: Computer Science Revision Worksheet

Introduction to Computer Science Midterm 3 Fall, Points

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Introduction to Algorithms and Programming (COMP151)

1 Unit 8 'for' Loops

Chapter 1. Principles of Object Oriented Programming

CSci 1113 Midterm 1. Name: Student ID:

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Sample Paper - II Subject Computer Science

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

[Page 177 (continued)] a. if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65 << endl";

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Fundamentals of Programming Session 7

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

To become familiar with array manipulation, searching, and sorting.

Lab # 02. Basic Elements of C++ _ Part1

Chapter 2: Basic Elements of C++

CPT101- Principles of Programming

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

CHAPTER 9 FLOW OF CONTROL

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

KENDRIYA VIDYALAYA SANGATHAN, GUWAHATI REGION HALF-YEARLY EXAMINATION-2015 CLASS XI : COMPUTER SCIENCE Time Allotted : 3 hrs. Max.

Name SECTION: 12:45 2:20. True or False (12 Points)

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

CHAPTER : 9 FLOW OF CONTROL

CS242 COMPUTER PROGRAMMING

Sample Paper Class XI Subject Computer Sience UNIT TEST II

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

IS 0020 Program Design and Software Tools

ASSIGNMENT CLASS-11 COMPUTER SCIENCE [C++]

Chapter 2 Basic Elements of C++

The Hyderabad Public School, Begumpet, Hyderabad, A.P

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Chapter 2: Introduction to C++

Chapter 2 - Control Structures

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Computer Science II Lecture 1 Introduction and Background

Introduction to Programming

Transcription:

Kingdom of Saudi Arabia Ministry of Higher Education Course Code: ` 011-COMP Course Name: Programming language-1 Deanship of Preparatory Year Jazan University Total Marks: 20 Duration: 60 min Group: Examination for the Second Term - Academic Year 1434 1435 H Mid-Term Name of student: ID: Sr. No. Q.1 Select the correct option of your choice from the followings: (5*1=5 Marks) i. Which of the following is used to give tab space between two words. (a) \t (b) \ (c) /t (d) None of the above ii. iii. Output Statement uses the operator with cout (a) > (b) >> (c)<< (d) @ Statement in c++ should end with. (a) ; (b) : (c), (d). iv. Single-line comment uses: (a) \\ (b) // (c ) /* (d) *\ v. conditional operator is ternary operator it takes three operands. (a)? : (b) >> (c ) /* (d) # Deanship of preparatory year SET-A Page 1 of 4

Q.2 Define the following terms. (2*2=4 Marks) (i) Block in C++ language....... (ii) High Level Language.. Q.3 Find out errors in the below given program? (2*3=6 Marks) (i) #include<iostream #include<conio.h> using namespace std; void main(); int n,sqr,cub cout<<"enter the number : "; cin>>n; sqr=n*n; cub=n*n*n; cout<<"\nsquare="<<sqr; cout>>"\ncube="<<cub; getch(); Deanship of preparatory year SET-A Page 2 of 4

Answer: (ii) #include<iostream> include<conio.h> using namespace std; void main() int i: for(i=1; i<=10, i++) cout<<i<<endl; getch(); Answer: Deanship of preparatory year SET-A Page 3 of 4

Q.4 Write a Program to find the greatest of three numbers. (5*1=5 Marks) ***** Good Luck ***** Deanship of preparatory year SET-A Page 4 of 4

Kingdom of Saudi Arabia Ministry of Higher Education Jazan University Faculty of Computer & Information Systems Computer Science Department Exam Date: / / 1435 Course Code: Comp 011 Midterm exam - Academic Year 1434 1435 H Name: Id: Group: - Q-1> Multiple Choice Questions: (5 Marks) a) Which of the following is conditional operator? (a)?: (b) = = (c) & (d) > = b) Which of the following is a pictorial representation of an algorithm? (a) Gnat Chart (b) Pareto Chart (c) Flowchart (d) None c) Which of the following statement add 1 to the variable X? (a) X++ (b) X=X+1 (c) X+=1 (d) All d) Which of the following is not a repetition statement? (a) While (b) For (c) Do-While (d) IF Deanship of preparatory year SET-A Page 5 of 4

e) Which of the following is not a Control Structure? (a) Sequence (b) Selection (c) Repetition (d) Counter Q-2> Fill in the blanks: (3 Marks) a) Every C++ program must have a function called. b) Object is used to print the output on the screen. c) repetition is called indefinite repetition. Q-3> Write the output of the following program. (2 Marks) #include<iostream.h> Using namespace std; void main() Deanship of preparatory year SET-A Page 6 of 4

int k; for (k=1; k<=5; k++) cout<< 5*k<<endl ; Ans: _ Q-4> Rewrite the errors in the following program. (2 Marks) #include<<iostream.h>> void main( ) int a, b, sum: cout<< Enter value of a : >>; cin>>a; sum = =a + b; Deanship of preparatory year SET-A Page 7 of 4

cout<< Value of a and b : sum; return 0; Ans: _ Q-5> Subjec ve Ques ons (Defini ons) (4 Marks) a) What is Selection Structure? Ans: _ Deanship of preparatory year SET-A Page 8 of 4

b) What is a Counter-Controlled repetition? Ans: _ Deanship of preparatory year SET-A Page 9 of 4

Q-6> Write Programs (4 Marks) a) Write a C++ program to print the number from 1 to 10 using Do-While loop. Ans: _ Deanship of preparatory year SET-A Page 10 of 4

b) Write a C++ program to calculate student grades. Ans: _ Deanship of preparatory year SET-A Page 11 of 4

Deanship of preparatory year SET-A Page 12 of 4

KINGDOM OF SAUDI ARABIA MINISTRY OF HIGHER EDUCATION JAZAN UNIVERSITY, JAZAN Collage of Computer and Information Systems نظم المعلومات المملكة العربية السعودية وزارة التعليم العالى جامعة جازان كلية الحاسب اآللى و Student Name : Student ID : Group : Level : Preparatory Year Subject : Programming in C++ Code : Comp - 011 Exam Day : Exam date : - - 1435H Exam Duration: 2 Hours Fall Term Spring Term Academic Year : MARKS DISTRIBUTION SECTION - A SECTION - B SECTION - C Total (in words) 1 9 14 2 10 15 3 11 16 4 12 5 13 Student Answer Sheet 1434-1435 H Deanship of preparatory year SET-A Page 13 of 4

6 7 Total (in Numbers) 8 TOTA L A: B: C: CLASS WORK (OUT OF 60) GRAND TOTAL (OUT OF 100) Question Paper approved by :( signature with Date ) Course Coordinato r Track Leader Exam Committee - 1 Exam Committee - 2 QAU Exam Evaluator Note : This question Paper is not Eligible for printing if not signed by any of above signatures Invigilat or Examiner Reviewer Department Coordinator/Head Note: All questions are compulsory. Please use the left side blank sheet for extra work Q.1. Answer the following questions [2*3=6 Marks] i. Define keyword with example. Deanship of preparatory year SET-A Page 14 of 4

- - - - - ii. Define while repetition statement. - - - - - Q.2 Multiple Choice Questions: [10*1=10 Marks] i. How many times the statements for ( ; ; ) will execute? (a) 10 (b) 1 (c) 0 (d) infinite times Deanship of preparatory year SET-A Page 15 of 4

ii. iii. iv. The Preprocessor directives begin with. (a) @ (b) # (c) * (d) $ Every statement in C++ should end with. (a) ; (b): (c) (d) >> is English like representation of the code. (a) Flowchart (b) Algorithm (c) Program (d) Pseudo code v. C++ is an example of languages. (a) Assembly languages (b) Machine languages (c) High level languages the above (d) All of 1 Programming in C++ 1434-1435 H vi. is a conditional operator. (a) = = (b)? : (c) >> (d) + = vii. The expression count + = count is equivalent to. (a) count++ b) count + (c) count - - (d) None of these viii. A set of statement contains within a pair of braces it called (a) command (b) comment (c) block (d) flowchart ix. Do While loop is considered as repeat ion (a) Counter-controlled (b) not Counter-controlled (c) output function (d) input function x. The function that print output for the user is. (a) cin>> (b) cin<< (c) cout<< (d) cout>> Deanship of preparatory year SET-A Page 16 of 4

Q.3. Write the following Programs: [2*5=10 Marks] i. Write a program using if else statement to find out the result of a student based on the following conditions: - If the grade is greater than 75 then Display Distinction - If the grade is greater than 60 and less than 75 then Display Pass - If the grade is less than 60 then Display Fail - - - - - - - - - - Deanship of preparatory year SET-A Page 17 of 4

2 Programming in C++ 1434-1435 H - - - - - - ii. Write a program using switch statement to Display the name of a day of the week when a user enters a number between 1 and 7, otherwise display incorrect entry. - - - - Deanship of preparatory year SET-A Page 18 of 4

- - - - - - - - - - - - Deanship of preparatory year SET-A Page 19 of 4

- - 3 Programming in C++ 1434-1435 H Q.4. Find out the syntax errors in the following codes and rewrite the correct code: [2*4=8 Marks] i. include <iostrea> using namespace std; void main( ) int x,y cout<< enter two integer ; cin>>x>y; if(x==y cout<<x<< == <<y; return 0; - - - - Deanship of preparatory year SET-A Page 20 of 4

- - - - - - ii. #include <iostream using namespace std; vid min() int c=0; whle(c<= 10 c++; cou<c <<\n ; 4 Programming in C++ 1434-1435 H -- -- Deanship of preparatory year SET-A Page 21 of 4

- - - - - - - - - Q.5. What will be the output of the following code? [2*3=6 Marks] i. #include <iostream> using namespace std; int main() int counter=6; do Deanship of preparatory year SET-A Page 22 of 4

cout<<counter<< ; counter++; while (counter<=5); - - - - - -- 5 Programming in C++ 1434-1435 H -- - - ii. #include <iostream> using namespace std; void main( ) Deanship of preparatory year SET-A Page 23 of 4

for (int x=10; x>=2; x-=2) cout<<x<<"\n "; - - - - - - - - - - Deanship of preparatory year SET-A Page 24 of 4

I. Multiple Choice Questions 1. Which of the following is a condition that will test whether the value in the integer variable num is even or not? (a) (num % 2 ==0) (b) (num / 2 ==0) 6 Programming in C++ 1434-1435 H (c) (Num % 2 == 1) (d) None of the above. Ans: A 2. Which of the following is a control structure? (a) Sequence structure. (b) Repetition structure. (c) Decision structure. (d) All of the above. Ans: D 3. How many times will the following while loop print "Hello"? int i=1; while(i<=13) cout<<"hello"; (a) 10 (b) 8 (c) 0 (d) An infinite number of times Ans: D 4. What will be the first and last values of i after execution of following loop? n=20; for(i=0;i<n;i++) cout<<i<<endl; (a) 0 and 19 (b) 1 and 19 (c) 0 and 20 (d) 1 and 20 Ans: B 5. What will be the output of the following code? #include<iostream.h> void main() int x=0; if(x>=0) x=x+5; if(x>=5) x=x+4; (a) 7 (b) 5 (c) 9 (d) None of the above Ans: A Deanship of preparatory year SET-A Page 25 of 4

6. To set the value of a variable before any processing occurs, you the variable. (a) construct (b) iterate (c) initialize (d) increase Ans: C 7. In sort, the smallest item from the unsorted list is swapped with the item at the beginning of the unsorted list. (a) selection (b) bubble (c) insertion (d) all of the above Ans: A 8. Norwegian, Farsi and Russian can be classified as language. (a) machine (b) symbolic (c) high level (d) natural Ans: D 9. is a program designed to teach programming to novices that emphasizes the structured programming approach. (a) C++ (b) C (c) Pascal (d) Scheme Ans: C 10. A language uses the traditional approach to programming and is also referred to as an imperative language. (a) procedural (b) functional (c) declarative (d) object oriented Ans: A 11. is an English like representation of the code. (a) Flowchart (b) Algorithm (c) Program (d) Pseudocode Ans: D 12. The standard data type describes a number without a fractional part. (a) float (b) double (c) int (d) char Ans: C 13. C, C++ and Java can be classified as languages. (a) symbolic (b) machine (c) natural (d) high level Ans: D 14. is a basic algorithm that adds a list of numbers. (a) smallest (b) summation (c) product (d) largest Ans: C 15. The constructs handles repeated actions. (a) sequence (b) decision (c) declarative (d) repetition Ans: D 16. For insertion sort, n 1 passes are needed to sort the data. (a) selection (b) bubble Deanship of preparatory year SET-A Page 26 of 4

(c) insertion (d) all of the above Ans: D 17. Iteration is a process in which as algorithm calls itself. (a) insertion (b) recursion (c) iteration (d) searching Ans: B 18. HTML, PERL and SQL fall under the classification of modern language. (a) special (b) object oriented (c) declarative (d) modern Ans: A 19. In C++, is the hiding of data and operations from the user. (a) encapsulation (b) inheritance (c) modularity (d) polymorphism Ans: A 20. LISP is a(n) functional language. (a) object oriented (b) procedural (c) declarative (d) functional Ans: D 21. The only language understood by computer hardware is a language. (a) symbolic (b) machine (c) high level (d) nautral Ans: B 22. languages are also known as assembly languages. (a) symbolic (b) machine (c) high level (d) nautral Ans: A 23. The software used to write a program is called a. (a) source file (b) preprocessor (c) translator (d) text editor Ans: D 24. A popular object oriented language is. (a) LISP (b) C++ (c) COBOL (d) FORTRAN Ans: B 25. A standard data type in the C++ language is. (a) char (b) int (c) float (d) all of the above Ans: D II. Write C++ statements to accomplish each of the following tasks 1. Assign the value 250 to the double variable sum. Ans: double sum=250; Deanship of preparatory year SET-A Page 27 of 4

2. Display the value of integer variable sum on the screen. Ans: cout<<sum; 3. Declare a constant named PIE with the value 15. Ans: const float pie=15; 4. Display the values between 1 and 10 on the screen. Ans: for(i=1;i<=10;i++) cout<<i; 5. The function reads a single character from the user. Ans: getch() 6. Write the equivalent increment statement of count = count + 1 Ans: count++; 7. Write the escape sequence for carriage return. Ans: \r 8. Write the equivalent assignment operator of x = x + 5 Ans: x+=5; 9. Write the syntax of for loop. Ans: for(assignment statement;test expression;increment operator) 10. Write a statement using AND logical operator. Ans: if(age>30&&age<65) 11. Write a statement using OR logical operator. Ans: if(basic>2500 salary<5000); 12. Write a statement using NOT logical operator. Ans: if(!(grade>50)) 13. Write a statement to test equality. Ans: if(y%2==0) 14. Write the syntax of do while loop. Ans: dostatement while(expression) 15. Write a statement to initialize array. Ans: int mm[5]=4,55,3,65,9; III. Define Deanship of preparatory year SET-A Page 28 of 4

1. What is high level language. Ans: High-level languages is a language that allow programmers to write instructions that look almost like everyday English and contain commonly used mathematical notations 2. What is compiler. Ans: A compiler is a Translator program that convert high-level language programs into machine language. 3. Define the term algorithm. Ans: A procedure for solving a problem in terms of 1. The action to execute 2. The order in which the actions execute is called an algorithm. 4. Define for loop, with example? Ans: For repetition statement specifies the details (initialization, loop test condition, increment or decrement) in a single line of code. Example: for (int i=1; i<=10; i++) cout<< i<<endl ; 5. Define the term Keyword. Ans: A keyword is a word in a code that is reserve by C++ for a specific use. Example: int, char, if, else, switch, while etc. 6. What is Block in c++ language. Ans: A set of statement contain within a pair of braces ( and ) is called a compound statement or Block 7. What is unary operator, explain with example. Ans: A unary operator is an operator that applies only a single variable. Example: ++a (Preincrement), (postincrement) a++, etc 8. Define the break statement with example. Ans: A break statement is used to terminate a control statement's execution Example: switch(day) case 1: cout<< Saturday ; break; 9. What is logical AND and logical OR. Ans: Logical AND(&&) operator is used when we wish to ensure that two conditions are both true before we choose a certain path of execution. Deanship of preparatory year SET-A Page 29 of 4

Logical OR ( ) operator is used when we wish to ensure at some point in a program that either or both of two conditions are true before we choose a certain path of execution. 10. What is Function in C++, Give an example. Ans: Functions allow the programmer to modularize a program by separating its tasks into self-contained units. Example: int square() cout<< square of integer << a; return a*a; Deanship of preparatory year SET-A Page 30 of 4

IV. Find out the syntax errors in the following codes and rewrite the correct code: Q.1 include<iostream> void main() cout<< my name is ; Ans: # include<iostream> void main() cout<< my name is ; Q. 2: #include<iostrea> void main() int x,y cout<< enter two integer ; cin>>x>y; if(x==y) cout<<x<< == <<y; Ans: #include<iostream> void main() int x,y ; cout<< enter two integer ; cin>>x>>y; if(x==y) cout<<x<< == <<y; Q.3: Ans: #include<iostream> void main() Int grade; std:cin>>grade; If grade>=60 cout << passed ; else cout << fail ; #include<iostream> void main() Int grade; Deanship of preparatory year SET-A Page 31 of 4

std: : cin>>grade; If( grade>=60) cout << passed ; else cout << fail ; Q.4: Answer: Q.5: Answer: #include <iostream> using std::cout; using std::endl; void main() int c=0 while(c<= 10) C++; cout<<c <<\n ; #include <iostream> using std::cout; using std::endl; void main() int c=0 ; while(c<= 10) C++; cout<<c << \n ; #include <iostream> using std::cout; using std::endl; int main() For(int i=0,i<=10;i+cout<<i<<endl; #include <iostream> using std::cout; using std::endl; int main() For(int i=0 ; i<=10; i++ ) Deanship of preparatory year SET-A Page 32 of 4

cout<<i<<endl; return 0; V. Rewrite the following programmes: Q.1: Rewrite the following program using for loop and write down the output of the program: Ans: #include <iostream> using std::cout; void main() int a=2; while (a<=6) cout <<a<< " "; a++; Q.2: Rewrite the following program using for loop and write down the output of the program: Ans: #include<iostream> using std::cout; void main() int a=6; while(a<=60) cout<<"the table of the given no. is"<<a<<"\n"; a+=6; Q.3: Rewrite the following program using while loop and write down the output of the program: Ans: #include<iostream> using std::cout; void main() for(int x=1;x<=10;x++) cout<< the series of the no. is <<x<< \n ; Q.4: Rewrite the following program using while loop and write down the output of the program: Ans: #include <iostream> using namespace std; void main() int total, gradecounter, grade, average; Deanship of preparatory year SET-A Page 33 of 4

total = 0; gradecounter = 1; while ( gradecounter <= 10 ) cout << "Enter grade: "; cin >> grade; total = total + grade; gradecounter = gradecounter + 1; average = total / 10; cout << "\ntotal of all 10 grades is " << total << endl; cout << "Class average is " << average << endl; Q.5: Ans: VI. Q.1: Ans: Rewrite the following program using do-while loop and write down the output of the program: #include <iostream> using std::cout; void main() int a=1; int b=2; int c=0; while(c<= 20) c=b*a; a++; cout<<b << x << a << = <<c; cout<< \n ; Write programmes: Write a program using if else statement for the result of the student based on the given condition: a) If the grade is greater than 75 print Distinctions b) If the grade is greater than 60 print Pass c) If the grade is less than 60 print Fail #include<iostream> Deanship of preparatory year SET-A Page 34 of 4

using std::cout; using std::cin; void main() int grade; cout<<"enter the grade"; cin>>grade; if(grade>=75) cout<<"distingtion"; else if(grade>=60) cout<<"pass"; else cout<<"fail"; Q.2: Ans: Q.3: Ans: Write the program to print square of an integer using function. #include<iostream> int square(int y) int p; p=y*y; return p; using std::cout; void main() int i; i=10; cout<<square(i)<<""; Write a program to enter number and print the name of the day using switch statement #include <iostream> using namespace std; void main() int day; cout<<"enter the day : "; cin>>day; switch (day ) case 1: cout<<"saturday"<<endl; break; Deanship of preparatory year SET-A Page 35 of 4

case 2: cout<<"sunday"<<endl; break; case 3: cout<<"monday"<<endl; break; case 4: cout<<"tuesday"<<endl; break; case 5: cout<<"wednesday"<<endl; break; case 6: cout<<"thursday"<<endl; break; case 7: cout<<"friday"<<endl; break; default: cout << "Incorrect entery."<<endl; break; KINGDOM OF SAUDI ARABIA MINISTRY OF HIGHER EDUCATION المملكة العربية السعودية وزارة التعليم العالى Deanship of preparatory year SET-A Page 36 of 4

JAZAN UNIVERSITY, JAZAN Collage of Computer and Information Systems نظم المعلومات جامعة جازان كلية الحاسب اآللى و Student Name : Student ID : Group : Level : Preparatory Year Subject : Programming in C++ Code : Comp - 011 Exam Day : Exam date : - - 1434H Exam Duration: 2 Hours Fall Term Spring Term Academic Year : MARKS DISTRIBUTION SECTION - A SECTION - B SECTION - C Total (in words) 1 9 14 2 10 15 3 11 16 4 12 5 13 6 Student Answer Sheet 1434-1435 H 7 Total (in Numbers) 8 Deanship of preparatory year SET-A Page 37 of 4

TOTA L A: B: C: CLASS WORK (OUT OF 60) GRAND TOTAL (OUT OF 100) Question Paper approved by :( signature with Date ) Course Coordinato r Track Leader Exam Committee - 1 Exam Committee - 2 QAU Exam Evaluator Note : This question Paper is not Eligible for printing if not signed by any of above signatures Invigilat or Examiner Reviewer Department Coordinator/Head Note: All questions are compulsory. Please use the left side blank sheet for extra work Q.1. Answer the following questions [2*3=6 Marks] i. Define keyword with example. - - Deanship of preparatory year SET-A Page 38 of 4

- - - ii. Define while repetition statement. - - - - - Q.2 Multiple Choice Questions: [10*1=10 Marks] i. How many times the statements for ( ; ; ) will execute? (a) 10 (b) 1 (c) 0 (d) infinite times ii. iii. The Preprocessor directives begin with. (a) @ (b) # (c) * (d) $ Every statement in C++ should end with. (a) ; (b): (c) (d) >> Deanship of preparatory year SET-A Page 39 of 4

iv. is English like representation of the code. (a) Flowchart (b) Algorithm (c) Program (d) Pseudo code v. C++ is an example of languages. (a) Assembly languages (b) Machine languages (c) High level languages the above (d) All of 1 Programming in C++ Alternative Exam 1433-1434 H vi. is a conditional operator. (a) = = (b)? : (c) >> (d) + = vii. The expression count + = count is equivalent to. (a) count++ b) count + (c) count - - (d) None of these viii. A set of statement contains within a pair of braces it called (a) command (b) comment (c) block (d) flowchart ix. Do While loop is considered as repeat ion (a) Counter-controlled (b) not Counter-controlled (c) output function (d) input function x. The function that print output for the user is. (a) cin>> (b) cin<< (c) cout<< (d) cout>> Q.3. Write the following Programs: [2*5=10 Marks] i. Write a program using if else statement to find out the result of a student based on the following conditions: - If the grade is greater than 75 then Display Dis nc on - If the grade is greater than 60 and less than 75 then Display Pass Deanship of preparatory year SET-A Page 40 of 4

- If the grade is less than 60 then Display Fail - - - - - - - - - - 2 Programming in C++ Alternative Exam 1433-1434 H - Deanship of preparatory year SET-A Page 41 of 4

- - - - - ii. Write a program using switch statement to Display the name of a day of the week when a user enters a number between 1 and 7, otherwise display incorrect entry. - - - - - - Deanship of preparatory year SET-A Page 42 of 4

- - - - - - - - - - - - 3 Programming in C++ Alternative Exam 1433-1434 H Deanship of preparatory year SET-A Page 43 of 4

Q.4. Find out the syntax errors in the following codes and rewrite the correct code: [2*4=8 Marks] i. include <iostrea> using namespace std; void main( ) int x,y cout<< enter two integer ; cin>>x>y; if(x==y cout<<x<< == <<y; return 0; - - - - - - - Deanship of preparatory year SET-A Page 44 of 4

- - - ii. #include <iostream using namespace std; vid min() int c=0; whle(c<= 10 c++; cou<c <<\n ; 4 Programming in C++ Alternative Exam 1433-1434 H -- -- - - - Deanship of preparatory year SET-A Page 45 of 4

- - - - - - Q.5. What will be the output of the following code? [2*3=6 Marks] i. #include <iostream> using namespace std; int main() int counter=6; do cout<<counter<< ; counter++; while (counter<=5); - Deanship of preparatory year SET-A Page 46 of 4

- - - - -- 5 Programming in C++ Alternative Exam 1433-1434 H -- - - ii. #include <iostream> using namespace std; void main( ) for (int x=10; x>=2; x-=2) cout<<x<<"\n "; - Deanship of preparatory year SET-A Page 47 of 4

- - - - - - - - - Kingdom of Saudi Arabia Ministry of Higher Education Course Code: ` 011-COMP Course Name: Programming language-1 Date: 7.08.2014 Deanship of Preparatory Year Jazan University Total Marks: 20 Duration: 60 min Group: 6 Programming in C++ Alternative Exam 1433-1434 H Deanship of preparatory year SET-A Page 48 of 4

Examination for the summer Term - Academic Year 1434 1435 H Alternative Mid-Term Name of student: ID: Sr. No. Q.1 Select the correct option of your choice from the followings: (5*1=5 Marks) i. Which of the following is used to give tab space between two words. (a) \t (b) \ (c) /t (d) None of the above ii. iii. Output Statement uses the operator with cout (a) > (b) >> (c)<< (d) @ Statement in c++ should end with. (a) ; (b) : (c), (d). iv. Single-line comment uses: (a) \\ (b) // (c ) /* (d) *\ v. conditional operator is ternary operator it takes three operands. (a)? : (b) >> (c ) /* (d) # Q.2 Define the following terms. (2*2=4 Marks) (i) Block in C++ language. Deanship of preparatory year SET-A Page 49 of 4

...... (ii) High Level Language.. Q.3 Find out errors in the below given program? (2*3=6 Marks) (i) #include<iostream #include<conio.h> using namespace std; void main(); int n,sqr,cub cout<<"enter the number : "; cin>>n; sqr=n*n; cub=n*n*n; cout<<"\nsquare="<<sqr; cout>>"\ncube="<<cub; getch(); Answer: Deanship of preparatory year SET-A Page 50 of 4

(ii) #include<iostream> include<conio.h> using namespace std; void main() int i: for(i=1; i<=10, i++) cout<<i<<endl; getch(); Answer: Q.4 Write a Program to find the greatest of three numbers. (5*1=5 Marks) Deanship of preparatory year SET-A Page 51 of 4

***** Good Luck ***** Deanship of preparatory year SET-A Page 52 of 4