Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Using C++) This program should contain seperate header files and cpp files for

ID: 3915173 • Letter: #

Question

(Using C++) This program should contain seperate header files and cpp files for each of the following: Appliances, dish washer, over and refrigerator.

The lab problem: An appliances store needs your help to build a simple application that reads a shipping manifest of the newly arrived appliances at the store and prints a list of them on the computer screen.

You do not know all appliance that the store receives. Currently, the store receives and sells only ovens, dishwashers, and refrigerators, but plans to extend in the future and add more appliances. Therefore, your application must be able to easily handle new types of appliances that will be added in the future with minimal code change (and utilize code reusability). This is a scenario where you need to use the concept of polymorphism and pointers to handle different types of classes using their base class.

Input File: You are given an input file containing the most recent shipping manifest from the factory. It contains the data for an unknown (to your program) number of appliances (you can assume there are no more than 100.) Each begins with a single upper-case letter; 'R' if the appliance is a refrigerator, 'D' for a dishwasher, 'O' for an oven. This is followed by the appliance's data, which varies depending on its type.

Your application must have a base class, Appliance, with two private data members, modelNumber and serialNumber, both are string types. Each of these data members has setters and getters. Derive three classes from this base class as follows:

·       Refrigerator. A refrigerator has a capacity in cubic feet (a float, default value 0), and may or may not be frost-free (a boolean, default value false). The boolean value is stored in input and output as 'T' for true and 'F' for false.

·       Dishwasher. A dishwasher has a cycle time in minutes (integer) and has options for water saver mode or optional high-temperature dry (both booleans, input/output as 'T' or 'F')

·       Oven. An oven has a size in cubic feet (a float) and may or may not be self-cleaning (stored as a bool, input/output is 'S' for self-cleaning, 'R' for regular) or have a convection option (another boolean, input/output as 'C' if convection, 'R' for regular).

Virtual Functions:

·       Each appliance has a ReportType() const method that returns a string: 'Refrigerator', 'Dishwasher', or 'Oven'. This should be defined as a pure virtual function in the parent (Appliance) and separately written for the child classes.

·       Each appliance has method ReadData(istream&) to read its data. This method is a void method. This must be defined in the parent class as a pure virtual function and implemented in each of the child classes.

·       Each appliance has void method WriteData() const that writes the data of the appliance. This must be defined in the parent class as a virtual function and implemented in each of the child classes. The parent class definition prints the model and serial numbers of the appliance; and must be called in each of the child classes’ definitions to print the serial and model numbers before printing the other information.

Main application:

Your main program should have an array of 100 pointers to Appliance, called InStock []. As you read the data file, begin by reading the object's type. Based on the type, create a dynamic object of that type and store it in the array, InStock[], (Hint: you can use switch-case.) Then call the ReadData() method using the new object to get the data from the file for that object. After reading the entire file, call WriteStuff() function (more details below), to print the list of appliances on the screen grouped by their type. See figure 1.

Write a void WriteStuff(Appliance* items[], int Count, const string& TargetType) function in the main file to print on the screen the appliances stored in the array, each appliance printed based on its type, by calling the WriteData() function. This should be done by iterating over the array of pointers three times and using the ReportType() method to select only one type of appliance at a time.

After printing the list, delete all of the dynamically created variables using a loop at the end of the main function.

Text File: appliances.txt

R AFSD243509 78902349078 6.5 T
D ACME234890 79802347098 48 T F
R AFSD234999 23479084238 6.8 F
O ACM9234023 70982347908 3.3 R R
D ACME234790 79802347809 55 T T
O ACM9802349 23490782348 3.5 R C
O ACM9082349 23490823022 3.3 S C

Recived the following applinces (total: 7) lovens : ACM9234023 70982347908 3.3 R R ACM9802349 23490782348 3.5 R C ACM9082349 23490823022 3.3 S C Dishwashers ACME234890 79802347098 48 T F ACME234790 79802347809 55 TT Refrigerators AFSD243509 78902349078 6.5 T AFSD234999 23479084238 6.8F Cleaning the freestore....Done! Press any key to continue . .

Explanation / Answer

here is your files : --------->>>>>>>

Main.c : ---------->>>>>>


#include "Dishwasher.h"
#include "Oven.h"
#include "Refrigerator.h"

void WriteStuff(Appliance *InStock[],int count,const string &type){
cout<<" "<<type<<"s:";
for(int i = 0;i<count;i++){
  if(type == InStock[i]->ReportType()){
   InStock[i]->WriteData();
  }
}
}

