Exam 2 Computer Science

studied byStudied by 463 people
5.0(1)
Get a hint
Hint

File

1 / 66

flashcard set

Earn XP

Description and Tags

For CS135 students and friends

67 Terms

1

File

An Area in secondary storage used to hold information.

C++ Standard Template Library includes a header file for file I/O: fstream

Header to only use input from a file: ifstream

Header to only use output to a file: ofstream

New cards
2

File I/O

knowt flashcard image
New cards
3

Strings Continued

knowt flashcard image
New cards
4

Command Line Arguments

A parameter supplied to the program when it is invoked.

New cards
5

Using Command Line Arguments

knowt flashcard image
New cards
6

List

A collection of components arranged one after another

New cards
7

(1D)Array

A list containing a collection of a fixed number of components of the same data type.

New cards
8

Arrays

knowt flashcard image
New cards
9

Accessing Information in Arrays

knowt flashcard image
New cards
10

Processing Arrays Types

1. Initializing an array

2. Reading data into an array

3. Printing an array

4. Finding the sum/average of an array

5. Finding the largest/smallest element in an array

New cards
11

Initializing an Array

knowt flashcard image
New cards
12

Reading Data Into an Array

knowt flashcard image
New cards
13

Printing an Array

knowt flashcard image
New cards
14

Finding the Sum/Average of an Array

knowt flashcard image
New cards
15

Finding the Min/Max of an Array

knowt flashcard image
New cards
16

In-Bound Index

An index that is 0 <= index <= arraySize -1.

New cards
17

Out-Of-Bounds Index

An index that is index < 0 or arraySize - 1 < index.

New cards
18

Array Out of Bounds

knowt flashcard image
New cards
19

Copying One Array Into Another Array

knowt flashcard image
New cards
20

Two-Dimensional Array

A collection of a fixed number of components arranged in rows and columns, wherein all the components are of the same data type.

New cards
21

2D Arrays

knowt flashcard image
New cards
22

Void Functions

Functions that do not have a return type. These functions do not return a value or use a return statement.

New cards
23

Value-Returning Functions

Functions that have a return type. These functions return a value of a specific data type using the return statement.

New cards
24

Void Functions Without Parameters

knowt flashcard image
New cards
25

Void Functions With Parameters

knowt flashcard image
New cards
26

Value-Returning Functions

knowt flashcard image
New cards
27

Formal Parameters

A variable declared in the function heading.

● The formal parameters are the parameters you can use only in your user-defined function.

● General syntax (Formal Parameter List): dataType identifier, dataType identifier, …

New cards
28

Actual Parameters

A variable or expression listed in a call to a function.

● The actual parameters are the parameters you can use only in your calling function.

● General syntax (Actual Parameter List): expression or variable, expression or variable,

New cards
29

Scope

Where in the program an identifier is accessible (visible).

New cards
30

Local Identifier

Identifiers declared within a function or block of code. These identifiers are not accessible outside of the function or block of code they are declared in.

New cards
31

Global Identifier

Identifiers declared outside of every function definition. These identifiers are accessible from any function in your program (but not without side effects).

New cards
32

Rules when accessing identifiers:

knowt flashcard image
New cards
33

Function Prototype

The function heading without the body of the function or identifiers of the formal parameters.

New cards
34

Function Prototype Page

knowt flashcard image
New cards
35

Value Parameters

A formal parameter that receives a copy of the value of the corresponding actual parameter.

New cards
36

Value Parameter Page

knowt flashcard image
New cards
37

Reference Parameters

A formal parameter that receives the address (memory location) of the corresponding actual parameter.

New cards
38

Reference Parameters Page

knowt flashcard image
New cards
39

Default Parameters

knowt flashcard image
New cards
40

Function Overloading

Creating several functions with the same name.

New cards
41

Function Overloading Page

knowt flashcard image
New cards
42

Control Structures

knowt flashcard image
New cards
43

While Looping

knowt flashcard image
New cards
44

Types of While Loops

knowt flashcard image
New cards
45

For Looping

knowt flashcard image
New cards
46

