4. Input and Output Flashcards

(54 cards)

1
Q

I/O

A

sequence of bytes (stream of bytes) from source to destination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

stream

A

sequence of characters from source to destination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

input stream

A

sequence of characters from input device to computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

output stream

A

sequence of characters from computer to output device

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

standard I/O devices

A

use iostream to extract data from keyboard + send output to screen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

iostream contains definitions of 2 types:

A

istream - input stream

ostream - output stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

iostream’s 2 variables

A

cin - stands for common input

cout - stands for common output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

using cin and cout

A

-include iostream must be used (preprocessor directive)
-declaration is similar to these statements:
istream cin;
ostream cout;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

extraction operator&raquo_space;

left hand operand

A

an input stream variable such as cin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

extraction operator&raquo_space;

right hand operand

A

a variable of simple data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

extraction operator&raquo_space;

syntax using it with cin

A

cin&raquo_space; variable&raquo_space; variable …;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

use of&raquo_space;

A

every occurence of&raquo_space; extracts the next data item from the input stream

eg. cin&raquo_space; x&raquo_space; y; is equivalent to cin&raquo_space; x; cin&raquo_space; y;

skips all the whitespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

whitespace characters

A

consist of blanks and certain nonprintable characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

data type of input

A

eg.&raquo_space; distinguishes between character 2 and number 2 by the right hand operand of&raquo_space;

(if it is char, 2 is treated as character 2, if it is int, it is treated as number 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

reading data: reading into char variable

A
  • eo&raquo_space; skips leading whitespace, finds + stores only next character
  • reading stops after a single character
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

reading data: reading into int/double variable

A
  • skips leading whitespace, reads + or - (if any), reads digits (incl decimal)
  • stops on whitespace non-digit character
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cin&raquo_space; z

z is adouble and 39 is input. What is the value of z?

A

z = 39.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

functions

A
  • (subprogram)
  • set of instructions
  • when activated, it accomplishes a task
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

main function

A

executes when a program is run

other functions only execute when called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

header files

A

predefined functions organised as a collection of libraries called header files

a header file can contain several functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

predefined functions

A

to use, need name of appropriate header file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what you need to know to use predefined functions

A
function name
no. of parameters req
type of each parameter
what function is going to do
23
Q

predefined function example

A

-compute x using pow (power) function
-pow is in cmath library
pow takes 2 numeric parameters
-then returns a number

24
Q

cin vs get function

A

> > cant read blanks or notice new lines and skips blanks + new lines

25
get function
- inputs next character (incl whitespace) | - stores character at location indicated by its arguments
26
sytax of cin and get function
cin.get(varChar); eg. cin.get(ch1); cin.get(ch2); cin >> num; If I type "A 34" ch1 = "A" ch2 = " " num = 34
27
other istream functions
cin.ignore(intExp, chExp); istreamVar.clear(); istreamVar.putback(ch); istreamVar.peek();
28
cin.ignore example: cin.ignore(100, '.');
-ignore next 100 characters or ignore input until it encounters '.'. Whichever comes first. The '.' will be discarded too.
29
input failure
- input data does not match corresponding variables - input stream enters fail state - all further I/O statement using that stream ignored - program continues to execute w/ values stored in variables - causes incorrect results
30
syntax of cout and <
cout << expression or manipulator << expression or manipulator << ...; called output statement
31
<< oeprator
called insertion operator or stream insertion operator
32
manipulator
alters output
33
endl
simplest manipulator, causes cursor to move to beginning of next line
34
\n
newline | cursor moves to beginning of next line
35
\t
tab | moves to next tab stop
36
\b
backspace | moves 1 space to left
37
\r
return | moves to beginning of current line
38
\\
backslash | blackslash is printed
39
\'
single quotation | single quotation mark printed
40
\"
double quotation | double quotation mark printed
41
formatting output commands
setprecision(n) fixed showpoint setw
42
setprecision(n)
outputs decimal numbers up to n decimal places
43
fixed
outputs floating-point numbers in a fixed decimal format
44
showpoint
forces output to show decimal point + trailing zeros
45
eg of setprecision and fixed
cout << setprecision(5) << f; = 3.1416 cout << fixed << setprecision(5) << f; 3.14159
46
setw
outputs value of an expression in specific columns
47
types of manipulators
with parameters and without parameters
48
parameterised
req iomanip header | eg. setprecision, setw, setfill
49
nonparameterised
req iostream header | eg. endl, fixed, showpoint, left, flush
50
I/O and string type
eo >> skips leading whitespace chars and reading stops at a whitespace character
51
reading strings with blanks
use function getline
52
getline
reads until end of current line
53
>>
extracts data from an input stream into a variable
54
<<
pushes data into an output stream