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

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

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

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

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

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

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

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

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

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

Solve only 2 out of 3 questions

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.

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

Chapter 1 INTRODUCTION

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

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

A First Program - Greeting.cpp

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

CSCE 206: Structured Programming in C++

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

CSCE Practice Midterm. Data Types

Scientific Computing

Introduction to C++ (Extensions to C)

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

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

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

WARM UP LESSONS BARE BASICS

Midterm Practice Exam

REVIEW. The C++ Programming Language. CS 151 Review #2

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

READ THIS NOW! Do not start the test until instructed to do so!

Chapter 4 - Notes Control Structures I (Selection)

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

BITG 1233: Introduction to C++

Chapter 2: Basic Elements of C++

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100


FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

Ch 6. Functions. Example: function calls function

CSCE 2004 Midterm Exam Spring 2017

Getting started with C++ (Part 2)

EECS402 Lecture 02. Functions. Function Prototype

Lab Instructor : Jean Lai

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

PIC 10A. Final Review: Part I

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

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

CSCE Practice Midterm. Data Types

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

University of Dublin

Fundamentals of Programming CS-110. Lecture 2

Sample Code: OUTPUT Daily Highs & Lows

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

CS 1044 Programming in C++ Test 1 READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties.

Unit 7. 'while' Loops

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

CSCE 121 ENGR 112 List of Topics for Exam 1

I/O Streams and Standard I/O Devices (cont d.)

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato,

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

(3) Some memory that holds a value of a given type. (8) The basic unit of addressing in most computers.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

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

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.

Introduction to the C++ Programming Language

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

Summary of basic C++-commands

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Independent Representation

CS 247: Software Engineering Principles. ADT Design

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Notes on the 2008 Exam

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

Week 3: Pointers (Part 2)

Arrays. Week 4. Assylbek Jumagaliyev

PIC 10A. Review for Midterm I

True or False (15 Points)

Objectives. In this chapter, you will:

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

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

1a Computers, Problem Solving!

Transcription:

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science Instructor: Dr. Khalil Final Exam Fall 2013 Last Name :... ID:... First Name:... Form I Section No.: ( ) EXAMINATION INSTRUCTIONS * Do not turn this page until asked to do so. * Exam time is 120 minutes. * Put the answers on the same question sheet, do not use any additional papers, even for scratch. * Write your name, ID, section no. in the indicated places. * Read the exam instructions. * Read the honesty policy. * Sign the following statement. Academic Integrity Policy Cheating in Exams is a violation of the honesty policy of AUC. Whispering, talking, looking at someone else s paper, or copying from any source is considered cheating. Any one who does any of these actions or her/his answers indicates that she/he did any of them, will receive a punishment ranging from zero in this exam to failing the course. If repeated, it may lead to dismissal from AUC. I have read the honesty policy and exam instructions and I am presenting this exam as entirely my effort. Signature: --------------------------------------------------------------------------------------------------------------------------- DO NOT USE THIS SECTION Question Points Grade 1 10 2 20 3 20 + 3 4 15 + 3 5 15 6 20 Total 100 1

Question 1 (10 points) Tick only one possible answer for each of the following: 1) The Boolean expression!(x > y ) can be simpilified into: a. ( x < y) [ ] b. ( x >= y) [ ] c. True [ ] d. none of the above [ ] 2) Intellectual Property: a. A form of protection that can be granted by the government for an invention; gives exclusive rights of an invention to its inventor for 20 years. [ ] b. Standards of moral conduct as they relate to computer use. [ ] c. The rights to which creators of original creative works (such as software, artistic, literary works, inventions, and more) are entitled. [ ] d. The legal right to sell, publish, or distribute an original software, artistic or literary work; is held by the creator of a work as soon as it exists in physical form. [ ] 3) The value of ((x 4)!= 4) && ((x 4) == 4) is: a. (x 4) [ ] b. False [ ] c. (x + 4) [ ] d. none of the above [ ] 1) In binary: 1011 + 11011 =? a. 101000 [ ] b. 100110 [ ] c. 110110 [ ] d. none of the above [ ] 2) Summing up all even integers is a nonalgorithmic problem, because: a. It s too difficult to compute [ ] b. It involves infinite number of operations without termination [ ] c. No machine can do it [ ] d. The algorithm to do it will very long [ ] 4) The ALU is the unit of computer responsible of: a. Storing programs and data permanently [ ] b. Performing arithmetic and logical operations [ ] c. Performing Input/Output operations [ ] d. None of the above [ ] 5) The value of ((x <= y ) True) is: a. ( x > y) [ ] b. ( x <= y) [ ] c. False [ ] d. none of the above [ ] 6) Von Neumann architecture is: a. A stored-program computer [ ] b. A web browser [ ] c. An architecture for RAM [ ] d. All the above [ ] 7) (110) 10 + (110) 2 is equivalent to: a. (220) 10 [ ] b. (1110100) 2 [ ] c. (1100) 2 [ ] d. None of the above [ ] 8) The software that controls and manages the computer resources is: a. Linker [ ] b. Loader [ ] c. Web browser [ ] d. Operating system [ ] 2

