Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Random Access File 4 The Random Access File 5 Sequential Operations 6 Computing the number of records 7 Sequential Listing of Records 8 Random Record

Random Access File

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

4 The Random Access File 5 Sequential Operations 6 Computing the number of records 7 Sequential Listing of Records 8 Random Record Access Defining a Record Structure To facilitate easy random access, it is necessary that all of the "records" in the file are the same size. This will allow us to locate a specific record easily by performing some simple math. We need a representation of a campsite with the following values:site number (an integer will work for this) *site description (a string) * a flag indicating whether the site provides electric power or nota per-night booking rate for the site (a floating point value will work for this) We want to keep the record simple, so we will use a struct. Create a header file CampsiteRecord.h and add the following structure definition * A fixed-size record representing a campsite in a * recreational area struct CampsiteRecord CampsiteRecord ( CampsiteRecord(int number, const char description[ , bool has_electric, double rate) static const int desc_size 128; int char bool double max storage size of description site number number description[ desc_sizeli IIl a short description has electric, rate: /Iis power available? /IT per-night rate The non-default constructor should copy its parameters into the attributes of the object. Implement it now, being sure to copy the c-string description safely Hint: Remember, you cannot use assignment to copy c strings!. You might want to refer to your notes, book, or online documentation for a refresher on how to use strnepy from the library. Implement the constructor in a new implementation file CampsiteRecord.cpp. Avoid information leakage! There is a security concern that we must mention at this point. The random access file will be written in binary mode, meaning that all of the bytes contained within the record will be copied directly into the file. That would include any bytes that are not actually in use in the record-the ones at the end of the description c-string, and potentially '"padding" bytes introduced between attributes in physical memory (this varies from system to system). But, those "unused" bytes might actually contain information... Remember that main memory isn't "cleared when variables go out of scope values often remain there until the memory is re-used. Writing from "unused" memory into a file leaks whatever information was in that unused memory. Imagine the following scenario, where the description is drastically shortened to it on the screen (it is not shown at its real 128 byte length, instead it is shown as 24 bytes). The bytes marked n belong to number, d belong to description, e belong to has electric, r belong to rate Memory before a record is created (i.e. "uninitialized): my password is open sesame". Don't t Memory after a record has been created (the represents the terminating 0' on the c-string): 4 The Random Access File 5 Sequential Operations 6 Computing the number of records 7 Sequential Listing of Records 8 Random Record Access Defining a Record Structure To facilitate easy random access, it is necessary that all of the "records" in the file are the same size. This will allow us to locate a specific record easily by performing some simple math. We need a representation of a campsite with the following values:site number (an integer will work for this) *site description (a string) * a flag indicating whether the site provides electric power or nota per-night booking rate for the site (a floating point value will work for this) We want to keep the record simple, so we will use a struct. Create a header file CampsiteRecord.h and add the following structure definition * A fixed-size record representing a campsite in a * recreational area struct CampsiteRecord CampsiteRecord ( CampsiteRecord(int number, const char description[ , bool has_electric, double rate) static const int desc_size 128; int char bool double max storage size of description site number number description[ desc_sizeli IIl a short description has electric, rate: /Iis power available? /IT per-night rate The non-default constructor should copy its parameters into the attributes of the object. Implement it now, being sure to copy the c-string description safely Hint: Remember, you cannot use assignment to copy c strings!. You might want to refer to your notes, book, or online documentation for a refresher on how to use strnepy from the library. Implement the constructor in a new implementation file CampsiteRecord.cpp. Avoid information leakage! There is a security concern that we must mention at this point. The random access file will be written in binary mode, meaning that all of the bytes contained within the record will be copied directly into the file. That would include any bytes that are not actually in use in the record-the ones at the end of the description c-string, and potentially '"padding" bytes introduced between attributes in physical memory (this varies from system to system). But, those "unused" bytes might actually contain information... Remember that main memory isn't "cleared when variables go out of scope values often remain there until the memory is re-used. Writing from "unused" memory into a file leaks whatever information was in that unused memory. Imagine the following scenario, where the description is drastically shortened to it on the screen (it is not shown at its real 128 byte length, instead it is shown as 24 bytes). The bytes marked n belong to number, d belong to description, e belong to has electric, r belong to rate Memory before a record is created (i.e. "uninitialized): my password is open sesame". Don't t Memory after a record has been created (the represents the terminating 0' on the c-string)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

3. Identify challenges to good listening and their remedies

Answered: 1 week ago

Question

4. Identify ethical factors in the listening process

Answered: 1 week ago