int main(){
Appliance *InStock[100];
ifstream ifile;
int num = 0;
ifile.open("Appliances.txt");
if(!ifile.is_open()){
  cout<<" Appliances File Does Not Opened Please check File !!! ";
  return -1;
}
char type;
for(int i = 0;i<100;i++){
  if(ifile.eof()){
   break;
  }
  ifile>>type;
  switch(type){
   case 'D':
    {
     InStock[num++] = new Dishwasher();
     InStock[num-1]->ReadData(ifile);
     break;
    }
   case 'R':
    {
     InStock[num++] = new Refrigerator();
     InStock[num-1]->ReadData(ifile);
     break;
    }
   case 'O':
    {
     InStock[num++] = new Oven();
     InStock[num-1]->ReadData(ifile);
     break;
    }
  }
}
num--;
cout<<"Received the following appliances(total:"<<num<<") ";
WriteStuff(InStock,num,"Oven");
cout<<endl;
WriteStuff(InStock,num,"Dishwasher");
cout<<endl;
WriteStuff(InStock,num,"Refrigerator");
cout<<" Cleaning the freestore........Done!";
for(int i = 0;i<num;i++){
  delete InStock[i];
}

return 0;
}

Appliances.h : ------------->>>>>>>>

#ifndef APPLIANCES_H
#define APPLIANCES_H

#include<iostream>
#include<fstream>

using namespace std;

class Appliance{
private:
  string modelNumber;
  string serialNumber;
  
public:
  //constructors
  Appliance(){
   modelNumber = "";
   serialNumber = "";
  }
  Appliance(string mN,string sN){
   setModelNumber(mN);
   setSerialNumber(sN);
  }
  //setters
  void setModelNumber(string mN){
   modelNumber = mN;
  }
  
  void setSerialNumber(string sN){
   serialNumber = sN;
  }
  //getters
  string getModelNumber()const{
   return modelNumber;
  }
  string getSerialNumber()const{
   return serialNumber;
  }
  
  //virtual functions
  virtual string ReportType()const = 0;
  virtual void ReadData(istream &) = 0;
  virtual void WriteData()const{
   cout<<" "<<modelNumber<<" "<<serialNumber;
  }
};

#endif

Dishwasher.h : ------------>>>>>>>>>>>

#ifndef DISHWASHER_H
#define DISHWASHER_H
#include "Appliances.h"

class Dishwasher:public Appliance{
private:
  int cycleTime;
  bool wsMode;
  bool ht;
public:
  Dishwasher():Appliance(){
   cycleTime = 0;
   wsMode = false;
   ht = false;
  }
  
  //virtual functions
  string ReportType()const{
   return "Dishwasher";
  }
  void ReadData(istream &is){
   string mN,sN;
   char T;
   is>>mN>>sN>>cycleTime>>T;
   setModelNumber(mN);
   setSerialNumber(sN);
   if(T == 'T'){
    wsMode = true;
   }else{
    wsMode = false;
   }
   is>>T;
   if(T == 'T'){
    ht = true;
   }else{
    ht = false;
   }
  }
  
  void WriteData()const{
   Appliance::WriteData();
   cout<<" "<<cycleTime;
   if(wsMode){
    cout<<" T";
   }else{
    cout<<" F";
   }
   if(ht){
    cout<<" T";
   }else{
    cout<<" F";
   }
  }
  
};

#endif

Oven.h : ------------>>>>>>>>>>>

#ifndef OVEN_H
#define OVEN_H
#include "Appliances.h"

class Oven:public Appliance{
private:
  float size;
  bool sC;
  bool conv;
public:
  Oven():Appliance(){
   size = 0;
   sC = false;
   conv = false;
  }
  
  //virtual functions
  string ReportType()const{
   return "Oven";
  }
  void ReadData(istream &is){
   string mN,sN;
   char T;
   is>>mN>>sN>>size>>T;
   setModelNumber(mN);
   setSerialNumber(sN);
   if(T == 'T'){
    sC = true;
   }else{
    sC = false;
   }
   is>>T;
   if(T == 'T'){
    conv = true;
   }else{
    conv = false;
   }
  }
  
  void WriteData()const{
   Appliance::WriteData();
   cout<<" "<<size;
   if(sC){
    cout<<" S";
   }else{
    cout<<" R";
   }
   if(conv){
    cout<<" S";
   }else{
    cout<<" R";
   }
  }
  
};

#endif

Refrigerator.h : ----------------->>>>>>>>>>>

#ifndef REFRIGERATOR_H
#define REFRIGERATOR_H
#include "Appliances.h"

class Refrigerator : public Appliance{
private:
  float capacity;
  bool frost_free;
  
public:
  //constructor
  Refrigerator():Appliance(){
   capacity = 0;
   frost_free = false;
  }

  //virtual functions
  string ReportType()const{
   return "Refrigerator";
  }
  void ReadData(istream &is){
   string mN,sN;
   char T;
   is>>mN>>sN>>capacity>>T;
   setModelNumber(mN);
   setSerialNumber(sN);
   if(T == 'T'){
    frost_free = true;
   }else{
    frost_free = false;
   }
  }
  void WriteData()const{
   Appliance::WriteData();
   cout<<" "<<capacity;
   if(frost_free){
    cout<<" T";
   }else{
    cout<<" F";
   }
  }
  
};

#endif