Question

Write a menu driven application that is going to use the hierarchy that you have written for homework 8 and the functions thaIt is a C++ program by using inheritance and vectors

My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp

I already have these files

File.cpp

#include "File.h"

// Constructor of File that takes File name and type as arguments
File::File(string type, string name) {
   this->type = type;
   this->name = name;
}
//returns the type.
string File::getType() {
   return type;
}

//returns the name of file.
string File::getName() {
   return name;
}

File.h

#ifndef __FILE_H__
#define __FILE_H__

#include
#include

using namespace std;

// class declration of File class
class File{
   public:
       // constructor.
       File(string, string);

       string name; // Name of file
       string type; // Type of file

       // virtual functions to be defined in inheriting classes.
       virtual size_t getSize(){}
       virtual void displayProperties(){}

       // returns type and name of file.
       string getType();
       string getName();
};

#endif

Image.cpp

#include "Image.h"

// Constructor for image class with call to constructor
// of parent class.
Image::Image(string name, int r, int c): File(name,"image") {
  
   row = r;
   col = c;

    int** colorDepth = new int*[row];
   for(int i = 0; i < row; ++i)
            colorDepth[i] = new int[col];

}

// returns the size of Image. Please check if the logic is right or not.
size_t Image::getSize() {
   return row*col;
}

// Function to display the properties of file.
void Image::displayProperties() {
   cout<<"File Name : "<    cout<<"File Type : "<    cout<<"File Size : "<    cout<<"Image File Dimensions : "<    cout<<"Color Depth\n"<    for(int i = 0;i        for(int j = 0;j            cout<        }
       cout<    }

}

// returns the height of image.
int Image::getHeight() {
   return row;
}

// returns the width of image.
int Image::getWidth() {
   return col;
}

// retunr the image.

char** Image::getColorDepth() {
   return colorDepth;
}

Image.h

#ifndef __IMAGE_H__
#define __IMAGE_H__

#include "File.h"

// Image File class declaration.
class Image: public File {
   public:
       // dimensions of image.
       int row, col;
       // color depth of each pixel
       char **colorDepth;

       // constructor of image
       Image(string name, int r, int c);
       // returns the size of file.
       size_t getSize();
       // display properties of Image file.
       void displayProperties();
       // returns the height of file.
       int getHeight();
       // returns the width of file.
       int getWidth();
       // return sthe color depth.
       char **getColorDepth();

};

#endif

Text.cpp

#include "Text.h"

// constructor definition giving constructor call to its parent.
Text::Text(string name, string contents):File(name,"text") {
   characters = contents;
}

// returns size of file.
size_t Text::getSize() {
   return characters.size();
}

// display Properties of file.
void Text::displayProperties() {

   cout<<"File Name : "<    cout<<"File Type : "<    cout<<"File Size : "<    cout<<"File contents : "< }

// returns contents of file.
string Text::getCharacters() {
   return characters;
}

Text.h

#ifndef __TEXT_H__
#define __TEXT_H__

#include "File.h"

// class declaration with public inheritance of File class.
class Text: public File {

   public:
       // file contents.
       string characters;

       Text(string name, string contents);
       size_t getSize();
       void displayProperties();
       string getCharacters();

};

#endif

HOMEWORK 8 WAS

The aim of this homework assignment is to practice writing hierarchy of classes. 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 a file multiplied by number of bits to color a single bit divided by 8. The size of the Text file is calculated by counting number of ASCII characters stored in a file. 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. Provide function to retrieve character count for a Text file. Provide functions to retrieve dimensions and color depth of an Image File. Write .h and .cpp files for File, Image, and Text classes.

HOMEWORK 9 was

The aim of this homework assignment is to practice writing recursive functions. For this homework assignment write two recursive functions: The first one receives a vector of File pointers and recursively outputs properties of every file stored inside this vector. 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.

THANKS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

File.cpp
#include "File.h"

using namespace std;

File::File()
{
   name = "";
   type = "";
}

File::File(string t, string n)
{
   type = t;
   name = n;
}

string File::getType()
{
   return type;
}

string File::getName()
{
   return name;
}

void File::displayProperties()
{
   cout << "File Properties: " << endl;
   cout << "Name: " << name << endl;
   cout << "Type: " << type << endl;
}


File.h

#ifndef __Homework_8__File__
#define __Homework_8__File__

