CS 14228 Final Exam

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the output of the following

First Loop and Second Loop Displays employee 1 employee 2 employee 3 employee 4 employee 5 Third Loop Displays employee 1 shows shows infinitely

What is a do while loop

a 'post-test' loop executes at least once Use when the code in the loop must be executed at least one time Test a condition at the bottom

What is a while loop

a 'pre-test' Executes zero or more times use when number of repitions is NOT known in advance Test a condition at the 'top' to determine whether or not to continue loop General form is while (logical expression include input validation for interactive programs that use while loops A while loop can also be sentinel or end-of-file controlled

What are constants

constant values that are assigned to variables; values that aren't meant to change during the program's execution; however, since they are stored in normal variables, the could be accidentally be changed; therefore it is better to store these values in constant variables Named constants - named constants or constant variables must be initialized when defined; cannot accidentally be changed during program execution Identifiers - programmer-defined names of things that appear in programs such as variables, constants (literals), and function

What is a function definition?

contained the function header line and the statements that make up the function

What is the software life cycle

Stage 1 - Problem Analysis and Specification Stage 2 - Design Stage 3 - Coding Stage 4 - verification and validation stage 5 - maintenance stage 6 - obsolence

What is string data type

String library #include <string> Variable declaration General format string variable_name; Input, output, and assignment of strings work just like numeric types

How do you initilize all elemnts in an array to 0 with a loop

for (int i = 0; i < SIZE; ++i) scores[i] = 0;

How do you read data into an array

for (int i = 0; i < SIZE; ++i) { Cout << "Enter a value: "; cin >> score[i]; }

What is an assignment statement

general form is variable = expression

What are the decision making or selection control constructs

if if-else if-else if-else if-else... switch

What does a nested do-while loop look like

int main ( ) { char again; double sum = 0.0; double price; Do { Cout << "Enter the price of the item purchases: " Cin >> price; Sum = sum + price; Do { Cout << endl << "More Items? ( Enter y for yes or n for no)"; Cin >> again; } while (again != 'y' && again != 'Y' && again != 'n; && again != 'N'); } while (again == 'y' II again == 'Y'); Cout << endl << "The total of all purchases is " << sum; Return 0; }

What does a user controlled loop look like

int no_purchases Cout << "How many items did you buy? "; Cin >> no_purchases For (int 1 = 1; i <= no_purchases; ++i) Cout << "item " << i << endl;

Do the variable names of the actual arguement need to match the names of the variables dummy arguements

no, they are just given value in order of appearance call is printLarge (num1, num2); header is void printLarge (double num2, double num1) although confusing, the variable num2 that is in the function will actually be assigned the value from num1 in int main and vice versa

What is Java

object-orientated language developed at Sun Microsystems used to develop programs that run over the internet in a web browser

What does declaring a loop index variable in the for loop's initilization expression mean

only exists within loop if declared in loop

What pass can alter storage in int main and uses an &

pass by reference AKA pass by address

What pass can get a copy of the arguement from int main but cannot change the value of it in int main, only changes the value within the function

pass by value

What is short-circuit evaluation

refers to the condition where an expression is no longer evaluated because additional evaluation will change the value of said expression

What are the parts of all function definitions

return type function name parameter list (can be empty) body (enclosed in curly braces)

What is a variable definition

there are two basic types of data: numbers & characters; you must 'define' variables and what type of data the variables will hold

What is an array declaration and how is an array numbered

type array_name [SIZE] numbered from 0 to SIZE -1

What type of functions return one value to the calling routine vie a return statement?

typed function Library functions such as sqrt ( ), pow ( ), & abs ( ) all return a single value of a particular data type. The main function returns a value.

What is stream extraction operator

used for input from the keyboard of from a file >> Cin - read from the keyboard

what is a stream insertion operator

used for output to the screen or file << Cout fout

What is a sentinel while loop

value while (read) loop general form read initial value while value read is not sentinel value process the value read next value end while loop

What is a parameter or dummy arguement

variable declared in the function header line that receives an actual arguement passed to the function from the calling routine

What type of function does something but return nothing or returns multiple values to the calling routine?

void function

What is the definition of a void function with an empty parameter list?

void printColumnHeaders ( ) { Cout << "Name Hours Worked Hourly Rate";

What is a variable initilization

when a value is assigned to a variable as part of the variable's definition

What loop would work best for the following situation: A ball is dropped from a starting height. Each time the ball bounces, it returns to half the height from which it started. For a user-specified starting height (in inches), how many bounces will it take before the ball bounces to less than 1 inch in height?

while loop

How are arguements passed by position?

within the paramter

What are the expressions precedence rule

() parentheses Unary minus * / % (evaluate left to right) + - (evaluate left to right)

What is a function protype

(or function declaration) is the declaration of a function. Just as variables are declared before they are used, functions should be prototyped (declared) before they are called. Using a function prototype eliminates the need to place a function definition before all calls to a function.

What is shorthand operators

+= -= *= /= %= make sure to initialize anything that uses a shorthand operator

What are the assignment operators

= Assignment statement When the value is assigned to a variable as part of the variable's definition, it is called initialization

What are the language translators?

Assembler - software that translates assembly language code to binary machine language instructions before it is executed by a computer Interpreter - software that translates one statement at a time of a program written in a high-level language into a sequence of machine actions and executes the statement immediately before going on to translate the next statement Compiler - software that translates a program written in a high-level language into binary machine language instructions so that the program can be executed by a computer. The compiler searches along the way for syntax (grammar) errors in the program

What is CPU? ROM? ALU? Control Unit? Main Memory/Core Memory? (RAM) Auxiliary Memory? Input/Output devices

CPU - Central Processing Unit - Controls the computer and how it works. in consists of two basic parts: the ALU and the Control Unit ROM - read only memory is found in the CPU ALU - Arithmetic and Logic Unit - addition, subtraction, multiplication, division, comparisons Control Unit - controls the intruction cycle of the program - Fetch, update, decode, execute Main Memory - Core Memory - RAM - Random Access Memory - RAM is fast and expensive and provides more power Main memory is discrete and volatile in that is it easily lost when the computer is turned off and the information has not been saved Auxililiary Memory - floppy disks, hard drives, CD, DVD< flash drives, etc Input device - keyboard, mouse, scanner, light pens, optical mark readers, voice recognizers, etc output devices - monitors, printer, speaker, etc

What are the repitition/loops control constructs

Count for loops While Loops Do While loops

What are the steps for file input/output

Declare the file variables ifstream infile; ofstream outfile; Open the files infile.open ("prog0.inp") outfile.open ("prog0.out) You should use the full path to the file being opened. You must either use a forward slash or two backslashes in the path to the file (or have them saved in the same location on the computer) Read from or write to files infile >> score; outfile << average; Close the files infile.close ( ); outfile.close ( );

What is a program that returns a single bool value look like?

Function Prototype bool isOdd (int); Function Call if (isOdd(x))... Function Definition bool isOdd (int number) { bool result; if(number%2==0) result=false; else result=true; return result; }

What is a program that calculates the average of two integers and the function returns the single value

Function Prototype double averageValues (int total, int count); Note -Recall that including the names for parameters (dummy arguments) in the prototype is not necessary; however, when multiple arguments are sent, listing the names in the prototype helps indicate the order in which the arguments were listed Function Call avg=averageValues (total, count); Function Definition double avgerageValues (int total, int count) { double avg; avg = static_cast<double>(total)/count; return avg; }

What is a program that has a function that returns a value read from a file

Function Prototype double getADouble (ifstream & ); Function Call Real_number = getADouble (fin) Function Definition double getADouble (ifstream &fin) { Double value; Fin >> value; Return value; }

What is a program that has a function return a single value entered by a user?

Function Prototype double getADouble(); Function call Real_number = getADouble(); Function definition double getADouble { Double value; Cout << "Enter a real number"; Cin >> value; Return value;

What is an example of defining user defined function that return a single value

Function Prototype int sum (int, int); Function Call to a function that returns a single value Just like with the predefined math functions discussed previously, functions that return a single value are usually called as a part og an assignment statement total = sum (a, b); Function Definition int sum (int num1, int num2) { int result; result = num1+num2; return result; }

What is an end-of-file controlled while loop

General form - while ( !fin.eof( ) ) the eof ( ) function has been known to be persnickety under certain circustances there is an alternative approach General form - while ( fin >> exam_score )

What is part of a computer's hardware? a computer's software?

Hardware CPU RAM Secondary storage devices input devices output devices Software operating system applications programs

How do you check to see if input/output files opened

If (!infile) Message about termination Return 1; If (!outfile) Message about termination Return 1;

What are the simple data types?

Int - whole numbers Float (single precision), double (double precision), long double - real number Char (primarily used for storing characters but actually an integer data type, usually 8 bits Bool (set to either true or false Integer data types, sizes, and ranges

What are the expression types

Integer division (be careful) Int 5 / int 2 would be 2 no decimals no left-overs Pure expression (all values of a single type) Mixed expression The presence of a real makes everything real Type coercion to a pure expression Data type rankings (in descending order) Double Float Int In a mixed expression, the lower-ranked type is converted to the higher ranking type Overflow and underflow Each numeric data type has a max and min value when you take max + 1 you get min, when you min - 1 you get max It's all a big circle

What is an example of a program using the function printLarger with 2 parameters

Note: Recall that the variable names of the actual arguments do not need to match the variable names of the parameters or dummy arguments.

What is an example of using the function printValue with one parameter

Note: The variable name of the actual argument does not need to match the variable name of the parameter or dummy argument.

What is memory organization

Random Access Memory (RAM) Each byte has a unique address High order bit/low order bit How many unique addresses are there is each address in primary memory is a 10-bit address 2 to power 10 or 1024 unique addresses

What are the sequential control constructs

Read Write Assignment

How do you pass data to a function

Recall math functions previously examined (sqrt, pow, abs). x = sqrt ( a ); y = abs ( b ); z = pow ( 4.0, 3.0 ); the variables a and b and the literals 4.0 and 3.0 in the examples above are arguments passed to the functions. Arguments are the information needed by the function to do its job. (We will refer to these as the actual arguments.)

What are the three types of control constructs

Sequential Decision making or selection repetition/loops

What is setw? setprecision? fixed? showpoint? What library is used for these?

Setw - used for lining up columns of data; reserves a specified number of spaces for printing a value Setfill - when used with setw can be used to fill a designated field with specific characters setprecision, fixed, and showpoint manipulators Setprecision specifies the number of decimal places to be displayed Can be used to control the number of significant digits or precision with which floating-point values are displayed Values are rounded to a specified decimal place Fixed manipulator forces the digits to be printed in fixed-point notation, or decimal notation instead of in scientific notation Showpoint manipulator By default, floating-point numbers are not displayed with trailing zeros, and those without a fractional part are not displayed with a decimal point To display numbers padded with zeros, the showpoint manipulator can be used Most compilers display trailing zeros when the setprecision and fixed manipulators are used together without showpoint Setprecision, fixed, and showpoint remain in effect for all floating-point values until a new setprecision is used For floating-point value output, setw, fixed, showpoint, and setprecision are used together iomanip library

How do you pass a file variable to a function

To allow a function to write to a file or read from a file, it is not enough to simply pass a file variable to the function. An additional character, the ampersand (&), is needed when declaring the file variable parameter in the function prototype and function header line. The reasoning behind including this extra character is left for a future discussion.

What is typecasting

To avoid the implicit type coercion, you can use the cast operator. The cast operator, also known as type conversion to type casting, takes the following form Static_cast<new DataTypeName> (expression reduced to a value to be converted Expression is evaluated first then the value is converted

What are the matmatical operators

Unary operators - (negation) ex -5 Binary operators + addition - subtraction * multiplication / division (WARNING INTEGER DIVISION) % modulus operator (returns the remainder after integer division No exponentiation operator Relational operators <= less than or equal to == equal to >= greater than or equal to != not equal to < less than > greater than Stream insertion operator - used for output to the screen or to a file << Cout is to output to the screen Endl is an output manipular by simulating hitting the return key on the keyboard Stream Extraction operator - used for input from the keyboard or from a file >> Cin - used to read from the keyboard

What is a switch

Used for selecting one of several possible integer or integer compatible values when there is a small number of cases to check Break statements mark the end of if the above is true execute until you reach a break, then skip the rest

Which allows access to memory? Pass by reference or pass by value?

When an actual argument is passed to a function by reference (or address), access is provided to memory. If the function changes the value of the parameter or dummy argument, this does affect the value of the actual argument.

How are arguements passed by value?

When an actual argument is passed to a parameter or dummy argument, a copy of the value of the argument is passed. If the function changes the value of the parameter or dummy argument, this does not affect the value of the actual argument.

What are user-defined function that receive data

Writing and calling a function printValue that receives an integer value and prints that integer value to the screen:

Will for (;;) run?

Yes, but Becky doesnt like it

What is a count (for) loop

a 'pre-test' loop use when number of repitions is known in advance General form For ( Initialize loop index variable; Test logical expression; Increment or decrement ) Do not modify the loop index variable inside the loop. The result is not predictable

What is input validation?

a process of checking the validity of input data Check numbers to ensure they are within a range of possible values Check values their 'reasonableness' Check items selected from a menu or other sets of choices to ensure they are available options Check variables for values that might cause problems, such as division by 0

What is Visual Basic

a software development environment by Microsoft that allows programmers to create windows-based applications

What is C++

a spin-off of the C language also developed at Bell Labs that offers object-orientated features not found in C; portable

What is a function call?

a statement that causes a function to be executed

What is an algorithm? What are the expressions?

a step by step ordered procedure that solves a problem in a finite number of precise steps Expressions Top-down design (hierarchy chart) - start with the overall task, then break down into progressively smaller tasks (Divide and Conquer) Natural language (English-like statements) Flowchart - a diagram that shows the logical flow of a program Pseudocode - a cross between natural language and a programming language Programming Language language translators

What is a C

a structured language developed at Bell Laboratories that allows low-level programming while using a high-level language

What are variables

a symbolic name represents a location in the computer's random-access memory (RAM) used to hold a piece of information, information that may change while the program is running; variable names should be self-documenting (clearly reflecting their purpose) should be self-documenting

What is main

a typed function that returns as an integer value

What data type holds multiple values

a vector

What is using namespace std

declares that a program that will be accessing entities whose names are part of the namespace called std

What is the COBOL

designed for business applications

What is the FORTRAN

designed in the late 1950s to meet the needs of the scientific and engineering communities

What does a do while look for when used for error trapping

do { Cout << "Enter an integer between 1 and 10: "; Cin >> number; } while (number < 1 II number > 10);

What loop would also work best for the following situation: Solve the payroll problem where the input file contains an unknown number of employee records. While the employee ID#, rate of pay, and number of hours worked can be read from the file, print to an output file the employee ID# and the amount earned in table form

end-of-file controlled while loop

What loop would work best for the following situation: Solve the payroll problem where the input file contains an unknown number of employee records. Read from an input file the employee ID#, his/her rate of pay, and the number of hours worked. Print to an output file the employee ID# and the amount earned in table form. Process employee records until end of file.

end-of-file controlled while loop

What does y = y++ do? What about y = ++y?

first one displays then bumps the y value if it displayed it would display the original y value the second one bumps then does it reads add one and it asks to what and it reads the y so the y is displayed as the +1 and now stored with the +1

How do you print the value of an array to the screen with a count loop

for (int i = 0; i < 5; ++i) Cout << scores[i] << endl;

What is a program that uses a function sum and demonstrates calling a user defined function that returns a single value

int sumIntegers (int, int); int main ( _ { int num1, num2, total; cout << "Enter 2 integers: "; Cin >> num1 >> num2; total = sumIntegers (num1, num2); Cout << "The sum is " << total; Return 0; } int sumIntegers ( int num1, int num2) { int result; result=num1 + num2 return result; }

What is PASCAL

introduced the concept of structured programming & special data types; a teaching language

How do you find the largest value in an array with a loop

largest =scores[0]; // Assumes first element is the largest for (int i = 1; i < SIZE; ++i) { if (scores[i] > largest) Largest = scores[i] } Cout << "Largest value: " << largest;

What are low-level languages? High-level languages

low-level Assembly language - closer to the numeric machine language of the computer itself than to our natural language Disadvantages - machine-dependent, not close enough to natural language to be easily learned and understood, and requires a technical background High-level BASIC - met the need for simplicity; often used in an interactive environment FORTRAN - designed in the late 1950s to meet the needs of the scientific and engineering communities COBOL - designed for business applications Pascal - introduced the concept of structured programming & special data types; a teaching language C - a structured language developed at Bell Laboratories that allows low-level programming while using a high-level language C++ - a spin-off of the C language also developed at Bell Labs that offers object-orientated features not found in C; portable Java - object-orientated language developed at Sun Microsystems used to develop programs that run over the internet in a web browser Visual Basic - a software development environment by Microsoft that allows programmers to create windows-based applications

What is the BASIC

met the need for simplicity; often used in an interactive environment

What are some different ways to access array elements

scores[2] = 34; //assigns the integer 34 to array element scores[2] scores[0] = scores[2] +1; //assigns the value in scores[2] + 1 to array element scores[0] cin >> scores[4]; //read an integer from the keyboard and store it in array element scores[4] cout << scores[3]; //write the integer value in array element scores[3] to the screen

What loop would work best for the following situation: Exam scores are read from an input file until a negative exam score is encountered. The average of the exam scores is printed to a file.

sentinel - value while (read) loop

What loop would work best for the following situation: The user is prompted to enter the item price. When all prices have been entered, the total is calculated, tax is added and a total amount due is printed to the screen.

sentinel - value while (read) loop

What is computer science

study of machines that execute algorithms

How do you sum the values in an array

sum = 0; for (int 1 = 0; i<SIZE;++i) sum += scores[i];

Is it better to use a symbolic constant for an array size or put the actual number

symbolic constant for ease of modification

What are statements

terminated by a semicolon

What is a preprocessor directive

the # include directive causes contents of another file to be inserted into your program

What does a call to void function contain?

the function name the argument list (which may be empty) a semicolon When a function is called from main, the statements in the body of the function are executed. After the function statements have been executed, control returns to the statement following the call to the function.

What does a function prototype contain

the function return type the function name the parameter type list (which may be empty) a semicolon Function prototypes can be placed outside of main, generally after the using namespace statement

What is a variable scope

the part of a program in which the variable is usable


Ensembles d'études connexes

PARTICIPATION QUIZ CHAPTER 1 ELECTRICAL UNITS OF MEASUREMENT

View Set

*Lab.03 BIO.141: Joints in the Human Body

View Set

1.4 PERANAN PEMERINTAH DAN RAKYAT

View Set

202110 BSCI-3700-001 Professor Bugg Safety Test 1

View Set

The Iroquois Creation Myth: "The World on Turtle's Back"

View Set

AMH 2020 Prep 4th Exam Chapters 27 & 28

View Set

CompTIA A+ 801 and 802 Comprehensive Set

View Set