CSCE 121 - Final Exam

¡Supera tus tareas y exámenes ahora con Quizwiz!

ch1:2 Why is software important?

-It is required to perform complex calculations, which are not possible to perform manually. -There are lots of software in communication which enables human beings to connect to remote areas. -It helps in performing repeated tasks effectively and efficiently. -It helps in controlling critical machines like airplane, medical devices etc.

ch1:5 Where does software play an important role? List some examples.

-Ship technology: software helps in designing, construction, engine maitnence etc. -Telecommunication: telecommunication satellites are used to switch the nearest network to connect the call when users dial a number -medical science: in surgery, various types of imaging techniques are used to perform the operations more successful

ch9:8 Why should the public interface to a class be as small as possible?

-can be learned easily -can be remembered easily -implementation doesn't require too much time -in case of error, it is easy to debug a small interface

ch8:21 What goes into an activation record?

-function definition -variable definition -function calling

ch5:13 Why is using exceptions a better idea than returning an "error value"?

-in error reporting both the called function and the callers must test for errors whereas in exception handling the testing is taken care of by the handlers -exceptions cannot be ignored, returned code can -errors have to be manually propagated up the call stack

ch8:6 Why is it a good idea to initialize variables as they are declared?

-it helps in reducing the debugging time b/c values are known to the programmer in the beginning itself -it reduces the num of lines required for declaring and initializing a variable separately -in large programs if a variable is not declared at the beginning and the programmer forgot to initialize it then it may give compile time errors or may contain garbage values which may produce unexpected results

ch8:11 What kinds of scope are there? Give an example of each.

-local: statements within a function or { } -global: defined at the top of the program and outside of a function. Scope is whole program -class: data members and functions that are defined within a class. can be used depending on the access -statement: variables defined in the statements (such as a while statement). The variables exist until the execution of the statement. -namespace: a scope with a name and is defined in the global scope or some other namespace. IT is used as extra info to separate similar functions, classes, variables, etc.

ch4:15 What are some common problems with switch-statements?

-logical operators and relational operators cannot be used e.g: case a>= 15: //doesn't work -only int and char type variables can be used -easier to read, but lots of bugs can occur -cannot use continue statements to send control to the beginning like loops can

ch3:20 What are some good rules for choosing names?

-must start with a letter -only contain letters, digits, and underscores -no spaces

ch5:4 List three approaches we can take to eliminate errors in programs and produce acceptable software.

-organize the software -eliminate errors -check for the remaining errors

ch8:10 What is the scope of a declaration?

-scope of local declarations: scope is inside a function -scope of global declarations: scope is whole program

ch4:28 What makes vector so popular/useful?

-size doesn't need to be provided in advance -vectors are growable in size -elements can be accessed randomly using indices

ch12:11 How do screen coordinates work? Window coordinates? Mathematical coordinates?

Screen/window: begin in top left corner and continue to the right for x and down for y. mathematical: begins in bottom right corner

ch13:3 What are the header files needed to use the graphics interface library?

GUI.h and Window.h

ch12:5 In which namespace do we keep our classes (our graphics library)

Graph-lib

ch4:14 When would a programmer prefer a switch-statement to an if-statement?

If there are multiple conditions, it is better to use a switch statement

ch3:16 What is an initialization and how does it differ from an assignment?

Initialization is the first value assigned to a variable, Assignment is used to assign a new value to a variable which already has some value.

ch3:22 Why can conversion from double to int be a bad thing?

It can lead to loss of data which can affect the output and can lead to a wrong result. e.g: double a=2.5; int b=a; // b=2 double c=b*2.0; //c=4, not 5 like the programmer prob. wanted

ch2:8 What does the linker do for your program?

It takes an object;file generated by compiler and object code from the standard library and then links these two object codes to generate executable file of program

ch12:15 How do you write text somewhere in a window?

Text te{Point{100,100}, "hello"}; win.attach(te); win.set_label("Canvas#4");

ch13:19 How do you label a Shape with a line of text?

Text(Point x1, const string& s1): lab{s}{ add(x1); } void set_label(const string& s1){ lab=s1;} string label() const { return lab;}

ch2:5 What is the purpose of the compiler?

The compiler takes a source-code file as input and checks for syntax error in it. If there was no syntax errors in the source code then the compiler generates object-code for that source code. If the compiler does detect any syntax errors then it shows error messages to the programmer for modification.

