Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms The C Programming Language.
Advertisements

Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Chapter 10.
Computer Science 1620 Loops.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
The If/Else Statement, Boolean Flags, and Menus Page 180
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Guide To UNIX Using Linux Third Edition
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Programming Introduction to C++.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
High-Level Programming Languages: C++
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
1 Chapter 9 Scope, Lifetime, and More on Functions.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Chapter 5 Functions For All Subtasks. Void functions Do not return a value. Keyword void is used as the return type in the function prototype to show.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Cs 141 Exam 1 Review1 Game Show!. Cs 141 Exam 1 Review2  What type/types hold the following:  'a'  '\n'  '4'
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 5 An Array Class Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
C++ Classes and Data Structures Jeffrey S. Childs
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University CONTROL STRUCTURES Simple If: if (boolean exp) { statements.
#include using namespace std; // Declare a function. void check(int, double, double); int main() { check(1, 2.3, 4.56); check(7, 8.9, 10.11); } void check(int.
1 CS161 Introduction to Computer Science Topic #8.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
Lecture 2 Functions. Functions in C++ long factorial(int n) The return type is long. That means the function will return a long integer to the calling.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CPS120 Introduction to Computer Science Exam Review Lecture 18.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
CS 1428 Final Exam Review. Exam Format 200 Total Points – 60 Points Writing Programs – 45 Points Tracing Algorithms and determining results – 20 Points.
Intro Programming in C++ Computer Science Dept Va Tech August, 2001 © Barnette ND & McQuain WD 1 Pass-by-Value - default passing mechanism except.
Function Parameters and Overloading Version 1.0. Topics Call-by-value Call-by-reference Call-by-address Constant parameters Function overloading Default.
Chapter Topics The Basics of a C++ Program Data Types
MT262A Review.
Chapter 1.2 Introduction to C++ Programming
Computing Fundamentals
Basic Elements of C++.
Chapter 1. Introduction to Computers and Programming
Variables A piece of memory set aside to store data
Basic Elements of C++ Chapter 2.
Pointers, Dynamic Data, and Reference Types
Counting Loops.
CS150 Introduction to Computer Science 1
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Introduction to C++.
Fundamental Programming
Presentation transcript:

Cs 141 Exam 2 Review1 Game Show!

Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review3 Whats wrong with this function void doubleIt(int num){ num = 2* num; }

Cs 141 Exam 2 Review4 Whats wrong with this function int double bar(int num){ return num; }

Cs 141 Exam 2 Review5 Whats wrong with this function void doubleIt(int num){ return 2* num; }

Cs 141 Exam 2 Review6 void baz (int num1, int &num); Which is the call by value parameter and which is the call by reference parameter?

Cs 141 Exam 2 Review7  What does call by value mean?

Cs 141 Exam 2 Review8  What does call by reference mean?

Cs 141 Exam 2 Review9 In what ways do return values and call-by- reference parameters accomplish the same thing. In what ways are they different?

Cs 141 Exam 2 Review10 What are the limitations of return values versus call-by-reference parameters?

Cs 141 Exam 2 Review11 void bar(int numArray[]){ } Is numArray call by value or call by reference?

Cs 141 Exam 2 Review12 What do you have to do to make an array parameter call by value?

Cs 141 Exam 2 Review13  What is the purpose of assertions?

Cs 141 Exam 2 Review14  What is meant by a global variable?

Cs 141 Exam 2 Review15  Where are global variables declared?

Cs 141 Exam 2 Review16 If the following function compiles then what is a? void func1(int b){ a = b; }

Cs 141 Exam 2 Review17 int a=10; what output? void func2(int b){ int a; a = b; } void func3(){ cout << a; } int main(){ func2(5); func3(); }

Cs 141 Exam 2 Review18 C-strings are a bit like our big Integers. We had arrays of 1000 locations we could use to store digits, but for any given big Integer, we may only use a few of those locations. C-strings are an array of characters but for any given string we may only use a few of the characters in the full array. In bigIntegers, how did we determine how many locations hold the digits of our number? In C-strings, how do we determine how many locations hold the characters in our string?

Cs 141 Exam 2 Review19 We've learned quite a few preexisting functions that we can use when programming. What functions did we use to generate random numbers?

Cs 141 Exam 2 Review20 What functions did we use to convert c- strings to numbers?

Cs 141 Exam 2 Review21 What functions did we use to test if a character was whitespace? Or a digit?

Cs 141 Exam 2 Review22 Some pre-existing functions we've learned belong to classes. What function did we learn to get the c- string equivalent of a C++ string?

Cs 141 Exam 2 Review23 What is the difference between exit and return?

Cs 141 Exam 2 Review24 Do return and exit have a different effect when called in the main function? Do return and exit have a different effect when called in another function?

Cs 141 Exam 2 Review25 Is int main() in our basic template a function?

Cs 141 Exam 2 Review26 What is special about the main function?

Cs 141 Exam 2 Review27 What is the difference between break and continue?

Cs 141 Exam 2 Review28 What function did we learn to open a file?

Cs 141 Exam 2 Review29  What is the type of variable used for output files?

Cs 141 Exam 2 Review30  What is the type of variable used for input files?

Cs 141 Exam 2 Review31 What is the difference between get and peek?

Cs 141 Exam 2 Review32 What two functions can be used to allocate memory dynamically?

Cs 141 Exam 2 Review33 If you allocate memory with malloc, what function should you use to deallocate it?

Cs 141 Exam 2 Review34 If you allocate memory with new what function should you use to deallocate it?

Cs 141 Exam 2 Review35 What is the difference between a plain array of characters and C-string?

Cs 141 Exam 2 Review36 Suggest an assertion to test the preconditions of this function: /* precondition: a and b are positive */ void func7(int a, int b);

Cs 141 Exam 2 Review37 What is a function prototype? How is it useful?

Cs 141 Exam 2 Review38 Propose a struct to hold a song type

Cs 141 Exam 2 Review39 Declare a variable of type song and initialize it to represent an actual song that you like.

Cs 141 Exam 2 Review40 Propose a struct to hold a BigInteger type?

Cs 141 Exam 2 Review41 Declare a variable of type BigInteger and initialize it to represent the variable 89.

Cs 141 Exam 2 Review42  How do you test if a file open succeeds?

Cs 141 Exam 2 Review43  How do you test if a file read or write succeeds?

Cs 141 Exam 2 Review44  How do you test if you read all the contents of a file?

Cs 141 Exam 2 Review45  If I did this ./a.out inputFile.txt  What would argc be?

Cs 141 Exam 2 Review46  If I did this ./a.out inputFile.txt  What would argv[1] be?

Cs 141 Exam 2 Review47  What type/types hold the following:  0,1,-1,2,-2,...

Cs 141 Exam 2 Review48  What is the main difference between the values that can be stored in an int variable and the set of all integers that you learned about in math?

Cs 141 Exam 2 Review49  What type/types hold the following: 0,1,2,3,4,...

Cs 141 Exam 2 Review50  What type/types could be legitimately substituted for TYPE TYPE foo = 4;

Cs 141 Exam 2 Review51  What is the main difference between a float and a double?

Cs 141 Exam 2 Review52 int bar = 23/4; What is bar?

Cs 141 Exam 2 Review53 int foo = 23%4; What is foo?

Cs 141 Exam 2 Review54 float bop = 23/4; What is bop?

Cs 141 Exam 2 Review55  int baz;  What is the value of baz?

Cs 141 Exam 2 Review56  What are three ways to initialize the value of a variable?

Cs 141 Exam 2 Review57  What would happen if you did this:  const int foo = 5;  foo = 10;

Cs 141 Exam 2 Review58  Is this a valid comment?  /* Written by Jeanna

Cs 141 Exam 2 Review59  Is this a valid comment?  \\ Written by Jeanna

Cs 141 Exam 2 Review60  What are two ways to write a valid comment?

Cs 141 Exam 2 Review61  Declare a variable to hold someone's last name.

Cs 141 Exam 2 Review62  Declare a variable to hold someone's age in years.

Cs 141 Exam 2 Review63  Declare a variable to hold someone's hourly wage.

Cs 141 Exam 2 Review64  Declare a variable to hold someone's middle initial.

Cs 141 Exam 2 Review65  If you wanted to declare a variable to keep track of the number of times someone blinks in a year, what would be a good choice for the type and why?

Cs 141 Exam 2 Review66 What does != mean?

Cs 141 Exam 2 Review67  What is the difference between = and ==?

Cs 141 Exam 2 Review68  What does && mean?

Cs 141 Exam 2 Review69  What does || mean?

Cs 141 Exam 2 Review70  What is the difference between: cin >> foo; cout << foo;

Cs 141 Exam 2 Review71  What type/types hold the following:  'a'  '\n'  '4'

Cs 141 Exam 2 Review72  Which of these lines is not like the others? foo++; ++foo; foo+=1; foo = foo +1; foo+1;

Cs 141 Exam 2 Review73  What is wrong with this? if ((answer == ‘y’) | (answer == ‘Y’)){ cout << “User entered yes\n”; }

Cs 141 Exam 2 Review74  What is wrong with this? if ((answer == ‘y’) && (answer == ‘Y’)){ cout << “User entered yes\n”; }

Cs 141 Exam 2 Review75 What will happen if you do this? num =3; if (num =2){ cout << “Number is 2\n”; } else { cout << “Number is not 2\n”; }

Cs 141 Exam 2 Review76 What will happen if you do this num =3; if (num !=2){ cout << “Number is not 2\n”; } else if (num < 4) { cout << “Number is less than 4\n”; } else if (num >0){ cout << “Number is greater than 0\n”; }

Cs 141 Exam 2 Review77  What is the value of BAZ below? enum SillyNames {FOO=1, BAR, BAZ};

Cs 141 Exam 2 Review78  Declare an enum of the days of the week.

Cs 141 Exam 2 Review79  What is the advantage of declaring an enum?

Cs 141 Exam 2 Review80  Are these two boolean expressions the same? (x >=10) ((x ==10) && (x > 10))

Cs 141 Exam 2 Review81  There are 3 different types of clauses in an if statement: if, else if and else  How many of each can you have?

Cs 141 Exam 2 Review82  Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions total =0; i=0; while (i< 10){ total = total +i; i++; } cout << total;

Cs 141 Exam 2 Review83  Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions for(i=0; i< 10; i++){ total = total +i; } cout << total;

Cs 141 Exam 2 Review84  Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions howMany=0; while(input_stream >> num){ howMany++; total = total + num; } average = total/howMany;

Cs 141 Exam 2 Review85  If homMany and total are ints, what problem will be have computing average? What could we do to fix the problem? What type should average be? howMany=0; while(input_stream >> num){ howMany++; total = total + num; } average = total/howMany;

Cs 141 Exam 2 Review86 int numbers[3]; How many ints are declared? How would you refer to the first one? The last one? Write a for loop to add them all up

Cs 141 Exam 2 Review87 int numbers[3][2]; How many ints are declared? How would you refer to first one? How would you refer to the last one? Write a for loop to add them all up.

Cs 141 Exam 2 Review88  If you want to read from or write to a file what must you add to our basic template?

Cs 141 Exam 2 Review89 #include

Cs 141 Exam 2 Review90  Declare a variable to hold a file you want to read from

Cs 141 Exam 2 Review91 ifstream input_file;

Cs 141 Exam 2 Review92  Declare a variable to hold a file you want to write to.

Cs 141 Exam 2 Review93 ofstream output_file;

Cs 141 Exam 2 Review94 How would you open the file “foo.txt”?

Cs 141 Exam 2 Review95 fileVariable.open(“foo.txt”);

Cs 141 Exam 2 Review96  If you try to open a file, what type of error should you check for and how do you do that?

Cs 141 Exam 2 Review97 Check if weren't able to open the file fileVariable.open(“foo.txt”); if (fileVariable.fail()){ cout << “Couldn't open the file\n”; }

Cs 141 Exam 2 Review98  How would you open the file foo.txt?

Cs 141 Exam 2 Review99  What does it mean to have a if statement nested inside a loop?

Cs 141 Exam 2 Review100  What does it mean to have nested for loops?  What are nested for loops especially good for?

Cs 141 Exam 2 Review101  True or false: There are some problems for which you must use a do-while loop. A while loop just won't work.

Cs 141 Exam 2 Review102  When is it generally better to use a do- while loop instead of a while loop?

Cs 141 Exam 2 Review103  When is it generally better to use a for loop instead of a while loop or do-while loop?

Cs 141 Exam 2 Review104  When you get a bunch of compiler errors which one should you fix first and why?

Cs 141 Exam 2 Review105  If you are trying to fix a specific compiler error, how can you figure out where the problem is?

Cs 141 Exam 2 Review106  What is a fence post error?

Cs 141 Exam 2 Review107  If you were going to test this loop what would be three great values of x to test? Why? cin >> x; for (int i=0; i< x; i++){ cout << i; }

Cs 141 Exam 2 Review108 Will these do the same thing? for (i=0; i< 3;i++ ) cout << i; for (i=0;i< 3 ){ cout << i; i++; }

Cs 141 Exam 2 Review109 Will these do the same thing? for (i=0; i< 3;i++ ) cout << i; i=0; while (i< 3 ) cout << i++;

Cs 141 Exam 2 Review110  What would you expect to happen if you did this int numArray[5]; numArray[5] = 100; cout << numArray[5];

Cs 141 Exam 2 Review111 Whats wrong with this int numArray[9]; for (int i=0; i<=9; i++){ numArray[i] = i; }

Cs 141 Exam 2 Review112 Do these all do the same thing? cout << num << “\n”; cout << num << endl; cout << num; cout << “\n”;

Cs 141 Exam 2 Review113  What child of a famous British poet is often considered the first programmer?

Cs 141 Exam 2 Review114 Ada Byron Lovelace ( )

Cs 141 Exam 2 Review115  Who is the creator of C++?

Cs 141 Exam 2 Review116 Bjarne Stroustrup

Cs 141 Exam 2 Review117  Who is the creator of the C programming language and a co-author of the UNIX operating system?

Cs 141 Exam 2 Review118 Dennis Ritchie

Cs 141 Exam 2 Review119  Explain the joke in the name C++

Cs 141 Exam 2 Review120  Who coined the term “debugging” and wrote the first compiler for a computer programming language?

Cs 141 Exam 2 Review121 Rear Admiral Grace Hopper

Cs 141 Exam 2 Review122 Picture of the moth that was the first computer “bug”

Cs 141 Exam 2 Review123 Who is this?

Cs 141 Exam 2 Review124  Linus Torvalds author and developer of Linux

Cs 141 Exam 2 Review125 Who is this?

Cs 141 Exam 2 Review126  Steve Jobs, co-founder and CEO of Apple Corporation

Cs 141 Exam 2 Review127 Who is this?

Cs 141 Exam 2 Review128  Steve Wozniak, co-founder of Apple Corporation

Cs 141 Exam 2 Review129  What does IBM stand for?

Cs 141 Exam 2 Review130  International Business Machines

Cs 141 Exam 2 Review131  Who is considered the founder of IBM?

Cs 141 Exam 2 Review132 Thomas J. Watson

Cs 141 Exam 2 Review133  Give me an example of function overloading?