Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this code in C++ WITHOUT USING VECTORS: Declare a class called FileType to represent the files stored on a hard drive. The FileType object

Write this code in C++ WITHOUT USING VECTORS:

Declare a class called FileType to represent the files stored on a hard drive. The FileType object should contain the file name, date created, file type (txt, doc, rtf, dat, in, out, cmd, cpp, java, py, etc.), file size in kilobytes, owner, permissions (read (r), write (w), and execute (x) access), a buffer to hold the contents of the file (a character array), and the size of the buffer (256 elements).

The class should have the following constructors:

A default constructor that assigns the term NA to all string variables, '-' to all character variables, and 0 to the numerical variables.

A constructor that accepts values as arguments and assigns them to the appropriate member variables.

Write the appropriate mutator functions (setters) that store values in these member variables and accessor functions (getters) that return the values of the private member variables.

A constructor is a member function without a return type (also not a void function) that initialize all private member varibles to specific values

Include the additional member functions listed below:

print: this member function does not take any parameters. This member function should print the contents of the file (buffer as described above) to the console in the form shown below:

========= reading sample.txt file ...

This is was my first C++ program in COSC 112

/*

#include

using namespace std;

int main() {

cout << "Hello world ";

return 0;

}

*/

Done reading file ...

fileInfo: this member function does not take any parameters. This member function should print the meta information about the file to the console - the file name, date created, file type, file size, owner, and permission in the form shown below:

General file information =======

File name: sample

File type: *.txt

Size: 1 KB

Date created: 5/9/2022

------ Security

Owner: ragada

Permissions: rwx

replaceAll: this member function takes as its parameters a character array and it size. This member functions should change all the elements of the character array with values from the parameter (Hint: this member function does not return a value).

count: this member function does not take any parameters. This function counts how many elements are in the character array and returns that value to the calling function. Note: While the maximum array size is 256, the number of elements in the array may be less than 256.

To test the class, create a driver.cpp that declare an instance of the FileType object. The instance should represent a small storage device that contains 15 different files.

Write the driver function to test the member functions mentioned above.

changePermission: this driver function does not take any parameters. The driver function prompts the user for which file permissions they wish to change and the changes it.

printFileList: This driver function takes the FileType array object, and the integer size. The function should display the meta data (file info) for each file in the array object as shown below:

File at location index 0

General file information =======

File name: sample

File type: *.txt

Size: 1 KB

Date created: 5/9/2022

------ Security

Owner: ragada

Permissions: rwx

File at location index 1

General file information =======

File name: invoice

File type: *.csv

Size: 32 KB

Date created: 4/15/2021

------ Security

Owner: ragada

Permissions: rwx

...

initFileList: The function takes as an input file reference, an FileType array object, and the integer size. The function should initialize the contents of the FileType array object accordingly. Each line of input is laid out as follows: file name, file type (txt, doc, rtf, dat, in, out, cmd, cpp, java, py, etc.), file size, date created, owner, permissions (read (r), write (w), and execute (x) access), a buffer to hold the contents of the file (a character array), and the size of the buffer (256 elements).

Complete the questions below.

Exercise 1: Write the C++ statements to define the FileType object as described above in the FileTypeHeader.h file.

/*PASTE CODE HERE */

Exercise 2: Write the member function definitions for the additional member functions as described above in the FileTypeImp.cpp file.

/*PASTE CODE HERE */

Exercise 3: Write the function definition for changePermisions function specifications above in the driver.cpp file.

/*PASTE CODE HERE */

Exercise 4: Write the function definition for initFileList function specifications above in the driver.cpp file.

/*PASTE CODE HERE */

class FileType{

//required data members

private:

string filename;

time_t date_created;

string file_type;

int file_size;

string owner;

string permissions;

vector buff;

public:

//default constructor

FileType(){

filename = "untitled.txt";

date_created = time(0);

file_type = "Text File";

file_size = 0;

owner = "";

permissions = "";

}

//parametrized contructor

FileType(string _filename, string _file_type, int _file_size, string _owner, string _permissions, vector _buff){

filename = _filename;

date_created = time(0);

file_type = _file_type;

file_size = _file_size;

owner = _owner;

permissions = _permissions;

buff = _buff;

}

//accessors

string getFileName(){

return filename;

}

string getDateCreated(){

return ctime(&date_created);

}

string getFileType(){

return file_type;

}

int getSize(){

return file_size;

}

string getOwner(){

return owner;

}

string getPermissions(){

return permissions;

}

vector readFileData(){

return buff;

}

//mutators

void rename(string _name){

filename = _name;

}

void changePermission(string _permissions){

permissions = _permissions;

}

void overrrideFileData(vector _buff){

buff = _buff;

setSize(sizeof(_buff));

}

void appendDataToFile(string _newline){

buff.push_back(_newline);

updateSize(sizeof(_newline));

}

void printFileData(){

for(string line: buff){

cout<

}

}

void setSize(int _size){

file_size = _size;

}

void updateSize(int val){

file_size += val;

}

};

int main() {

FileType file1;

cout<

vector vec;

vec.push_back("this is the first line!");

vec.push_back("this is the second line!!");

FileType file2("myfile.txt", "Text File", size(vec), "me", "+rwx", vec);

file2.printFileData();

cout<<"Size: "<

file2.appendDataToFile("adding new line to file content");

file2.readFileData();

cout<<"Size: "<

vector vec2;

vec2.push_back("new line, this will override previoud content");

vec2.push_back("have fun!!");

file2.overrrideFileData(vec2);

cout<<"Size: "<

file2.printFileData();

}

// C++ program to find the sum of two

// numbers using function declared in

// header file

#include "iostream"

// Including header file

#include "sum.h"

using namespace std;

// Driver Code

int main()

{

// Given two numbers

int a = 13, b = 22;

// Function declared in header

// file to find the sum

cout << "Sum is: "

<< sumOfTwoNumbers(a, b)

<< endl;

}

// Driver Code

int main()

{

// Given two numbers

int a = 13, b = 22;

// Function declared in header

// file to find the sum

cout << "Sum is: "

<< sumOfTwoNumbers(a, b)

<< endl;

}

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

Step: 3

blur-text-image

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions