Create a class called Lamp that has the following attributes

Create a class called Lamp that has the following attributes: enum STATE: only two possible values {ON, OFF} static constant ac_power: initialized to a value of 60.0 protected data: length: length of the lamp height: height of the lamp width: width of the lamp watts: the number of watts of the current light bulb used in the lamp brand: the brand of the lamp state: a variable of type STATE that is either ON or OFF public methods include: constructor with no arguments: sets all internal data to \"-1\" destructor: cleans up memory bool set_brand(char* arg): sets the variable \"name\" to arg. bool debug(FILE* fp): prints out the values of all internal data in the class; assume fp is a value file pointer that points to an open file (e.g., stdout). Also create a main program called foo.ee (binary is \"foo\"), that supports the following interface: foo Hirsch Tiffany foo Hirsch Tiffany Stiffel foo Hirsch Tiffany Stiffel... This program handles a variable number of arguments (e.g., 7 different lamp brands). It creates an array of objects Lamp and creates one object for each lamp specified from the command line. I can specify any values from the command line (e.g., don\'t hardcode \"Tiffany\"). Once the objects are created, you will write a loop over the array that calls the debug method for each object. The only output from your program will be this debugging output showing the values of the class data. No other data should appear on the output stream. Before the program exists, make sure memory is properly cleaned up. You will turn in four files: Makefile foo.cc: contains only the main program foo.h: contains the header file defining the class foo_00.cc: contains the implementations for all class methods

Solution

// LAMP.h
#ifndef LAMP_H
#define LAMP_H

class LAMP
{
int length;
int height;
int width;
int watts;
char* brand;
string state;

public:
LAMP();
~LAMP();
bool set_brand(char* arg);
bool debug(FILE* fp);
};
#endif

----------------------------------------------------------------------------------
// LAMP.cpp
#include \"LAMP.h\"
#include <fstream>
#include<iostream>

using namespace std;
// constructor
LAMP::LAMP()
{
length = -1;
height = -1;
width = -1;
watts = -1;
brand = \"new\";
state = \"OFF\";
}
// destructor
LAMP::~LAMP(){
}
// class methods impleementing
LAMP :: bool set_brand(char* arg){
   this->brand = arg;
}
LAMP::bool debug(FILE* fp){
   ofstream outputfile;
outputfile.open (fp);
   fp<<length;
   fp<<height;
   fp<<width;
   fp<<watts;
   fp<<brand;
   fp<<state;
   return true;
}
//main stsrts here
int main(){
`   // creating object
   LAMP obj;
   cout<<obj.set_brand(\"PHILIPS\");
   return 0;
}

 Create a class called Lamp that has the following attributes: enum STATE: only two possible values {ON, OFF} static constant ac_power: initialized to a value o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site