Question

In: Computer Science

This laboratory is designed to get you started with the project and random access file I/O....

This laboratory is designed to get you started with the project and random access file I/O.

  1. Open your source file and write or copy the code for the class interface for the Sdisk.
    Class Sdisk
    {
    public :
    Sdisk(string diskname, int numberofblocks, int blocksize);
    int getblock(int blocknumber, string& buffer);
    int putblock(int blocknumber, string buffer);
    int getnumberofblocks(); // accessor function
    int getblocksize(); // accessor function
    private :
    string diskname;        // file name of software-disk
    int numberofblocks;     // number of blocks on disk
    int blocksize;          // block size in bytes
    };
  2. You can copy a sample main program from here.
    // You can use this to test your Sdisk class 
    
    int main()
    {
      Sdisk disk1("test1",16,32);
      string block1, block2, block3, block4;
      for (int i=1; i<=32; i++) block1=block1+"1";
      for (int i=1; i<=32; i++) block2=block2+"2";
      disk1.putblock(4,block1);
      disk1.getblock(4,block3);
      cout << "Should be 32 1s : ";
      cout << block3 << endl;
      disk1.putblock(8,block2);
      disk1.getblock(8,block4);
      cout << "Should be 32 2s : ";
      cout << block4 << endl;;
    }
  3. Create function stubs (functions with no code) for the class functions.
  4. Work first on the constructor that creates the Sdisk.
  5. Now work on putblock to open the file and write a block.
  6. Finally work on getblock to open the file and get a block.
  7. Now test with the example main program.

Solutions

Expert Solution

#include<iostream>
#include<fstream>
using namespace std;


Class Sdisk
{
public :
Sdisk(string diskname, int numberofblocks, int blocksize)
{diskname=block;
numberofblocks=4;
blocksize=4;
}

int getblock(int blocknumber, string& buffer);
int putblock(int blocknumber, string buffer);
int getnumberofblocks(); // accessor function
int getblocksize(); // accessor function
void stubs();
private :
string diskname;        // file name of software-disk
int numberofblocks;     // number of blocks on disk
int blocksize;          // block size in bytes
};

int Sdisk::putblock(int blocknumber,string& buffer)

{ ifstream f1;

f1.open("file.DAT");

if(!f1)

{

cout<<"ERROR IN OPENING FILE file.DAT|n";

exit(102);

}

f1.get(buffer);

f1.close();

}

int Sdisk::getblock(int blocknumber, string buffer)

{

ofstream f2;

f2.open("file2.DAT);

cout<<"DATA IN FILE";

while(!f2.eof())

{

f2.get(buffer);

cout<<buffer;

}

f2.close();

}

void Sdisk::stubs()

{

}

int main()

{
  Sdisk disk1("test1",16,32);
  string block1, block2, block3, block4;
  for (int i=1; i<=32; i++) block1=block1+"1";
  for (int i=1; i<=32; i++) block2=block2+"2";
  disk1.putblock(4,block1);
  disk1.getblock(4,block3);
  cout << "Should be 32 1s : ";
  cout << block3 << endl;
  disk1.putblock(8,block2);
  disk1.getblock(8,block4);
  cout << "Should be 32 2s : ";
  cout << block4 << endl;;
}

Related Solutions

5) File I/O A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O:...
5) File I/O A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O: B) Discuss Serialization, what is it? What are the processes and features? What is the function of the keyword Transient?
).Modify the project so that records are inserted into the random access file in ascending order...
).Modify the project so that records are inserted into the random access file in ascending order using an insertion sort methodology with the Social Security Number acting as the key value. This requires defining the method compareTo() in the Personal and Student classes to be used in a modified method add() in Database. The method finds a proper position for a record d, moves all the records in the file to make room for d, and writes d into the...
1).Modify the project so that records are inserted into the random access file in ascending order...
1).Modify the project so that records are inserted into the random access file in ascending order using an insertion sort methodology with the Social Security Number acting as the key value. This requires defining the method compareTo() in the Personal and Student classes to be used in a modified method add() in Database. The method finds a proper position for a record d, moves all the records in the file to make room for d, and writes d into the...
describe the mechanism that supports random file access in Java.
describe the mechanism that supports random file access in Java.
Java Programming Project 6: File I/O Purpose: To practice reading from as well as writing to...
Java Programming Project 6: File I/O Purpose: To practice reading from as well as writing to text files with the help of Scanner class methods, and PrintStream class methods. You will also learn to implement some simple Exception Handling. Carefully examine and follow ALL the program specifications. Take a look at the PPT slides for Chapter 7 File I/O for examples that will help with this program. Hotel Expense Recording Keeping: A hotel bookkeeper enters client hotel expenses in a...
This assignment will give you practice in Handling Exceptions and using File I/O. Language for this...
This assignment will give you practice in Handling Exceptions and using File I/O. Language for this program is JAVA Part One A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the client, the service sold (such as Dinner, Conference, Lodging, and so on), the amount of the sale, and the date of that event. Prompt the user for data to write the file. Part Two Write a program that...
Can you please solve these questions/ statements using python? I started with "importing" the file. I...
Can you please solve these questions/ statements using python? I started with "importing" the file. I only need question one to be answered not two-four. Can use whatever data frame of choice, I just need a sample code for each line. Thank you #1. #Fit a linear regression model on data: USA_housing.csv to predict the Price of the house. import pandas as pd housing_df = pd.read_csv("USA_Housing.csv") #Income: Avg. area income #Age: Avg age of the houses #Bedrooms: Avg No of...
// I can't get my cpp file to work with my header file and it always...
// I can't get my cpp file to work with my header file and it always says the error comes from compatibility I am using Visual Studio 2015 below is the error only my file path and program name has been erased. The issue comes up in my cpp file with the size_t empty and full functions. // Error (active)       declaration is incompatible with "bool ListType::empty()" (declared at line 12 of ListType.h)         // ListType header file #ifndef...
For each of the following file processing operations, indicate whether a sequential file, indexed random file, virtual storage access method, hashing,
For each of the following file processing operations, indicate whether a sequential file, indexed random file, virtual storage access method, hashing, or pointer structure would work best. You may choose as many as you wish for each step. Also, indicate which would perform the least optimally.a. Retrieve a record from the file based on its primary key value.b. Update a record in the file. c. Read a complete file of records. d. Find the next record in a file. e....
I. Describe the differences between discretionary access control model and mandatory access control model II. File...
I. Describe the differences between discretionary access control model and mandatory access control model II. File permissions in Linux can be also represented in digits from 0-7 for the owner, group and others with reading as the most significant bit (E.g., the value 6 represents the permission right rw- for a file). Suppose a file in Linux has the permission as the digits 764. • What does this permission right indicate for the owner/user, group and others? • What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT