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

Similar documents
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

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 Dr. KHALIL Exam II Spring 2010

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 Instructor: Final Exam Fall 2014

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

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

Solve only 2 out of 3 questions

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

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

WARM UP LESSONS BARE BASICS

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

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.

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

A First Program - Greeting.cpp

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

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

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

CSCE Practice Midterm. Data Types

CS101 PLEDGED SPRING 2001

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

Chapter 3 Problem Solving and the Computer

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

CSCE 206: Structured Programming in C++

Midterm Practice Exam

a. a * c - 10 = b. a % b + (a * d) + 7 =

University of Dublin

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

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

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

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

Describing and Implementing Algorithms

EECS402 Lecture 02. Functions. Function Prototype

Scientific Computing

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

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.

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

BITG 1233: Introduction to C++

Ch 6. Functions. Example: function calls function

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

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

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

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

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

Introduction to Computer Science Midterm 3 Fall, Points

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

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

Problem Solving: Storyboards for User Interaction

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

CSCE Practice Midterm. Data Types

Subprograms. Introduction to Programming (in C++) Subprograms: procedures and functions. Subprograms. Subprograms. Functions are defined as follows:

Summary of basic C++-commands

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met.

Week 3: Pointers (Part 2)

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Chapter 4 - Notes Control Structures I (Selection)

CMPS 221 Sample Final

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

Name Section: M/W or T/TH. True or False (14 Points)

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

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

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

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

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

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

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

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

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

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

Lab Instructor : Jean Lai

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

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CS242 COMPUTER PROGRAMMING

Chapter 1 INTRODUCTION

Computer Science II Lecture 1 Introduction and Background

Unit 7. 'while' Loops

Arrays. Week 4. Assylbek Jumagaliyev

Due Date: See Blackboard

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

Do not turn to the next page until the start of the exam.

CSCI-1200 Data Structures Fall 2011 Lecture 1 Introduction and Background

CSCE 2004 Final Exam Spring Version A

The following is a typical execution run of this program:

CPT101- Principles of Programming

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

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

Getting started with C++ (Part 2)

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

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Fundamentals of Programming CS-110. Lecture 2

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Transcription:

The American University in Cairo Computer Science & Engineering Department CSCE 106 Instructor: Final Exam Fall 2010 Last Name :... ID:... First Name:... 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 25 3 15 4 15 5 15 6 20 Total 100 1

Question 1 (10 points) Tick only one possible answer for each of the following: 1) The Compiler is a software that: a. translates a high-level language program into machine language [ ] b. translates an assembly language program into machine language [ ] c. lets users display and view a web document [ ] 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 [ ] 3) The value of (x 4!= 4) && (x 4 == 4) is: a. x - 4 [ ] b. True [ ] c. x + 4 [ ] 4) (11111111) 2 is equivalent to: a. (128) 10 [ ] b. (127) 10 [ ] c. (255) 10 [ ] 5) Von Neumann architecture is: a. A stored-program computer [ ] b. A web browser [ ] c. An architecture for RAM [ ] d. All the above [ ] 6)!((x == x) && (y > 10)) is equivalent to: a. True [ ] b. (x!= x) && (y < 10) [ ] c. (x!= x) (y <= 10) [ ] 7) The RAM is used to: a. To store fixed code to start up the computer [ ] b. To store programs and data that are to be executed [ ] c. To perform the arithmetic and logical operations [ ] d. none of the above [ ] 8) In binary: 1011 + 11011 =? a. 101000 [ ] b. 100110 [ ] c. 110110 [ ] d. 100101 [ ] 9) ((x == x) false) is equivalent to a. x == x [ ] b. false [ ] c. x!= x [ ] 10) ((x == x) && true) is equivalent to a. x == x [ ] b. false [ ] c. true [ ] 2

Question 2 (25 points) Show the output of each of the following program segments: bool myfunc(int n); int main () { for (int k=2; k <= 30; k += 3) If (myfunc(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; int x = 1, y = 1, z; y = y * x++; cout << x = << setw(2) << x << y = << setw(2) << y << endl; x = 6; y = 2; z = --x / y++; y = z-- + x++; cout << x = << x << y = << y << z = << z << endl; float a = 2, b = 2, c = 1.5, x; int d = 5, e = 4.5, y, z; x = a * b - c + d / e; y = a * (b - c) + d / e; z = a * (b - (c + d - 0.5) / e); cout << "x = " << setw(4) << x << " y = " << setw(4) << y << " z = " << setw(4) << z << endl; 3

# include <iostream> # include <iomanip> using namespace std; void main() { int num = 3509, d; const int ten = 10; d = num % ten; s = s + d; num = num / ten; d = num % ten; s = s + d; num = num / ten; d = num % ten; s = s + d; d = num / ten; s = s + d; cout << The result is << setw(4) << s << endl; 4

Question 3 (15 points) Write a C++ program that uses only two nested loops to produce the following output: @ @ @ @ @ @ @ @ @ # # # # # # # # & & & & & & & @ @ @ @ @ @ # # # # # & & & & @ @ @ # # & 5

Question 4 (15 points) Write a C++ program that computes and outputs the volume of a cone and area of its base, given the diameter of its base and its height. The program should validate the user input to accept only values that are greater than 0 for both diameter and height. The formulas for computing the cone s base area and volume are: Area of base = π X Radius 2 Volume of cone = 1/3 X π X Radius 2 X Height Print both computed values to the nearest tenth. Be sure to use proper formatting and appropriate comments in your code. The output should be clearly labeled. Show the three phases of software development: the analysis, design (draw a Flow Chart), and implementation. The Analysis The Flow Chart 6

The Program 7

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&, int&);. 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; void swap (.) { int T = X;.... GCD (int A, int B) { int R; R = A % B; while (.) { A = B;.. R =.. return..; 8

Question 6 (20 points) Write a complete modular C++ program that produces a table showing the temperature equivalents in degrees Fahrenheit and degrees in Celsius. The table consists of a header, set of rows and a footer (see the given example below). Let the user enter the starting, ending, and step values. Use the formula: celstemp = 5/9 (farentemp 32.00) You are advised to define four functions: main, header, footer, and converttocelsius. The main functions calls the header function to print the header of the table (as shown in the given example), takes from the user the starting, ending and step values (with enforcing the necessary validation that the ending value should be greater than the starting value), go over each Fahrenheit value in the range to call the function converttocelsius that takes the Fahrenheit value and returns its equivalent Celsius value according to the formula given above. The main function prints the Fahrenheit value and its equivalent Celsius value in one row of the table. After printing the last row in the table, the main function calls the footer function that prints the footer (18 dashes). - - - - - - - - - - - - - - - - - - F a h r e n h e i t C e l s i u s - - - - - - - - - - - - - - - - - -........................... - - - - - - - - - - - - - - - - - - 9

10 Good Luck