Question 2 (20 points) Show the output of each of the following program segments: bool myfunc(int n); int main () int num[10] = 7, 9, 11, 15, 17, 19, 21; for (int k = 0; k < 5; k ++) If (myfunc( num[k] )) cout << setw(4) << k; cout << endl; bool myfunc(int n) bool flag = true; int c = 2; while ( (c <= n/2) && (flag) ) if (n % c == 0) flag = false; else c++; return flag; float a = 3, b = 2, c = 1.5, x; int d = 4, e = 6.5, y; cout << setiosflags (ios :: fixed ios :: right); x = a * b c + ++d / e++; y = a * b c + e / --d; cout << " x = " << setw(4) << x << endl; cout << " y = " << setw(4) << y << endl; a = 3.3456; b = 5.9876; cout << setprecision(2); cout << setw(4) << a << setprecision(1) << setw(4) << b << endl; cout << setprecision(0) << setw(4) << a << setw(4) << b << endl; int n = 11101, w = 1, s = 0; const int ten = 10; cout << The equivalent value of << n << = ; do s = s + w * (n % ten); w = 2 * w; n = n / ten; while ( n!= 0 ); cout << s << endl; 3

Void interchange (int&, int&); void main() int a = 6.5, b = 5.3, c = 3.2; do if ( b < a) interchange (a, b); if ( c < b ) interchange (b, c); while (( b < a ) ( c < b )); cout << "The Final value is: << endl; cout << setw(4) << (b + c) / 2 << endl; void interchange (int& X, int& Y) int T = X; X = Y; Y = T; bool check ( int ); void main () int BB [5]; int AB [5] = 102, 10, 101, 1100, 103; for ( int index = 0; index < 5; index++) if ( check ( AB[index] ) ) BB[index] = 1; else BB[index] = 0; for ( int r = 0; r < 5; r++) cout << setw(3) << BB[r]; cout << endl; system ( pause ); bool check ( int n) const int ten = 10; bool flag = true; do if (( n % ten == 0 ) ( n % ten == 1 )) n = n / ten; else flag = false; while ( ( n!= 0 ) && ( flag) ); return flag; 4

Question 3 (20 points) 1. The following C++ function rotate takes three integer numbers over its parameters a, b, and c and then rotates them, such that a takes the value of c, b takes the value of a, and c takes the value of b. The function uses only one additional variable temp (as temproray store). After being rotated, the three values should be returned back to the main function. Complete the following code of the function rotate: rotate ( a,. b, c) int temp;..;..;..; 2. Write a C++ function exists that takes a big positive integer number (big) and a single digit (d) from 0 to 9. The function returns true if the digit (d) does exist in the big positive number (big), and returns false, otherwise.. (For example: if the function takes 2799817 as a big integer number, and 7 as a single digit, then, it returns true, and if the function takes 345086 as a big integer number, and 9 as a single digit, then, it returns false. Make your (Bonus 3 points: Make your function more efficient by terminating it after the first digit (d) is found in the big integer number (big) ) 5

Question 4 (15 points) Write only the C++ nested-loop to produce the following output: (Bonus 3 points for only using: nested-loop + one if statement + one switch statement) @ # # # # # # # # 1 2 # # # # # # # & & & # # # # # # @ @ @ @ # # # # # 1 2 3 4 5 # # # # & & & & & & # # # @ @ @ @ @ @ @ # # 1 2 3 4 5 6 7 8 # & & & & & & & & & 6

Question 5 (15 points) The ancient Greek Euclid developed a method for finding the Greatest Common Divisor (GCD) of two integers A and B (A greater than B). His method is: 1. If the remainder (R) of A / B is 0, then B is the GCD. 2. If it is not 0, then assign B to A and the remainder (R) to B. 3. Return to step 1 and repeat the process. The following C++ program takes two integer numbers N and M and prints out their GCD. The program is structured as three functions: the main, swap and GCD. The main function takes two integer numbers N and M and if N < M it calls the function swap that will interchange the values of N and M (N is assigned to M and M is assigned to N). Then, the function main calls the function GCD that receives the values of N and M as A and B, performs Euclid s process (defined above) and returns the corresponding GCD value to the main function that prints it out. The C++ program is given below but there are some missings (represented by dots). Complete these missings such that the program could be compiled and run correctly. # include <iostream> #include <iomanip> using namespace std; void swap(int& X, int& Y);. void main () int N, M; cin >> N >> M; if (N < M) << cout << The Greatest Common Divisor of << setw(4) << N << and << setw(4) << M << is <<. << endl; system ( pause ); void swap (.) int T = X;.... GCD (.. A,.. B ) int R = A % B; while (.) A = B;.. R =.. return..; 7

Question 6 (20 points) Write a C++ modular program to generate a table showing the equivalent decimal value of a binary value. The table contains 20 rows at most. The program goes through the following steps: 1. The main function takes a positive integer number n representing the number of rows to be printed in the table. The program validates the entered value for n to accept only a value that is greater than 0 but not more than 20. 2. The main function takes from the user the binary numbers one by one to be stored in an array. Each entered binary number should be validated by sending it to the function validate_binary that checks that it is only a combination of 0 s and 1 s and returns back an appropriate feedback to the main function. 3. The main function prints out the header of the table (see the given example below). Reads the binary numbers one by one from the array and sends it the function convertbtod which computes its equivalent decimal value and returns it back to the main function. The program prints a row with the two values; the binary number and its equivalent decimal value. 4. After printing n rows, the program prints a footer (see the example below). 5. You are advised to define and use appropriate functions to print the header and footer of the table. Example: for n = 5, and binary numbers = 101, 1101, 111, 1111, and 10001, the generated conversion table should look like the following one: ####################################### Binary Number Decimal Value ------------------------------------------------------------ 101 5 1101 13 111 7 1111 15 10001 9 ######################################... 8

9

Good Luck 10