#include <iostream>

using namespace std;

class File
{
private:
   string type;
   string name;
  
public:
   File();
   File(string t, string n);
  
   string getType();
   string getName();

   // Pure Virtual function for size since that is calculated independently depending on the tye of file
   virtual int getSize() = 0;
  
   // Virtual function that displays properties based on file type.
   virtual void displayProperties();
  
};

#endif /* defined(__Homework_8__File__) */

Image.cpp


#include "Image.h"
#include "File.h"

using namespace std;

Image::Image(string t, string n) : File(t, n)
{
   rows = 0;
   columns = 0;
   depth = 0;
   size = (rows*columns*depth)/8;
}

Image::Image(string t, string n, int r, int c, int d) : File(t, n)
{
   rows = r;
   columns = c;
   depth = d;
   size = (rows*columns*depth)/8;
}

int Image::getRows()
{
   return rows;
}

int Image::getColumns()
{
   return columns;
}

int Image::getDepth()
{
   return depth;
}

// Pure Virtual Function
int Image::getSize()
{
   return size;
}

// Virtual Function
void Image::displayProperties()
{
   cout << "File Properties: " << endl;
   cout << "Type: " << getType() << endl;
   cout << "Name: " << getName() << endl;
   cout << "Dimensions: " << rows << " X " << columns << endl;
   cout << "Depth: " << depth << endl;
   cout << "Size: " << size << endl;
}

Image.h

#ifndef __Homework_8__Image__
#define __Homework_8__Image__

#include <iostream>
#include "File.h"

using namespace std;

class Image : public File
{
private:
   int rows;
   int columns;
   int depth;
   int size;

public:
   Image(string t, string n);
   Image(string t, string n, int r, int c, int d);
   int getRows();
   int getColumns();
   int getDepth();
      
   // Virtual Functions
   int getSize();
   void displayProperties();
  
};

#endif /* defined(__Homework_8__Image__) */


Text.cpp


#include "Text.h"
#include "File.h"

using namespace std;

Text::Text(string t, string n) : File(t, n)
{
   numcharacters = 0;
   size = 0;
}

Text::Text(string t, string n, int charactercount) : File(t, n)
{
   numcharacters = charactercount;
   size = numcharacters/8;
}

int Text::getNumcharacters()
{
   return numcharacters;
}

// Virtual Functions
int Text::getSize()
{
   return size;
}

void Text::displayProperties()
{
   cout << "File Properties: " << endl;
   cout << "Type: " << getType() << endl;
   cout << "Name: " << getName() << endl;
   cout << "Characters: " << numcharacters << endl;
   cout << "Size: " << size << endl;

}


Text.h

#ifndef __Homework_8__Text__
#define __Homework_8__Text__

#include <iostream>
#include "File.h"

using namespace std;

class Text : public File
{
private:
   int numcharacters;
   int size;
  
public:
   Text(string t, string n);
   Text(string t, string n, int charactercount);
  
   int getNumcharacters();
      
   // Virtual Functions
   int getSize();
   void displayProperties();

};

#endif /* defined(__Homework_8__Text__) */

Add a comment
Know the answer?
Add Answer to:
It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program: The aim of this homework assignment is to practice writing hierarchy of classes. Design...

    C++ program: The aim of this homework assignment is to practice writing hierarchy of classes. 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...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all th...

    My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Template...

    Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Template Classes – Chapter 12 Write an example of a template function that can swap 2 generic elements. Create a C++ class vector using the class diagram shown in Figure 12.2. in Liangs textbook. Do not use the C++ provided header file <vector>...

  • C++ problem with dynamic arrays is that once the array is created using the new operator...

    C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...

  • C++ Could you check my code, it work but professor said that there are some mistakes(check...

    C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private:    string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){    return name; } }; class Circle : public...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • I've written this program in C++ to compare 2 pizzas using classes and it works fine....

    I've written this program in C++ to compare 2 pizzas using classes and it works fine. I need to convert it to java using both buffered reader and scanner and can't get either to work. //C++ driver class for Pizza program #include <iostream> #include <string> #include <algorithm> #include <iomanip> using std::cout; using std::cin; using std::string; using std::endl; using std::transform; using std::setprecision; using std::ios; using std::setiosflags; #include "Pizza.h" int main() {             char response = 'Y';             while (response == 'Y')...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT