• Home
  • Blog
  • c++ Modify and complete existing program

c++ Modify and complete existing program

0 comments

Modify and improve the existing code

Use a vector of File pointers

Design a hierarchy of Files. You have two different kinds of Files, Text File and an Image File. The files are identified by their name and type, which is identified by either txt or gif extension. An Image file has dimensions of pixel rows and pixel columns. Each pixel has a color depth that can be represented by number of bits. (8 bits is one byte). A Text file is a plain ASCII file that contains characters. Each character is represented by 8 bits. You should provide a function getSize that returns size of a file. Size of a file is measured in bytes. The size of an Image file is calculated by finding how many pixels are needed to store the file multiplied by number of bits to color a single bit divided by 8. The size of a Text file is calculated by counting number of ASCII characters stored in the file.

A), Provide a function to display properties of a File. Properties include: type, name, size, dimensions and color depth for an Image File, characters for a Text File. Provide functions to return type and names of files.

B), Provide function to retrieve character count for a Text file.

C), Provide functions to retrieve dimensions and color depth of an Image File.

D), Write two recursive functions: The first one receives a vector of File pointers and recursively outputs properties of every file stored inside this vector.

E), The second function receives a vector of File pointers and a string which represents a type of the file (gif or txt). The function should return another vector of File pointers containing only Image files or Text files, depending on the second parameter. The function should be recursive.

Write a menu driven application that is going to use the hierarchy classes. You will keep track of the collection of Files in a vector (File pointers, since File is an abstract class). The menu should contain the following options:

1. Read from a file (Read descriptions of Files from “files.txt” creating appropriate File object and putting it inside your vector. The file.txt is provided)

2. Create an Image File (Creates a single Image File asking the user for its properties)

3. Create a Text File (Creates a single Text File asking the user for its properties)

4. Print All Files (use functions written in D)

5. Print Image Files (use functions written in E)

6. Print Text Files (use functions written in E)

7. Delete a file by file name and type (Removes a file from a vector)

8. Quit (Terminate the program)

Here are the contents of the file.txt that you can use for testing purposes.

txt

students

500

txt

files

120

gif

picture1

100 x 200

8

gif

picture2

200 x 300

16

txt

testfile

450

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}