Do While Looping

knowt flashcard image
New cards
47

Break and continue

knowt flashcard image
New cards
48

Nested Control Structures

knowt flashcard image
New cards
49

Explain the difference between break and continue statements in a loop.

The break statement is used to exit a loop prematurely, whereas the continue statement is used to skip the rest of the loop's code and move to the next iteration.

New cards
50

What loop is best to use when you know the number of iterations?

For loops

New cards
51

What loop is best to use when you at least want one iteration?

Do ... while loop.

New cards
52

Why should we not use global variables in our program?

If you use a global variable throughout your program, it can be very hard to track down bugs with them. Problems caused by a global variable in one part of a program may be understood as problems in other parts of a program. Since the variable scope is larger, that means more code to surf through.

New cards
53

Given the following code snippet, what is the output after execution?

int n = 3;

for (int i = 1; i <= n; ++i) {

for (int j = 1; j <= i; ++j) {

cout << j << " ";

}

cout << endl;

}

1

1 2

1 2 3

New cards
54

In a few lines of code, verify if the file was open.

if(reader.is_open()){

cout<<"Valid file"«endl;

}

New cards
55

Explain the purpose of the library in C++.

Used for file input and output operations. It provides classes like ifstream (input file stream) and ofstream (output file stream) that enable reading from and writing to files

New cards
56

Create an 2D integer array named arr with 5 columns and 3 rows.

const int rows = 3;

const int columns = 5;

int arr[rows][columns];

New cards
57

With a few lines of code, print all elements of an array named values with 8 elements.

for (int i = 0; i < 8; ++i) {

cout << values[i] << " ";

}

New cards
58

Why is it important to be cautious about accessing elements beyond the bounds of an array in C++?

Accessing elements beyond the bounds of an array in C++ can lead to undefined behavior, including segmentation faults (seg faults). This occurs because memory outside the allocated array space may not belong to the program, causing unexpected results or crashes.

New cards
59

List the general steps of reading data from a text file into a one-dimensional array in C++.

1. Include Necessary Headers: #include <fstream>

2. Declare an Input File Stream

3. Open the File

4. Declare and Initialize the Array

5. Read Data from the File

6. Close the File

New cards
60

Provide the function signature for each function.

void acc(int id, char alpha, double cash);

int fire(float radius, float temperature = 60);

string ice(int temp = 31, bool shard = 29);

void bomb(int time[], int power, double radius);

void shift(int x, int pos[], double z);

acc(int, char, double)

fire(float, float) fire(float)

ice(int, bool) ice(int) ice()

bomb(int[], int, double)

shift(int, int[], double)

New cards
61

For a function: int findArea(int length, int width), provide an example that uses function overloading.

int findArea(int radius)

New cards
62

For the following program, correctly label the function prototype, body, call, and header.

1. Prototype

2. Call

3. Header

4. Body

<p>1. Prototype </p><p>2. Call </p><p>3. Header </p><p>4. Body</p>
New cards
63

Why are arrays always passed by reference to functions?

Arrays are a contiguous block of memory. Passing them by reference (by providing the memory address) avoids the overhead of copying the entire array, making function calls more efficient.

New cards
64
term image

(Ideas on how to approach this but not perfect)

<p>(Ideas on how to approach this but not perfect)</p>
New cards
65
term image

(Ideas on how to approach this but not perfect)

<p><span>(Ideas on how to approach this but not perfect)</span></p>
New cards
66
term image

(Ideas on how to approach this but not perfect)

<p><span>(Ideas on how to approach this but not perfect)</span></p>
New cards
67

Function Signature

The function name and formal parameter list data types. The signature does not include the return type of the function.

New cards

Explore top notes

note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 23 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 28 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 1 person
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 89 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard21 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard33 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard34 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard300 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard47 terms
studied byStudied by 2010 people
Updated ... ago
4.6 Stars(46)
flashcards Flashcard66 terms
studied byStudied by 245 people
Updated ... ago
4.4 Stars(5)
flashcards Flashcard59 terms
studied byStudied by 49 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard40 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)