FINAL EXAM - CS 121 (UAH, Professor Richard Coleman)

Ace your homework & exams now with Quizwiz!

Define the following term: extraction operator

(>>) inputs data from a keyboard or file

Be able to write simple code demonstrating the use of a while loop in a count-controlled loop.

// Count controlled loop #include<iostream> using namespace std; int main() { int loopCount; // loop control variable loopCount = 1; while(loopCount <= 10) { cout << "Hello! Loop count = " << loopCount << endl; loopCount++; // Increment control variable } return 0; }

Be able to write simple code demonstrating the use of a while loop in an end-of-file-controlled loop.

// EOF controlled loop #include<iostream> #include<fstream> using namespace std; int main() { ifstream inData; int intValue; inData.open("myData.txt"); if(!inData.good() { cout << "Failed to open myData.txt. Program terminating.\n"; return 0 } while(!inData.EOF()) { inData >> intValue; cout << "Got value: " << intValue << endl; } inData.close(); return 0; }

Be able to write simple code demonstrating the use of a while loop in a sentinal-controlled loop.

// Sentinel-controlled loop #include<iostream> using namespace std; int main() { char inChar; // Input variable cin.get(inChar); // Init sentinel variable while(inChar != '\n') { cout << inChar; // Print the character cin.get(inChar); // Get the next character } cout << endl; return 0; }

Be able to write simple code demonstrating the use of cin to input string values.

//prompt user for input cout << "Enter month, day, and year in integer form." << endl; cin >> month; cin >> day; cin >> year; cout >> "Date is " >> month >> " / " >> day >> " / " >> year >>

What are the three phases of problem solving and the steps under each phase?

1) Analysis and specification: understand (define) the problem and what the solution must do 2) General solution (algorithm): develop a logical sequence of steps that solves the problem. 3) Verify: follow the steps exactly to see if the solution really does solve the problem

List seven problem solving techniques used in computer program design.

1) Ask questions 2) Look for things that are familiar 3) Solve by analogy 4) Means-ends analysis 5) Divide and conquer 6) Building-block approach 7) Merging solutions

List and briefly define the three elements of the C++ language.

1) Syntax and semantics: defining the syntax or grammar of the language, and the semantics or meaning of commands in the language. 2) Symbols: defining certain operations, like the math operations of addition, subtraction, etc. 3) Reserve words: words that have a specifically defined meaning in a command.

What are the three real data types in C++?

1) float 2) double 3) long

What are the 5 integer data types in C++?

1) int 2) double 3) long 4) short 5) float

What are the six basic components of a computer?

1) the memory unit 2) the arithmetic/logic unit 3) the control unit 4) input devices 5) output devices 6) auxiliary storage devices

What header file must you #include if you are going to use file input or output in your program?

<fstream>

What header file do you have to #include in a program to use the cout command?

<iostream>

What is meant by the "dangling else" error and how do you ensure it does not occur.

A "dangling else" error occurs when an else statement is not paired with a beginning if condition and the else block of code will not execute. An else statement is always paired with the closest if statement unless braces are used to modify this.

In functional decomposition what is the difference between a Concrete Step and an Abstract Step?

A concrete step is a step for which the implementation details are fully specified, however, an abstract step is a step for which some implementation details remain unspecified

What is an auxiliary storage device? AND Give three examples.

A device that stores data in encoded form outside the computer's main memory. EXAMPLES: 1) USB 2) Hard Disk Drives 3) CDs

Define the following term: assembly language

A low-level programming language in which a mnemonic is used to represent each of the machine language instructions for a partoicular computer.

Define the following terms: functional decomposition

A technique for developing software in which the problem is divided into more easily handled subproblems, the solutions of which create a solution to the overall problem.

What are the 5 basic math operators (symbols) used in C++ for addition, subtraction, multiplication, division, and modulus division?

Addition : + Subtraction : - Multiplication : * Division : / Modulus : %

Define mixed type expression:

