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

Similar documents
CSCE Practice Midterm. Data Types

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

CSCE Practice Midterm. Data Types

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

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

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

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

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

EE 109 Lab 8a Conversion Experience

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

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

Lab 2.1: Fixing a C++ program

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

Midterm Exam 5 April 20, 2015

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

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

Arrays in C++ Instructor: Andy Abreu

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.

Learning Objectives: General Description: DONE DONE Structure Chart

Add Subtract Multiply Divide

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

CS101 PLEDGED SPRING 2001

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):

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

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

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

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

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

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

Lab Instructor : Jean Lai

VARIABLES & ASSIGNMENTS

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

Programming Language. Functions. Eng. Anis Nazer First Semester

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

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

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

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

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)

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

C++ For Science and Engineering Lecture 12

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

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

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

Chapter 2 C++ Fundamentals

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

System Design and Programming II

Computer Science II Lecture 1 Introduction and Background

Homework 11 Program Setup (with some IMPORTANT NEW STEPS!)

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

CSCE 2004 Midterm Exam Spring 2017

CS242 COMPUTER PROGRAMMING

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

Sonoma State University Computer Science Department CS 115 Fall 2010 Watts. Project 3 Part 1

University of Toronto

Tutorial Letter 103/1/2017 Introduction to Programming I

True or False (15 Points)

Functions, Arrays & Structs

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

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

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

Introduction to Programming

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

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

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

The following is a typical execution run of this program:

BRAZOSPORT COLLEGE LAKE JACKSON, TEXAS SYLLABUS COSC 1320: INTRODUCTION TO C++ PROGRAMMING COMPUTER TECHNOLOGY & OFFICE ADMINISTRATION DEPARTMENT

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

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

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

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

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

LAB 4.1 Relational Operators and the if Statement

Algorithms for Programming Contests - Week 1

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

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

Homework #3 CS2255 Fall 2012

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

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

True or False (12 Points)

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CS31 Discussion 1E. Jie(Jay) Wang Week1 Sept. 30

Review Questions II KEY

Finally, a receipt is printed on the screen and, after a pause, the process repeats for the next customer.

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

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

CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

Ch. 17: Linked Lists. Introduction to Linked Lists

Sample Code: OUTPUT Daily Highs & Lows

CMSC 202 Midterm Exam 1 Fall 2015

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.

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

CMPS 221 Sample Final

Transcription:

CS 215 Spring 2018 Lab Exam 1 Review Material: - All material for the course up through the Arrays I slides - Nothing from the slides on Functions, Array Arguments, or Implementing Functions Format: - You will be given 4-5 programming problems to solve. - All solutions will be written in one.cpp file in one main() function. - One.cpp file will be submitted in Canvas - You will have 1 hour and 30 minutes to complete the exam. Points will be deducted per minute late submitted in Canvas. Practice Exam: Below is an exam from last semester. - Your exam will be slightly shorter - Your exam will not include material on this exam that is not indicated above. - Your exam will include material indicated above that is not on this exam. Dropping the write a function requirement, you could basically copy/paste the answers given at the end into your main(). Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

CS 215 Fall 2017 Lab Exam 1 Sec 006 Exam Rules: - You may use any notes/books, including those posted on the course website. - You may not use any other website. - You may not use any other devices (turn off cell phones, no calculators, etc). - You may use the lab machine, your laptop, or your VM. - You must use MS Visual Studio (it will be graded using MSVS, just like projects). - You may not communicate with any person other than the TA in any manner during the exam. Doing so will be considered cheating. - Timed: the exam is timed: o you will have one hour and 20 minutes to post your.cpp file in Canvas. o The TA will give you a 10 minute warning and a 5 minute warning. o Any exam submitted late may receive a 1% Penalty per minute late Getting help: You may ask only your TA for help. If it is something simple, such as a clarification (ex. what does this mean? ), the TA can help you. If you ask for help with errors, or with solving the problem, the TA may say: - I can t help you with that (especially for major solutions to a problem). Or - I will sell you a hint for a certain number of points. If you agree to the purchase, the TA will deduct those points from your final grade on the exam, and will type something for you on the keyboard. The answer is not guaranteed to solve all your problems for you. Specifications: - Write and execute a complete C++ program in MS Visual Studio according to the following specifications. - Programs that do not compile and execute may not receive a passing grade (-40%) - You may leave some code in comments (along with an explanation to the grader), if needed, for partial credit. - You will not be graded on Style, with the exception of: o Using constants where instructed. You may use constants elsewhere, but not required. o Make a comment box at the top with your name and CS 215 Lab Exam 1 1. Write a function that is given a chemical symbol (a string) and alters an element name and atomic number. Lookup and assign the name and atomic number from the table to the right. When the symbol given is not on the table, set the name to Error and the atomic number to -1. Examples: Given: O Alter name= Carbon, atomicnum=6 Given: Na Alter name= Sodium, atomicnum=11 Given: Br Alter name= Error, atomicnum=-1

