|
@@ -4,7 +4,7 @@
|
4
|
4
|
![main2.png](images/main2.png)
|
5
|
5
|
![main3.png](images/main3.png)
|
6
|
6
|
|
7
|
|
-[Verano 2016 - Ive]
|
|
7
|
+[Verano 2016 - Ive - Rafa - Ive]
|
8
|
8
|
|
9
|
9
|
Arrays help us to store and work with groups of data of the same type. The data is stored in consecutive memory spaces which can be accessed by using the name of the array and indexes or subscripts that indicate the position where the data is stored. Repetition structures provide us a simple way of accessing the data within an array. In today's laboratory experience you will practice the use of counters and one dimensional arrays to implement a program in which you will use Benford’s Law to detect files with bogus data.
|
10
|
10
|
|
|
@@ -131,13 +131,14 @@ The **frequency of occurrence** is defined as the ratio of times that a digit ap
|
131
|
131
|
|
132
|
132
|
---
|
133
|
133
|
|
134
|
|
-This lab requires you to read data from a text file. You can skip the next section if you feel that your file reading skills are competent. Otherwise, read on..
|
135
|
134
|
|
136
|
135
|
|
137
|
136
|
## Reading data from text files in C++
|
138
|
137
|
|
|
138
|
+This laboratory experience requires you to read data from a text file. You can skip the next section if you feel that your file reading skills are competent. Otherwise, read on...
|
139
|
139
|
|
140
|
|
-C++ provides functions to read and write data to/from files. In this lab you will be using one of the most rudimentary file input/output schemes provided in C++ to read/write from **text** files. Text files consist exclusively of ASCII characters which represent data in any of the primitive types provided by C++. Typically, the values are separated by spaces. For instance lets asumme that the file `nameAge.txt` contains some data about names and ages.
|
|
140
|
+
|
|
141
|
+C++ provides functions to read and write data to/from files. In this laboratory experience you will be using one of the most rudimentary file input/output schemes provided in C++ to read/write from **text** files. Text files consist exclusively of ASCII characters which represent data in any of the primitive types provided by C++. Typically, the values are separated by spaces. For instance lets asumme that the file `nameAge.txt` contains some data about names and ages.
|
141
|
142
|
|
142
|
143
|
```
|
143
|
144
|
Tomas 34
|
|
@@ -192,18 +193,18 @@ int main(){
|
192
|
193
|
}
|
193
|
194
|
```
|
194
|
195
|
|
195
|
|
-The ifstream object is used for reading a text file **sequentially**. It keeps track of the next position in the file that should be read. Each time that a data is read from the file (using `inFile >> ____`) it advances its position so that the next `inFile >> ___` reads the next data and so forth.
|
|
196
|
+The `ifstream` object is used for reading a text file **sequentially**. It keeps track of the next position in the file that should be read. Each time that a data is read from the file (using `inFile >> ____`) it advances its position so that the next `inFile >> ___` reads the next data and so forth.
|
196
|
197
|
|
197
|
198
|
Notice the line `inFile >> name >> age`. This instruction accomplishes several tasks:
|
198
|
199
|
|
199
|
|
-* It reads a string and an int from the file (if available) and assigns them to the variables `name` and `age`.
|
|
200
|
+* It reads a `string` and an `int` from the file (if available) and assigns them to the variables `name` and `age`.
|
200
|
201
|
* If both data were read, the expression evaluates to `true`, thus entering the while block.
|
201
|
202
|
* If both data could not be read, the expression evaluates to `false` thus ending the while block.
|
202
|
203
|
|
203
|
204
|
|
204
|
205
|
Here are some code snippets for common reading tasks. Observe that all of them:
|
205
|
206
|
|
206
|
|
-1. Create a ifstream object, call the `open` function and check if the file is opened correctly.
|
|
207
|
+1. Create an `ifstream` object, call the `open` function and check if the file is opened correctly.
|
207
|
208
|
2. Create one or more variables to assign the values that are read from the file.
|
208
|
209
|
3. Implement a loop which repeats until no more data is available in the file.
|
209
|
210
|
3. `close` the file at the end.
|
|
@@ -266,7 +267,9 @@ Here are some code snippets for common reading tasks. Observe that all of them:
|
266
|
267
|
inFile.close();
|
267
|
268
|
```
|
268
|
269
|
|
|
270
|
+---
|
269
|
271
|
|
|
272
|
+---
|
270
|
273
|
|
271
|
274
|
##Laboratory session
|
272
|
275
|
|