An expression involving more than one data type. Usually used in the context of combing integer and floating point types in numeric computations.

What is a peripheral device? AND Give three examples.

An input, output, or auxiliary storage device attached to a computer. EXAMPLES: 1) Monitor 2) Mouse 3) Keyboard

Show how to concatenate strings with the + operator.

BookTitle = phrase 1 + phrase 2

Define the following term: hardware

CPU and all perihperal devices that attach to the CPU

What operators are used to enclose a block of code in a C++ program?

Curly brackets ( { } )

Show how you would count to 15 in binary numbers.

DECIMAL - BINARY 1 - 0001 2 - 0010 3 - 0011 4 - 0100 5 - 0101 6 - 0110 7 - 0111 8 - 1000 9 - 1001 10 - 1010 11 - 1011 12 - 1100 13 - 1101 14 - 1110 15 - 1111

Show how you would count to 15 in hexadecimal numbers.

DECIMAL - HEXA 1 - 1 2 - 2 3 - 3 4 - 4 5 - 5 6 - 6 7 - 7 8 - 8 9 - 9 10 - A 11 - B 12 - C 13 - D 14 - F 15 - G

Given two integer variables (int x=33 and int y=2), what is the answer to the following two formulas: z = x / y; z = z % y;

Formula #1) 16 Formula #2) 0

Is the string a C++ data type? Why or why not?

If strings are a data type in the sense of basic or atomic data types, then no, strings are not a data type. The string object is a part of a special C++ library known as the Standard Template Library

What is the difference between Syntax and Semantics?

If you violate any of the syntax rules your program won't compile. If you violate any of the semantics rules your program may compile and run, but it won't run correctly.

What does the #include preprocessor directive do?

Includes header files for other libraries, classes, interfaces, etc.

What do each of the following operators mean? &&, ||, !. Demonstrate how to use each in a compound condition statement.

OPERATOR : MEANING && : logical AND operator if(condition1 && condition2) || : logical OR operator if(condition1 || condition2) ! : logical NOT operator if(!(condition1 == condition2))

Demonstrate how to use each in a condition statement.

OPERATOR : MEANING == : equals operator != : does not equal operator < : less than operator > : greater than operator <= : less than or equal to operator >= : greater than or equal to operator

What does the following format specifier do when used in a cout statement to print numeric data: setprecision

Sets the decimal precision to be used to format floating-point values on output operations

What does the following format specifier do when used in a cout statement to print numeric data: showpoint

Sets the showpoint flag for the str stream

What is the difference between a signed and an unsigned integer type variable?

Signed variables will allow you to represent numbers both in the positive and negative ranges. Unsigned variables will only to represent numbers in the positive range

What function is used to print to the screen. Demonstrate its use.

The "cout" function cout << "statement" << endl;

Briefly describe what the computer's memory is and how it is organized? Include comments on RAM, ROM, bits and bytes.

The computer's memory is divided up into two sections: ROM or Read Only Memory and RAM or Random Access Memory. Both RAM and ROM are made up of many thousands or millions (and soon to be billions) of units called Bytes. Each byte consists of eight bits. Each bit is like a simple on/off switch. With eight switches, you can have up to 256 different combinations of on and off. This is the way data is encoded on the computer.

What is the insertion operator and what is it used for?

The insertion operator (>>) is used to display information on the console.

What is meant by "short-circuit" evaluations of compound conditional statements.

The operation x && y corresponds to the operation x & y, except that if x is false, y is not evaluated, because the result of the AND operation is false no matter what the value of y is. This is known as "short-circuit" evaluation.

Define the following term: object-oriented design

The process of identifying classes of objects and their interrelationships that are needed to solve a software problem.

Define the following term: bottom-down design

The process of program design in which the problem is defined in terms of low level simple objects that interact in some way. Design progresses from the simple objects and how they interact upward to more complex interactions. Also called object oriented programming. Focus is on the data objects in the software system.

What is a "conditional expression"?

