4. Input and Output Flashcards

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
Q

get function

A
  • inputs next character (incl whitespace)

- stores character at location indicated by its arguments

26
Q

sytax of cin and get function

A

cin.get(varChar);

eg.
cin.get(ch1);
cin.get(ch2);
cin&raquo_space; num;
If I type “A 34”
ch1 = “A”
ch2 = “ “
num = 34

27
Q

other istream functions

A

cin.ignore(intExp, chExp);

istreamVar.clear();

istreamVar.putback(ch);

istreamVar.peek();

28
Q

cin.ignore example: cin.ignore(100, ‘.’);

A

-ignore next 100 characters or ignore input until it encounters ‘.’. Whichever comes first. The ‘.’ will be discarded too.

29
Q

input failure

A
  • 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
Q

syntax of cout and <

A

cout &laquo_space;expression or manipulator &laquo_space;expression or manipulator &laquo_space;…;

called output statement

31
Q

&laquo_space;oeprator

A

called insertion operator or stream insertion operator

32
Q

manipulator

A

alters output

33
Q

endl

A

simplest manipulator, causes cursor to move to beginning of next line

34
Q

\n

A

newline

cursor moves to beginning of next line

35
Q

\t

A

tab

moves to next tab stop

36
Q

\b

A

backspace

moves 1 space to left

37
Q

\r

A

return

moves to beginning of current line

38
Q

\

A

backslash

blackslash is printed

39
Q

'

A

single quotation

single quotation mark printed

40
Q

"

A

double quotation

double quotation mark printed

41
Q

formatting output commands

A

setprecision(n)
fixed
showpoint
setw

42
Q

setprecision(n)

A

outputs decimal numbers up to n decimal places

43
Q

fixed

A

outputs floating-point numbers in a fixed decimal format

44
Q

showpoint

A

forces output to show decimal point + trailing zeros

45
Q

eg of setprecision and fixed

A

cout &laquo_space;setprecision(5) &laquo_space;f;
= 3.1416

cout &laquo_space;fixed &laquo_space;setprecision(5) &laquo_space;f;
3.14159

46
Q

setw

A

outputs value of an expression in specific columns

47
Q

types of manipulators

A

with parameters and without parameters

48
Q

parameterised

A

req iomanip header

eg. setprecision, setw, setfill

49
Q

nonparameterised

A

req iostream header

eg. endl, fixed, showpoint, left, flush

50
Q

I/O and string type

A

eo&raquo_space; skips leading whitespace chars and reading stops at a whitespace character

51
Q

reading strings with blanks

A

use function getline

52
Q

getline

A

reads until end of current line

53
Q

> >

A

extracts data from an input stream into a variable

54
Q

«

A

pushes data into an output stream