CSCE Practice Midterm. Data Types

Similar documents
CSCE Practice Midterm. Data Types

CSCE 2004 Midterm Exam Spring 2017

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

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

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

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.

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

CSCE 206: Structured Programming in C++

1st Midterm Exam: Solution COEN 243: Programming Methodology I

4. C++ functions. 1. Library Function 2. User-defined Function

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

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

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

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

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

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

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

CMSC 202 Midterm Exam 1 Fall 2015

Lab Instructor : Jean Lai

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

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

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

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

True or False (12 Points)

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 1

Problem Solving: Storyboards for User Interaction

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

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 3

Getting started with C++ (Part 2)

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 (!

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

A First Program - Greeting.cpp

More Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference

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

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

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

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

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

System Design and Programming II

CS2141 Software Development using C/C++ C++ Basics

1. In C++, reserved words are the same as predefined identifiers. a. True

LAB 4.1 Relational Operators and the if Statement

Functions, Arrays & Structs

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

A SHORT COURSE ON C++

Exceptions, Case Study-Exception handling in C++.

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

EECS402 Lecture 02. Functions. Function Prototype

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

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

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

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

do { statements } while (condition);

PIC 10A. Review for Midterm I

1) You want to determine whether time has run out. The following code correctly implements this:

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

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

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

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

FORM 2 (Please put your name and form # on the scantron!!!!)

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

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

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Tutorial Letter 103/1/2017 Introduction to Programming I

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

The following expression causes a divide by zero error:

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

Outline. 1 About the course

CMPS 221 Sample Final

Chapter 2 C++ Fundamentals

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

Exercise 1.1 Hello world

What we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator:

True or False (15 Points)

Introduction to Programming EC-105. Lecture 2

CPE Summer 2015 Exam I (150 pts) June 18, 2015

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

C++ For Science and Engineering Lecture 12

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

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

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010

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

3.1. Chapter 3: The cin Object. Expressions and Interactivity

Programming. C++ Basics

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1

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

Chapter 2: Basic Elements of C++

Transcription:

CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers you don't understand, see the TA for an explanation. This practice midterm is slightly longer than the one you can expect to see next week to provide extra questions for your practice. Data Types [15 points] Examine the following C++ assignment statements variable = expression. For each statement indicate the order in which the sub-pieces are evaluated, and the values along the way. Give the value and data type (float, int, char) of the final expression as well as the value and type stored in the variable. float Taxes; Taxes = (20 * 4 + 30 * 3)/50; float Result; Result = 5 / 2-5 % 2; int Distance; Distance = 3.5 + 3 / (2 + 3); int Number; Number = 3 * 2 / 10.0;

Loops [5 points] Rewrite the following while loop as a for loop that performs the same task. int Max = 1900; int Sum = 0; while ((Max < 1950)) Sum = Sum + (Max - 1900); cout << "Sum: " << Sum << "\n"; Max = Max + 5; [5 points] Rewrite the following do-while loop as a while loop that performs the same task. int Hours = 0; int Total = 0; do cout << "Enter a number between 0 and 20: "; cin >> Hours; if ((Hours > = 0) && (Hours < = 20)) Total = Total + Hours; while (Total < 200); [5 points] Rewrite the following nested for loops as a single for loop that produces the same output. int i, j; for (j = 1; j < 4; j++) for (i = j; i < j+1; i++) cout << "The value is: " << i << "\n";

Switch Statement [5 points] Write a C++ switch statement that stores 4.0 in NumberGrade if the grade is an A or a, 3.0 for B or b, 2.0 for C or c, 1.0 for D or d, and 0.0 for an F or f. It should output "invalid grade" and set value to -1.0 for any other character. char LetterGrade; float NumberGrade; cout << "Enter your grade: "; cin >> LetterGrade; Nested Loops [5 points] Consider the following C++ program. What does it print out? Show your work where necessary. #include <iostream> using namespace std; int main() int X, Y; // Outer loop for (Y=1; Y < 10; Y = Y + X) X=1; // Inner loop while(x < 3) cout << "X: " << X << endl; X=X+1; cout << "Y: " << Y << "\n"; // Code after loop cout << "Final value of X: " << X << "\n"; cout << "Final value of Y: " << Y << "\n"; return(0);

If Statements [10 points] Fill in a C++ program which asks the user several Y/N questions and selects a car for them based on their answers. The questions are 1) do you have children; 2) do you have lots of money; and 3) do you like trucks. The car selection should be based on the following: Porsche: Yukon: Civic: Villager: Explorer: Sentra: have no children, have lots of money, don't like trucks have no children, have lots of money, like trucks have no children, have little money have children, have lots of money, don't like trucks have children, have lots of money, like trucks have children, have little money #include <iostream> using namespace std; int main() // Declare variables char Children; char Money; char LikeTrucks; // Get user inputs (no error checking necessary) // Output the car choice based on user input above return 0;

Calling Functions [10 points] For each of the following function prototypes, which of the following calls are syntactically correct? Note: function calls that would compile with warnings or compile without warnings but cause implicit type conversions should be considered incorrect. // Variable declarations int A, B, C; float X,Y; char Char; // Function prototypes int Maximum (const int Num1, const int Num2); void Total (const float A, const float B, float &C); char GetChar(); Maximum (A,B); A = Maximum (7,3); A = Maximum (Num1, Num2); Total (A, B, C); Total (3.0, X, Y); Total (3.0, 5.0, 8.0); Total (Y, X, Y); GetChar (Char); Char = GetChar ();

Defining Functions [10 points] For this question, your task is to write function prototypes (the first line of the function that gives the return type and the list of parameters). You do NOT have to fill in the function bodies. Use const where appropriate. // This function takes in two numbers and returns their average. Average ( ); // This function asks the user how many sisters they have and returns their answer. GetSisters ( ); // This function takes in one number and returns the square root of this number. SquareRoot ( ); // This function take in a letter grade and returns // the corresponding grade point value (eg A = 4.0). GetGPA ( );

Function Tracing #include <iostream> using namespace std; const int X = 3; void Proc1 (int &Y) Y = 6; cout << "Inside Proc1, X: " << X << " Y: " << Y << "\n"; int Proc2 (int &Y, const int Z) int X = 7; Proc1 (X); Proc1 (Y); Y = 3; cout << "Inside Proc2, X: " << X << " Y: " << Y << " Z: " << Z << "\n"; return (Y + Z); int main() int A = 1; int B = 3; int C = 5; C = Proc2 (A,B); cout << "Finally, A: " << A << " B: " << B << " C: " << C << "\n"; return(0); [5 points] Using the box method, trace the execution of the program above to show the sequence of function calls, the values of variables, and return values. [5 points] Using this information, what does the program output?