The syntax of a conditional expression is as follows: (condition) ? expression1 : expression 2. It can often replace a simple "if-else" statement.

What does precedence mean in C++ math formulas? What is the order of precedence of the basic math operators?

There is an order of operations in C++ as well 1) Multiplication 2) Division 3) Remainder 4) Multiplication 5) Addition 6) Subtraction 7) Assignment

What is meant by type coercion and type casting?

Type casting: The implicit (automatic) conversion of a value from one data type to another Type coercion: The explicit (intentional) conversion of a value from one data type to another

Be able to write simple code demonstrating the use of cin to input character values using both the extraction operator and the cin.get() function.

WITH CIN: cout << "Enter a character:" << endl; cin >> ch; cout << "ch=" << ch << endl; WITH CIN.GET(): cout << "Enter three characters" << endl; cin.get(ch1); cin.get(ch2); cin.get(ch3); cout << "ch1 = " << ch1 << "ch2 = " << ch2 << "ch3 " << ch3; return 0;

What is the ASCII code?

a code for representing English characters as numbers, with each letter assigned a number from 0 to 127

Define the following term: standard input device

a device that retrieves input from the user, typically a keyboard

Define the following term: source file

a file that contains a program's source code; source files have a .cpp filename extension

Define the following term: object file

a file that contains the object code associated with a program; automatically generated by the compiler

Define the following term: I/O Redirection

a form of interprocess communication, and is a function common to most command-line interpreters

Define the following terms: programming language

a formal computer language designed to communicate instructions to a machine

What is a function in a C++ program?

a group of statements that perform a task together

What is a constant in a C++ program:

a location in memory, referenced by an identifier, that contains a data value that cannot be changed

What is pseudocode?

a mixture of English statements and C++-like control structures that can be translated easily into C++

Define the following term: assembler

a program that translates assembly language into machine code

Define the following term: algorithm

a step-by-step procedure for solving a problem in a finite amount of time

What is a variable? Show how to create variables for each of the C++ data types and set values in those variables.

a variable is a location in memory where we can store data values int = 5 double = 3.14159 long = 3.14159 float = 3.14 bool = true

If an input stream enters the FAILED state what happens to subsequent input?

all subsequent inputs are ignored

Define the following term: top-down design

an approach to structured programming which involves working from the larger problem down to the details (Top Down Design) by expanding the steps in an algorithm to add more detail at each step (Stepwise refinement)

Define the following term: iteration

an individual pass through, or repetition of the body of a loop

Define unary operator:

an operator that takes a single operand in an expression or a statement

Define the following term: machine language

another name for binary/what the computer understands

What is a literal value in a C++ program?

any number that cannot be modified by a program, but may be copied into a variable for further use.

Define the following term: software

any program that is stored in RAM or ROM and is executable by the microprocessor

Define the following term: stepwise refinement

by expanding the steps in an algorithm to add more detail at each step

What does cin.ignore() do. Be able to demonstrate its use.

cin.ignore() ignores input up to the newline unless otherwise specified //prompt user for input, accept first value cout << "Enter 3 integers on each line" << endl; cin >> i; cin.ignore(100, '\n'); cin >> j; cin.ignore(100, '\n'); cin >> k; cin.ignore(100, '\n');

Show how to create a constant called PI and set its' value to 3.141592.

const double PI = 3.141592

Be able to write simple code demonstrating the use of cin to input integer or floating point number values.

cout << "Enter a integer and a decimal" << endl; cin >> x >> d; cout << "x=" << x << "d=" << d << endl;

In object oriented design what is an Object?

entities consisting of data and operations on the data

What does the following format specifier do when used in a cout statement to print numeric data: fixed

force all subsequent number output to be in decimal notation instead of scientific notation

What does the following format specifier do when used in a cout statement to print numeric data: scientific

force all subsequent number output to be in scientific notation instead of decimal notation

What is an identifier in a C++ program and what are the rules for naming identifiers?