ch8:3 How do we syntactically distinguish between a variable declaration and a variable definition

The variable declaration only brings a name into the scope and it need not have the initializer while the definition is what brings the name into the program scope to complete initialization

ch3:18 Which of the following are legal names in c++? If a name is not legal, why not?

This_little_pig - legal latest thing - not legal (no spaces) MiniMineMine - legal This_1_is_fine - legal The_$12_method - not legal (no symbols) number - legal 2_For_1_special - (name must start w/ letter) _this_is_ok - not legal (same ^) correct? - not legal (no symbols)

ch5:6 What is a syntax error? Give five examples.

When the programmer doesn't follow the programming language. e.g: -incorrect keywords -missing semicolon -missing terminating character -wrong use of braces -incorrect function call

ch5:8 What is a linker error? Give three examples.

When the user calls the library function for some instructions in order to obtain the exact output of the program, but the function cannot be found in the built-in library. -when the function call uses a declaration, but the linker can't find a function definition -the function is not defined properly or if the name of the function is not displayed correctly it shows as a linker error. -when the library function is used and not declared or it's relevant header file is not included

ch4:4 What does an expression do?

computes a value from a number of operands. -names of variables are expressions -literals are too -parenthesis group expressions e.g: int I =20; is an expression

ch10:3 What, fundamentally, does an ostream do?

the type ostream is to deal with stream of output. that turns values of various type into character squences, and send those character to somewhare (such as to a console, a file, the main memory, or another computer).

ch10:2 What, fundamentally, does an istream do?

the type to deal with streams of input. the standard istream is called cin. an istream uses a buffer to communicate with the operating system. we can use istream through our keybord. until we hit enter, what we type is left in buffer. and we can use the backspace to erase what we typed.

ch13:13 What do you see if you define a Shape but don't attach it to a Window?

the window wont show anything

ch13:6 What do the arguments to Point indicate?

the x and y coordinates

ch5:15 Describe the process of how exceptions are thrown and caught.

throw-an exception is thrown whenever a problem occurs in the program catch-contains the code to handle the thrown exception try-the block where exceptions are found

ch2:6 What is the purpose of the #include directive?

to instruct the compiler to preprocess the information before starting the compilation of the program

ch8:23 What is the purpose of a namespace?

to overcome the complexity of differentiating two functions with the same name in the same class, used as extra info to separate similar functions, classes, variables etc.

ch4:29 How do you sort the elements of a vector?

using the sort() function to sort in ascending order

ch4:24 How do you write a for-loop that prints every element of a vector?

vector<int> v = {3,4,5,6}; cout << "The elements of the vector are: "; for(int i=0; i<v.size(); i++){ cout << v[i]; }

ch9:6 When should functions be put in the class definition, and when should they be defined outside the class? Why?

when a function is small it is better to put the function definition inside the class definition. If its large, put it outside.

ch5:7 What is a type error? Give five errors.

when the values to be stored are passed, and do not match the type, then there is an error. -wrong data type -unnecessary declaration of variables -invalid statement of assigning the values -wrong use of comma -missing data type

ch14:7 What is controlled by access control?

???

ch1:1 What is software?

A collection of programs or instructions running on the computer. It enables a user to interact with a computer and its hardware.

ch3:9 What is a literal?

A notation used to specify the type of value. They are used to differentiate one type of value from another.

ch14:6 How can you make a class abstract?

An abstract class is a class defined only to be used as a base class. It provides an interface to the derived class. To make it abstract you must add at least one pure virtual function.

ch8:12 What is the difference between a class scope and a local scope?

Class: area within a class. the variables declared can be used outside the class through an instantiation of the class depending on the access specifiers. static keyword can be used. Local: area within a function or block. Variables declared cannot be used outside the function. static keyword cannot be used.

ch13:4 What classes define closed shapes?

Closed_polyline, Polygon, Text, Rectangle, Circle, Ellipse

ch1:7 What's the difference between computer science and programming?

Computer Science: focuses more on formulating algorithm and theorizing (wide ranges of specializations are covered, e.g: architecture, engineering) Programming: Implementation and applications are more focused (only the programming part or writing code)

ch9:1 What are the two parts of a class, as described in the chapter?

Data members and member functions

ch14:11 What makes a class derived?

