The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)



Similar documents
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Comp151. Definitions & Declarations

An Incomplete C++ Primer. University of Wyoming MA 5310

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Ch 7-1. Object-Oriented Programming and Classes

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Basics of I/O Streams and File I/O

Illustration 1: Diagram of program function and data flow

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

C++ Language Tutorial

Chapter 9 Text Files User Defined Data Types User Defined Header Files

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

Member Functions of the istream Class

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Stacks. Linear data structures

Passing 1D arrays to functions.

Chapter One Introduction to Programming

C++FA 5.1 PRACTICE MID-TERM EXAM

Note: Syntactically, a ; is needed at the end of a struct definition.

Sources: On the Web: Slides will be available on:

13 Classes & Objects with Constructors/Destructors

First Bytes Programming Lab 2

Data Structures using OOP C++ Lecture 1

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

While Loop. 6. Iteration

Sequential Program Execution

Introduction to Java

7.7 Case Study: Calculating Depreciation

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Answers to Review Questions Chapter 7

Chapter 5. Selection 5-1

Computer Programming C++ Classes and Objects 15 th Lecture

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Chapter 5 Functions. Introducing Functions

CORBA Programming with TAOX11. The C++11 CORBA Implementation

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

MS ACCESS DATABASE DATA TYPES

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

The Payroll Program. Payroll

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

csce4313 Programming Languages Scanner (pass/fail)

5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class

The little endl that couldn t

Conditions & Boolean Expressions

Appendix K Introduction to Microsoft Visual C++ 6.0

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

Compiler Construction

Boolean Expressions 1. In C++, the number 0 (zero) is considered to be false, all other numbers are true.

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Syllabus OBJECT ORIENTED PROGRAMMING C++

C++ Input/Output: Streams

Object Oriented Software Design II

Chapter 1: Key Concepts of Programming and Software Engineering

Chapter 2: Elements of Java

CS 241 Data Organization Coding Standards

A brief introduction to C++ and Interfacing with Excel

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

The programming language C. sws1 1

Introduction to Java. CS 3: Computer Programming in Java

7th Marathon of Parallel Programming WSCAD-SSC/SBAC-PAD-2012

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Programming Languages CIS 443

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

C++ INTERVIEW QUESTIONS

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

EP241 Computer Programming

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

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

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

Learning Computer Programming using e-learning as a tool. A Thesis. Submitted to the Department of Computer Science and Engineering.

Coding Standard for Java

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents

Answers to Selected Exercises

Formatting Numbers with C++ Output Streams

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum

Goals for This Lecture:

CISC 181 Project 3 Designing Classes for Bank Accounts

Conditional Statements Summer 2010 Margaret Reid-Miller

Moving from C++ to VBA

/* File: blkcopy.c. size_t n

Chapter 8 Selection 8-1

DNA Data and Program Representation. Alexandre David

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Example of a Java program

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Lesson 10: Video-Out Interface

Portal Connector Fields and Widgets Technical Documentation

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Decision-making Computer Science Lesson to Prepare for UIL Computer Science Contest

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Transcription:

True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local variables. 2. The statement return 3 * alpha + 8; is valid in a value-returning function but not in a void function. Name: 3. If a programmer has developed a large portion of a complete project and wants to test the developed portion before implementing the remaining functions, this programmer is more likely to need function drivers than function stubs. 4. Because of representational error, two integers should not be compared for exact equality. 5. In the data type defined by enum Colors RED, GREEN, BLUE the enumerators are ordered such that RED > GREEN > BLUE. 6. C++ allows a struct to be a member of another struct. 7. In C++, a struct can be passed as a parameter either by value or by reference. 8. C++ does not allow aggregate operations on structs. Multiple Choice (2 points each) 9. If a variable alpha is accessible only within function F, then alpha is either a. a global variable or a parameter of F. b. a local variable within F or a parameter of F. c. a global variable or an argument to F. d. a local variable within F or an argument to F. 10. Given the function definition int Mystery( /* in */ float someval ) if (someval > 2.0) return 3 * int(someval); else return 0; what is the value of the expression Mystery(4.2)? a. 12 b. 12.0 c. 0 d. 0.0 e. nothing--the function call is invalid 11. A struct is an example of: a. a simple data type b. a homogeneous structured type c. a heterogeneous structured type d. an enumeration type