identifiers are the names we give things in our program. The identifier must begin with a letter, upper or lower case, and may consist of any number of letters or numbers plus the underscore character. The identifier may not be any of the reserved words in the C++ language, and may not contain any spaces.

Be able to write simple code demonstrating the use of the if statement to test the condition of some integer variable.

if (average >= 60) { cout << "Passing but marginal"; } else cout << "Failing";

Be able to write simple code demonstrating the use of the if..else statements to test the condition of some integer variable.

if (average >= 60) { if else (average < 70) { cout << "Passing but marginal"; } { else cout << "Failing"; }

Be able to write simple code demonstrating the use of nested if statements, i.e. if...else if ... else.

if (x < y) cout << "x is less than y" << endl; else if (x == y) cout << "x is equal to y" << endl; else cout << "x is greater than y" << endl;

What is the data type for an input file stream object?

ifstream

Be able to write simple code demonstrating the use of cin to input string values using the getline() function.

int main() { string s1; cout << "Enter a string" >> endl; getline(cin, s1); cout << "s=" << s1 << endl; return 0; }

What is an escape code? What do the following escape codes do in a string: \n, \t, \\, \", \x064

invokes an alternative interpretation on subsequent characters in a character sequence \n : new line \t : insert tab space \\ : insert backslash \" : insert double quote /x064 : prints the ASCII code @

Convert the following into a simple conditional expression: if(a > b) max = a; else max = b;

max = (a > b) ? a : b

Define the following term: central processing unit (CPU)

microprocessor mounted on the motherboard

What is the data type for an output file stream object?

ofstream

Be able to demonstrate the use of the open function in a file object.

ofstream outfile; // Declare an ofstream reference outfile = open("myfile.txt", ofstream::out); outfile = open("myfile.txt", ios::out); outfile = open("myfile.txt");

Define Binary operator:

operates on two operands and manipulates them to return a result

What is the operating system?

provides an interface between an application program and the computer hardware

What does the following format specifier do when used in a cout statement to print numeric data: setw

set the field width of the next item output

What is software piracy and why is it an important concern for professional software engineers?

software piracy is the unauthorized copying of software for either personal use or use by others. Computing professionals have an ethical obligation to not engage in software piracy and to try to stop it from occurring.

Show how to create a string variable and store a string value in it.

string BookTitle = "The Legend of Zelda";

Be able to write simple code demonstrating inputing string values from a file using the getline() function.

string s1; cout << "Enter a string" >> endl; getline(cin, s1); cout << "s=" << s1 << endl; return 0;

If a numeric value is printed and it has an E or e imbedded in the string of numbers, what does this mean?

that the output is in scientific notation

What is wrong with the following if statement: if(n = 3) cout << "n equals 3" << endl;

the "if" condition does not contain the "equals" logical operator, but the assignment operator. Thus, n will be set equal to 3.

Define the following term: termination condition

the condition that causes a loop to be exited

Define the following term: loop exit

the point at which the While expression is evaluated and the decision is made either to begin a new iteration or to skip to the statement immediately following the loop.

Define the following term: loop test

the point at which the condition is tested to determine if a new iteration will be started or the loop will end

Define the following term: Loop Entry

the point at which the flow of control reaches the first statement inside a loop

Define the following term: computer science

the scientific and logical approach to computations

What is the primary purpose of Computer Science?

to solve problems

Define the following term: complier

translates high level languages into assembly

What are all of the values a bool data type can hold?

true / false

Define the following terms: programmming

writing a list of instructions that tells the computer how to solve a problem

What is the difference between the decrement and increment operators as used in the following: X--, --X, Y++, ++Y.

x-- : post-decrement --x : pre-decrement y++ : post-increment ++y : pre-increment


Related study sets

Exponential Functions + Basic Log

View Set

A&P 2: Chapter 19 The Lymphatic System and Immunity

View Set

(Complete) Chapter 03: The Accounting Cycle: End of the Period

View Set