Derived classes are classes which inherits data members from different classes. it will be in the format: Class Derived_class : public Base_class {//data members};

ch3:21 What is type safety and why is it important?

Each object has a type when it is defined during its declaration. A program can be called type safe when objects are used as per the rules of their type. e.g: int a; int b=a; int c=10+b; not safe, b/c a wasn't initialized, and therefore the value of b and c becomes undefined.

ch4:5 What is the difference between a statement and an expression, as described in this chapter?

Expressions: return a value Statements: don't return anything An expression can be a statement, but a statement cannot be an expression.

ch12:16 How would you put a photo of your best friend in a window (using a program you wrote yourself)

Simple_window win(Point(100,100),8--,500,"my-friend"); Image img{Point(100,100),"bestfriend.jpg"}; win.attach(img);

ch12:10 How do you label a window?

Simple_window win{t1, 600.400."Canvas"} -label is "Canvas"

ch12:13 What command attaches a shape to a window?

Simple_window win{t1,800,500,"canvas"}; Polygon p; win.attach(p);

ch12:6 What header files do you need to do basic graphics using our graphics library?

Simple_window.h, Graph.h, Window.h

ch2:9 What is the difference between a source file and an object file?

Source file: a simple text file that is created with a code editor and that contains the actual code (.cpp) Object file: a binary file generated by the compiler or interpreter (.obj) -source files are compiled into object files

ch3:14 What is the difference between = and ==?

Stores data in memory, and gives the programmer a way to access it. Types: cahr, int, floar/double, string

ch13:14 How does a Rectangle differ from a Polygon with four Points (corners)?

a polygon can be any four sided figure which could mean a diamond which is not a rectangle

ch13:12 How many sides does a Closed_polyline defined by five Points have?

a polygon with 4 or more sides

ch9:5 What is an invariant? Give examples.

a rule that defines the condition for a variable to be valid

ch3:15 What is a definition?

a statement which is used to store data into a variable. e.g: int num=89;

ch12:4 What is a window?

a two-dimensional rectangular display screen

ch14:5 How does an abstract class differ from a class that is not abstract?

abstract: does not allow instantiate objects, contains at least one pure virtual function. declared for generalization. concrete: allows instantiate objects. does not contain pure virtual function. declared for derivation

ch4:26 Describe what push_back() does to a vector.

adds elements to the end of a vector. e.g: v.push_back(2) //adds 2 to the end of the v vector

ch14:10 What is a base class?

an entity which allows another class to derive and exhibit its behavior by allowing the access to data functions

ch5:9 What is a logic error? Give three examples.

an error that occurs in the program but instead of displaying an error the program outputs the wrong results. -when the loop is used in a program, and it is not terminated properly for(i=0; i<10;){cout << i;} // infinite loop -the condition or expression in the control statements doesn't display properly if(k=1){....} // wrong if(k==1){....} //right -the defined function is used to calculate the arithmetic expression but the results are wrong int sum(int a, int b){return a+b/3;} // should be (a+b)/3

ch8:13 Why should a programmer minimize the number of global variables?

b/c the variable can be changed by any function that is called, and there is no easy way for the programmer to know that this will happen

ch9:10 Why are "helper functions" best placed outside the class definition?

b/c these functions use the class's data members and its objects for various functions

ch5:16 Why, with a vector called v, is v[v.size()] a range error? What would be the result of calling this?

bc of how vectors are numbered

ch8:24 How does a namespace differ from a class?

classes define types. you can create an object of a type. namespaces declare a scope inside which other types, functions, or namespaces can exist. you cannot create an object of type namespace.

ch13:11 What properties can you set for every shape?

color and style

ch5:1 Name four major types of errors and briefly define each one.

compile-time: errors found during compilation (main errors) -syntax errors -type errors link-time: errors from the linker combining object files to generate an executable file run-time: after the linker successfully generates an executable file, these errors occur during run time (main errors) logic: errors from the output

ch8:2 How do we syntactically distinguish between a function declaration and a function definition?

declaration Function_type function_name (parameter1, parameter2); int sum(int a, int b); definition Function_type function_name (parameter1, parameter2){ stuff;} int sum(int a, int b){ cout << a+b; }

ch8:1 What is the difference between a declaration and a definition?

declaration: provides the basic info about the function definition: provides all of the details of that symbol, or if it is a variable then where it is stored.

ch14:8 What good can it do to make a data member private?

defining the data and functions under private access modifier enables the security of the created code of the base classes

ch13:8 What are the components of Color?

enum color_type for: red, blue, green, yellow, white, black, magenta, cyan, dark_red, dark_green, dark_yellow, dark_blue, dark_magenta, dark_cyan

ch13:7 What are the components of Line_style?

enum for: solid, dash, dot, dashdot, dashdotdot

ch4:17 When should the for-loop be used and when should the while-loop be used?

for loops are used when the number of times it needs to be executed is already known before-hand. While loops execute until the condition doesn't hold true anymore, The range is known to the user, but not the number of iterations.

ch4:16 What is the function of each part of the header line in a for-loop, and in what sequence are they executed?

for(initialization, condition, operation) 1. initialization, 2. check condition, 3. execute body, 4. increment operation

ch10:9 Name and define the four stream states.

good(), eof(), fail(), bad()

ch13:15 How does a Polygon differ from a Closed_polyline?

in closed_polyline no two lines can intersect each other, but there are no restrictions in polygon

ch9:2 What is the difference between the interface and the implementation in a class?

interface: the part of a class declaration that users can access directly. Public label is used to identify an interface inside the class. implementation: the part of a class declaration that users can only access indirectly through the interface. private label is used to identify an implementation inside the class.

ch2:7 What does the .h suffix at the end of a file name signify in c++?

it signifies that .h is an extension for a header file

ch13:5 Why don't we just use line for every shape?

it would be too complex to keep track of points to be connected. drawing curves on circles or ellipses would be nearly impossible

ch8:22 What is a call stack and why do we need one?

like a stack of data structure that stores the return address

ch12:12 What are examples of simple "shapes" that we can display?

line, lines, polygon, axis, rectangle, text, images

ch2:3 Name a function that must appear in every c++ program

main()

ch13:18 How do you move a Shape to another place in a Window?

must use the move function

ch12:14 Which basic shape would you use to draw a hexagon?

the Polygon shape

ch9:9 What does adding const to a member function do?

the function becomes constant, and thus they do not modify any objects

ch8:15 What is the difference between pass-by-reference and pass-by-const-reference?

pass-by-reference: used in situations where original variable needs to be modified pass-by-const-reference: used in situations where original variable must not be modified

ch8:14 What is the difference between pass-by-value and pass-by-reference?

pass-by-value: passes a copy of the variable. useful for small valued variables such as int, char, double. changes are not reflected in the original value of the variable.argument list is initialized with the copy of the original variable. pass-by-reference: passes a reference of the variable. useful for any type of variable such as user defined types. changes are reflected in the original variable. argument list is initialized with the address of the original variable.

ch14:9 What is a virtual function and how does it differ from a non-virtual function?

the member function that is expected to be defined again inside the derived classes. virtual functions are resolved at run-time, non-virtual are resolved at compile time. virtual function is expected to be overridden by derived class to implement polymorphism

ch3:8 What is an object?

the occupied region or place in memory that is used to store the data. They are type specific.

ch2:4 In the "Hello, World!" program, what is the purpose of the line return 0?

the statement indicates that the program terminated successfully

ch5:17 Define pre-condition and post-condition; give an example (that is not the area() function from this chapter), preferably a computation that requires a loop.

pre-condition: the set of conditions must be true before the function is called post-condition: the set of conditions must be true after the function has finished its work

ch4:27 What does vector's member size() do?

returns the size of the vector e.g: v.size(); //returns 5 (based on past two cards)

ch1:4 What could go wrong if some software fails?

software failure can be disastrous. It may cause loss of billions of dollars and even may cause loss of life. ex. -software is present in care fuel injection system, if the software fails this may lead to abnormal fuel injection or no fuel injection at all in which case the whole car will be halted.

ch13:20 What properties can you set for a text string in a Text?

text font size and text font

ch13:21 What is a font and why do we care?

text property which tells the style of the text


Conjuntos de estudio relacionados

Chapter 25: Drugs for Muscle Spasm and Spasticity

View Set

II Lecture Chapter 17 Short Answer: Nasal Surgery pp 381

View Set

PrepU Videbeck Ch 20 Eating Disorders

View Set

Chapter 10 - Business Ethics, Social Responsibility, and Environmental Sustainability

View Set

Nursing Application for Fluids and Electrolytes

View Set

chapter 5 : membrane potentials and action potentials

View Set

ACCY 501 Test 2: Internal Audit Flint

View Set

Module #4 Finance Test Questions

View Set