12. Given the function prototype int Top( int, int ); which of the following statements contain valid calls to the Top function? a. someint = 4 + Top(oneInt, anotherint); b. cin >> Top(oneInt, anotherint); c. cout << Top(5, Top(3, 4)); d. a and c above e. a, b, and c above 13. What is the appropriate function prototype for a function that receives a character letter grade and returns its integer equivalent on a four-point grading scale? a. void IntEquiv( char ); b. void IntEquiv( int ); c. int IntEquiv( char ); d. int IntEquiv( char& ); e. char IntEquiv( int ); 14. Assume you have the following declarations: enum Days SUN, MON, TUE, WED, THU, FRI, SAT Days someday; Days twobefore; and that someday has been assigned some value. The variable twobefore is to represent the day of the week that is two days before someday. Which of the following stores the proper value into twobefore? a. twobefore = someday - 2; b.twobefore = Days(someDay - 2); c. if (someday < TUE) twobefore = SAT; else twobefore = someday - 2; d.switch (someday) case SUN : twobefore = FRI; break; case MON : twobefore = SAT; break; default : twobefore = Days(someDay - 2); e. none of the above 15. Which of the following is a valid use of the C++ cast operation? a. beta = short(alpha); b. beta = (long double) alpha; c. beta = long double(alpha); d. a and b above 16. You are writing a program that will add three floating point variables x, y, and z. Their likely value ranges are as follows: x: 0.01 to 0.9 y: 2.1E10 to 3.0E10 z: -3.5E10 to -2.2E10 In which order should you add them to obtain the most accurate answer? a. Add x and y, then add z. b. Add z and x, then add y. c. Add y and z, then add x.

17. Given the declaration struct PersonRec int age; float height; int weight; which of the following is valid for creating and initializing a PersonRec variable? a. PersonRec me; me.age = 19; me.height = 66.5; me.weight = 140; b. PersonRec me = 19, 66.5, 140 c. PersonRec.age = 19; PersonRec.height = 66.5; PersonRec.weight = 140; d. a and b above e. a, b, and c above 18. Given the declarations typedef char String19[20]; struct BrandInfo String19 company; String19 model; struct DiskType BrandInfo brand; float capacity; DiskType mydisk; what is the type of mydisk.brand? a.char b. DiskType c.st ring19 d. BrandInfo e.none of the above Fill in the Blank (2 points each) 19. A(n) is a simple main function that is used to call a function being tested. 20. The of an identifier is the region of program code where it is legal to reference that identifier. 21. An If statement is an example of a(n) control structure. 22. is the condition that occurs when the result of a calculation is too large to be represented in memory. 23. is the conversion of a value from a "lower" type to a "higher" type according to a programming language s precedence of data types. 24. An If statement is an example of a(n) control structure.

25. Given the declarations enum WoodKind HARDWOOD, SOFTWOOD struct Size int length; int width; int thickness; struct Wood Size dimensions; WoodKind kind; int smoothsurfaces; Wood oneboard; write a statement to print the width of oneboard: 26. (16 points) a. (4 points) Declare an enumeration type for the undergraduate engineering degrees given at UAH, using the appropriate abbreviation for chemical engineering, civil engineering, computer engineering, electrical engineering, industrial engineering, mechanical and aerospace engineering, and optical engineering. b. (8 points) Write a value-returning function that converts the first two letters of the abbreviation into the type declared in (a). c. (4 points) Give the necessary declarations and make a call to the function you wrote in part (b).

27. (12 points) What is the output of the following C++ program? #include <iostream> using namespace std; void Do Global(); void DoLocal(); void DoReference(int&); void DoValue(int); int x; int main() x = 15; DoReference(x); cout << x = << x << after the call to DoReference. << endl; x = 16; DoValue(x); cout << x = << x << after the call to DoValue. << endl; x = 17; DoLocal(x); cout << x = << x << after the call to DoLocal. << endl; x = 18; DoGlobal(x); cout << x = << x << after the call to DoGlobal. << endl; return 0; void DoReference (int& a) a = 3; void DoValue (int b) b = 4; void DoLocal() int x; x = 5; void DoGlobal () x = 7;

28. (10 points) Given the declarations: struct NameType string first; string last; struct AddrType string city; string state; long zipcode; struct PersonType NameType name; AddrType address; PersonType person; write C++ code that store the following information into person: Beverly Johnson La Crosse, WI 54601 29. (12 points) Write a value-returning function that accepts one int parameter, num, and returns the value of num + num-1 + num-2... + 2 + 1. If num is negative, return 1. Use a for loop in your solution.