2. Write a function that is given the length and width of a rectangle. These values may contain decimal points. Calculate and return the area of the rectangle. Formula: area = length X width Example: given 2.5 and 4, returns 10.0 3. In main(), test the first function: USING A LOOP, repeat the following test 4 times: Ask the user to enter a chemical symbol. Invoke the function, giving it the symbol entered, and print the name and atomic number set by the function. Declare and use a constant for the number of tests! (4) Example execution: Enter symbol: O Main: name=oxygen num=8 Enter symbol: Na Main: name=sodium num=11 Enter symbol: Br Main: name=error num=-1 Enter symbol: Fe Main: name=iron num=26 4. In main(), test the second function: Ask the user to enter a length and width. Invoke the function, giving it the length and width entered by the user. Print the area returned. Then ask the user if they want to test again (Y/N). Repeat the test as long as the user responds with Y. Note: there will always be at least one test. When done testing, print the average of all areas calculated. Example execution: Enter length and width: 2.5 4 Main: Area = 10 Test again? (Y/N): Y Enter length and width: 4 5 Main: Area = 20 Test again? (Y/N): Y Enter length and width: 3 10 Main: Area = 30 Test again? (Y/N): N Average area = 20 (10 + 20 + 30) / 3

5. In main(), ask the user to enter a chemical symbol. Invoke the first function, giving it the symbol entered. Validate the user s input by repeating the question until the user enters a known symbol (one on the chart in question 1). Note: you should not directly check if the user entered C, H, O, Na, etc! Instead, use the information set by the function! (the function already does the work of checking if it s a valid symbol it sets the atomic number to -1 for an unknown symbol). Once a known symbol is entered, print the name and atomic number. Example execution: Enter symbol: xx Unknown symbol! Enter a known value! Enter symbol: Br Unknown symbol! Enter a known value! Enter symbol: He Unknown symbol! Enter a known value! Enter symbol: O Main: name=oxygen num=8 End the execution with the normal PAUSE. Overall sample execution:

Overall sample execution: Solution/Key: // -------------------------------------------------------------------------- // CS 215 Lab Exam 1 (Sec 006 & 007) // <student's name> //--------------------------------------------------------------------------- // 4 points for comment box - must have "CS 215 Lab Exam 1" and student name #include <iostream> #include <string> using namespace std; const int NUM_TESTS = 4; // 3 pts - must be global // ----------------------------- QUESTION 1 --------------------------- // 2 points: void return type // 1 point: a good function name // 2 points: string arg // 2 points: string & arg // 2 points: int & arg void chemlookup(string sym, string & name, int & anum) { // 15 points: sets name and anum correctly if (sym == "C") { name = "Carbon"; anum = 6; else if (sym == "H") { name = "Hydrogen"; anum = 1; else if (sym == "O") { name = "Oxygen"; anum = 8; else if (sym == "Na") { name = "Sodium"; anum = 11; else if (sym == "Cl") { name = "Chlorine"; anum = 17; else if (sym == "Fe") { name = "Iron"; anum = 26; else { name = "Error"; anum = -1;

//------------------------------- QUESTION 2 --------------------------- // 2 points: return type double or float // 1 points: good function name // 2 points: double/float length // 2 points: double/float width double rectarea(double length, double width) { // 4 points: calculates and returns area correctly return (length * width); int main() { // 1 point //------------------------------- QUESTION 3 --------------------------- string symbol, name; int atnum; // 4 pts: must use a LOOP to repeat 4 times // 2 pts: must use a CONSTANT for the 4 for (int i = 1; i <= NUM_TESTS; i++) { cout << "Enter symbol: "; s cin >> symbol; s chemlookup(symbol, name, atnum); // 4 pts cout << endl; cout << "Main: name=" << name << " num=" << atnum << endl; // 4 pts //------------------------------- QUESTION 4 --------------------------- string ans; double area, length, width, avg; double sum = 0; // 2 pts: init sum = 0 int count = 0; // 2 pts: init count = 0 do { // or WHILE that repeats at least once cout << "Enter length and width: "; s cin >> length >> width; s area = rectarea(length, width); // 3 pts sum += area; // 2 pts count++; // 2 pts cout << "Main: Area = " << area << endl; cout << "Test again? (Y/N): "; cin >> ans; while (ans == "Y"); // 3 pts avg = sum / count; s cout << "Average area = " << avg << endl << endl; // 2 pts //------------------------------- QUESTION 5 --------------------------- cout << "Enter symbol: "; cin >> symbol; chemlookup(symbol, name, atnum); // 3 pts while (atnum == -1) { // 3 pts cout << "Unknown symbol! Enter a known value! \n"; s cout << "Enter symbol: "; cin >> symbol; chemlookup(symbol, name, atnum); cout << "Main: name=" << name << " num=" << atnum << endl; // 2 pts system("pause"); return 0;