A) Ultimately, All Data Items Processed by a Computer Are Reduced to Combinations Or 1S and 0S

Total Page:16

File Type:pdf, Size:1020Kb

A) Ultimately, All Data Items Processed by a Computer Are Reduced to Combinations Or 1S and 0S

Alex Chen Stock P6

11.1 a) Ultimately, all data items processed by a computer are reduced to combinations or 1s and 0s. b) The smallest data item a computer can process is called a bit. c) A file is a group of related records d) Digits, letters, and special symbols are referred to as characters e) A group of related files is called a database f) Function fclose closes a file g) The fscanf statement reads data from a file in a manner similar to how scanf reads from stdin. h) Function getc reads a character from a specified file. i) Function fgets reads a line from a specified file j) Function fopen opens a file. k) Function fread is normally used when reading data from a file in random access applications l) Function fseek repositions the file position pointer to a specific location in the file

11.2 a) Function fscanf cannot be used to read data from the standard input. True b) The programmer must explicitly use fopen to open the standard input, standard output, and standard error streams – False, the three streams will open when the program opens. c) a program must explicitly call function fclose to close a file. False – the files will also be closed with the termination of the program. d) if the file position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file. False, function rewind can reposition the file pointer to the beginning e) Function fprint can write to the standard output. True f) Data in sequential-access files is always updated without overwriting other data. False, data in random access files is as sequential file records are not of uniform length. g) it is not necessary to search through all of the records in a randomly accessed file to find a specific record. True h) records in randomly accessed files are not of uniform length. False, they are of uniform length. i) Function fseek may only seek relative to the beginning of the file. False, it can seek relative to seek from the end of the file orfrom the current position.

11.3 a) ofPtr = fopen(“oldmast.dat”, “r”); b) tfPtr = fopen(“trans.dat”, “r”); c) nfPtr = fopen(“newmast.dat”, “w”); d) fscanf(ofPtr, “%d%s%f”, &accountNum, name, ¤tBalance); e) fscanf(tfPtr, “%d%f”, &accountNum, &dollarAmount); f) fprintf(nfPtr, “%d%s%.2f”, accountNum, name, currentBalance);

11.4 a) “payables.dat” was not opened before its reference to its file pointer. It must be opened with fopen b) printf cannot be used to output to a file; use fprint c) Open is not a function; use fopen d) e) scanf cannot be used to read from a file, use fscan f) When data is added to a file, the current data is discarded g) use a double equal sign between tfPtr and fopen – otherwise tfPtr is assigned the weird value h) To open a file without modifying it, open it for reading, not appending i) use a double equal sign between cfPtr and fopen – otherwise tfPtr is assigned the weird value

11.5 a) Computers store large amounts of data on secondary storage devices as disk storage devices b) A record is composed of several fields c) A field that may contain digits, letters, and blanks is called a character field d) To facilitate the retrieval of specific records from a file, one field in each record is chosen as a record key. e) The vast majority of information stored in computer systems is stored in sequential files. f) A group of related characters that conveys meaning is called a field g) The file pointers for the three files that are opened automatically by C when program execution begins are named stdin, stdout, and stderr. h) Function fputc writes a character to a specified file i) Function fputs writes a line to a specified file j) Function fwrite is generally used to write data to a randomly accessed file. k) Function rewind repositions the file pointer to the beginning of the file

11.6 a) The impressive functions performed by computers essentially involve the manipulation of zeroes and ones. True b) People prefer to manipulate bits instead of characters and fields because bits are more compact. False, people prefer to manipulate characters and fields because they are easier to use. c) People specify programs and data items as characters; computers then manipulate and process these characters as groups of zeroes and ones. True d) A person’s zip code is an example of a numeric field. True e)A person’s street address is generally considered to be an alphabetic field in computer applications False, alphabetical and numerical f)Data items processed by a computer form a data hierarchy in which data items become larger and more complex as we progress from fields to characters to bits etc. False, the other way around g) A record key identifies a record as belonging to a particular field. False, a record key identifies a record as belonging to a particular person/entity. h) Most organizations store all their information in a single file to facilitate computer processing. False, many different files i) Files are always referred to by name in C programs . False, referred by pointers j) When a program creates a file, the file is automatically retained by the computer for future reference. False, it is overwritten

11.11) struct person{ char lastname[15]; char firstname[15]; char age[4]; }; struct person records[100]; a) nfPtr = fopen("nameage.dat", "w"); b) int i = 0; for (i = 0; i < 100; i++) { lastName = "unassigned"; firstname = ""; age = "0"; } c) cout << "Enter index number of record to update" << endl; cin >> index; if (records[index].lastName == "unassigned") { cout << "No info" << endl; } else{ cout <<"Enter first name" << endl; cin >> records[index].firstname; cout <<"Enter last name" << endl; cin >> records[index].lastname; cout <<"Enter age" << endl; cin >> records[index].age; } d) cout << "Enter index number of record to delete" << endl; cin >> index; records[index].lastname = "unassigned"; records[index].firstname = ""; records[index].age = "0";

Recommended publications