1/62
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
iostream
input or output stream
fstream
input and output file stream
ifstream
input file stream
ofstream
output file stream
eof
test for end of input file
cout
standard output
cin
standard input
creating a new file syntax
fstream newfile:
opening a file syntax
newfile.open(“info.txt”, ios::out);
out mode
allows data to be written to a file, ios::out
in mode
allows data to be read from a file, ios::in
close an opened file
newfile.close();
ios::binary
binary mode, data is written to or read from it in pure binary format
read from a file
use either ifstream or fstream class and specify the name of the file
create a file
use either ofstream or fstream and specify name of file
create and open a text file
ofstream Myfile (“filename.txt”)
writing in a file
Myfile « “Writing words”;
iomanip
library used to manipulate output of program, uses showprecision(x), setw(x), showpoiint
showprecision(x)
format to x decimal places
setw(x)
set field/width to x spaces
showpoint
set the format flag for str stream
fail()
true if failbit or hardfail set, false otherwise
bad()
true if badbit set, false otherwise
good()
true if goodbit set, false otherwise
clear()
clear all flags (no arguments), or clear a specific flag
member functions
file stream objects have _________ for special reading and writing, getline, get, put
getline
reads a line of data including whitespace characters, needs name of file stream and name of string
getline syntax
getline(myFile, name);
get
reads a single character from the file
get syntax
gradeFile.get(letterGrade);
put
writes a single character to the file
put syntax
reportFile.put(letterGrade);
outfile.close()
when a program is finished with a file, it must close the file using close like:
binary files
contain data that is not necessarily stored as ASCII text, uses ios::binary flag
abstraction
a recognition of similarities between certain objects, view or representation of an entity that includes only the most significant attributes
order of abstraction languages
machine code, assembler languages, procedural languages, object-oriented programs, modeling languages
procedural abstraction
writing and using subprograms as black boxes, hiding the details of a complex task/process under a method name with parameters
advantages of procedural abstraction
breaking code into pieces, reusing in different situations, easier to test and replace code, hides detail, documentation is easier
data abstraction
collections of data containing data + operations as abstract entities, process of simplifying and representing the whole
advantages of data abstraction
grouping related pieces of information, simplifying the task of reasoning about data, defining and understanding what meaningful operations can be performed on data, easy to modify the code
struct and class
abstraction can be achieved using both ____________ keywords through the concept of abstract classes
struct
user-defined composite data type that groups together variables of different data types under a single name
struct syntax
struct structName {
dataType1 identifier1
dataType2 identifier2
}
member access operator (.)
used to access data into the struct member
member access syntax
structVariableName.memberName
initializing data into a struct member
student newStudent = {“John”, “Brown”, 4.0};
string class
way to represent a sequence of characters as an object of the class, stores the characters a s a sequence of bytes allowing access to a single-byte character
print specific position in string
string_name[position];
print specific string range
string_name.substr(start #, end#);
binary operator +
can be used to perform string concatenation
getline function
to read strings line by line with white space use _______
getline with string syntax
getline(cin, stringName);
relational operators
strings can use ________ to compare
two dimensional array
array (row #, column #)
c-string
specific type of char array that adheres to a convention, fundamentally define by the presence of a null-termination character
c-string header file
#include <cstring>
null characters
if you store a string whose length is less than the array size, the last components are unused and filled with ________
strcpy(s1, s2);
copies string s2 into string s1
strcat(s1, s2);
concatenates string s2 onto the end of string s1
strlen(s1)
returns the length of string s1
strcmp
compares strings character by character
strcmp(s1, s2);
returns 0 is they are the same
returns negative if s1<s2
returns positive if s1>s2
get function
to read a string with blanks, use the _____
get syntax with a string
cin.get(name, 10) → reads 10 characters into name