Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercises Fill in the blanks in each of the following: State which of the follow

ID: 649686 • Letter: E

Question

Exercises Fill in the blanks in each of the following: State which of the following are true and which are true and which are false. If false, explain why. Write statements that accomplish each of the following. Assume that the structure has been defined and that the file is already open for writing. a) Initialize the file ''nameage.dat'' so that there are 100 records with lastName = ''unassigned'', firstname = '' '' and age = ''0''. b) Input 10 last names, first names and ages and write them to the file. c) Update a record; if there's no information in the record, tell the user ''No info''. d) Delete a record that has information by reinitializing that particular record.

Explanation / Answer

11.5

a) Answer is files
Computers store data as files as back up on
secondary storage devices like cd,dvd or harddisks.

b) Answer is record
A record is a collection of several fields values
in a table.

c)Answer is key
For retrieval of specific record from a table,
key is used to get the unique records from table.

d) Answer is field.
A field is a column name that conveys a meaning
about a filed.

e) Answer is stdin, stdout, stderr are
three standard stream objects that are opened automatically when a program execution starts

f) Answer is fputc
The function fputc that writes a character to a file

g) Answer is fputs
The function fputs that writes a line to a file

h) Answer is fwrite

The function fwrite that use used to write data to random access files

i) Answer is rewind
The function rewind that sets the file position to
the beginiting of the file.

-------------------------------------------------------------------------------------------


11.6
True or False type

a) True

functions performed in programs work on zeros and ones of the data stored in computors

b) False
People cannot understand zero's and one's when
working with computer programs. people do not
prefer to work with ones and zeros.

c) True

People specify programs and data as characters
because people can understand characters rather
zeros and ones.

d) True
Zip code is group of digits . It is an example of
numeric data

e) False
Data items like integers,characters or words become
more complex

f) True
A recored key can identifies a record.
Record key uniquely identifies a record based on key value.

g) False
Multiple files are used to store information related to company

h) True
Files are refered by their names in C language
extension with .c

i) True
A file created using a program , the file
store in computer secondary storage for future
reference.

-------------------------------------------------------------------------------------------

11.11

a) Initialize 100 structure records and write to file

//Create file pointer for file nameage.dat
//To write structure data ,open file in binary in write mode
FILE*fPointer=fopen("nameage.dat","wb");
//create a structure to store 100 records
person personRecords[100];

int record;
for(record=0;record<100;record++)
{
   //set lastName and lastName and age
   personRecords[record].lastName="unassigned";
   personRecords[record].firstName="";
   personRecords[record].age="0";
  
   //Write records to file "nameage.dat" pointed to by pointer fPointer
   fwrite(&personRecords[record],sizeof(personRecords[record]),fPointer);
}
//close filepointer stream
fclose(fPointer);


b) Input 10 records to the file
//Create file pointer for file nameage.dat
//To write structure data ,open file in binary in write mode
FILE*fPointer=fopen("nameage.dat","wb");
//create a structure to store 10 records
person personRecords[10];

int record;
for(record=0;record<10;record++)
{

   printf("Enter last name");
   scanf("%s",personRecords[record].lastName);
   printf("Enter first name");
   scanf("%s",personRecords[record].firstName);
   printf("Enter last name");
   scanf("%s",personRecords[record].age);

   //Write records to file "nameage.dat" pointed to by pointer fPointer
   fwrite(&personRecords[record],sizeof(personRecords[record]),fPointer);
}

//close filepointer stream
fclose(fPointer);

c) update a record at recordNumber with first name, last name and age

//Create file pointer for file nameage.dat
//To write structure data ,open file in binary in write mode
FILE*fPointer=fopen("nameage.dat","wb");
//create a structure to store 10 records
const int SIZE=
person personRecords[SIZE];
int recordNumber;
int record;

printf("Enter record number to updat");
scanf("%d",&recordNumber)


if(recordNumber<0 || recordNumber>SIZE)
   printf("No record found");
else
   {
       printf("Enter last name");
       scanf("%s",personRecords[record].lastName);
       printf("Enter first name");
       scanf("%s",personRecords[record].firstName);
       printf("Enter last name");
       scanf("%s",personRecords[record].age);
       //update record with new data at recordNumer to file "nameage.dat"
       //pointed to by pointer fPointer
   fwrite(&personRecords[recordNumber],
       sizeof(personRecords[recordNumber]),fPointer);
   }

//close file pointer
fclose(fPointer);


d) Delete a record and reinitialize the record and write file

//Create file pointer for file nameage.dat
//To write structure data ,open file in binary in write mode
FILE*fPointer=fopen("nameage.dat","wb");
//create a structure to store 10 records
const int SIZE=
person personRecords[SIZE];
int recordNumber;
int record;

printf("Enter record number to delete");
scanf("%d",&recordNumber)


   if(recordNumber<0 || recordNumber>SIZE)
       printf("No record found");
   else
   {

   //reinitialize the record at recordNumber
   personRecords[recordNumber].lastName="unassigned";
   personRecords[recordNumber].firstName="";
   personRecords[recordNumber].age="";

   //Write reinitialized record to file "nameage.dat" pointed
   //to by pointer fPointer
   fwrite(&personRecords[recordNumber],
   sizeof(personRecords[recordNumber]),
   fPointer);
       }
  
   }

//close file pointer
fclose(fPointer);

Hope this helps you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote