Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the Panel class per this Module. ( Write a class means to write an H and a CPP , named as the class

Write the Panel class per this Module. ("Write a class" means to write an H and a CPP, named as the class is named.) Test it with this _testPanel.cpp:
// c++_testPanel.cpp Panel.cpp
#include
using namespace std;
#include "Panel.h"
int main()
{
Panel p;
p.addButton("1");
p.addButton("2");
p.addButton("3");
p.addButton("4");
if (p.areAnyLit()) cout <<"
ERROR 1
";
if (p.isLit("2")) cout <<"
ERROR 2
";
p.press("X");
p.press("2");
p.press("3");
cout <<"
EXPECTED: [2][3]
";
cout << "ACTUAL: "<< p << endl;
p.clear("Y");
p.clear("2");
cout <<"
EXPECTED: [3]
";
cout << "ACTUAL: "<< p << endl;
cout <<"
EXPECTED: 3
";
cout << "ACTUAL: "<< p.getFirstLit()<< endl;
if (!p.areAnyLit()) cout <<"
ERROR 3
";
if (p.isLit("2")) cout <<"
ERROR 4
";
if (!p.isLit("3")) cout <<"
ERROR 5
";
}
This will be the first full and complete "building block" in our elevator simulation.
Here are some hints:
1. In the stream insertion operator, use something like panel.buttons[i].isLit to access the "is it lit?" attribute Button at index i in the vector of Button objects owned by the parameter object " panel ".
2. In the member functions, use an unsigned int in the for-loops that traverse the vector of buttons, like this: for (unsigned int i =0; i < host.buttons.size(); i++).
3. In Panel::getFirstLit(), traverse the vector of buttons, looking only at the lit ones. Find the one with the lowest sequence number and return its label. If none are lit, return a blank string.
Note -- there is no need for a stream insertion operator for the Button class.
Compile like this (commend line statement): you won't need it if the program running from the IDE but a driver program.
c++-std=c++11_testPanel.cpp Panel.cpp -Wall
Submit the Panel.cpp and Panel.h. DON'T submit _testPanel.cpp
** For this course, any user defined classes will have the header file (classname.h) includes the class declaration only and the source file (classname.cpp) includes the member function implementation only. There will be another *.cpp file as the driver program including the main() function.
Panel class declaration (Panel.h example)
class Panel
{
struct Button
{
string label;
bool lit;
int sequence;
static int count;
};
vector buttons;
public:
void addButton(string);
void press(string);
void clear(string);
string getFirstLit() const;
bool isLit(string) const;
bool areAnyLit() const;
friend ostream& operator<<(ostream&, const Panel&);
};
Panel class member function implementations will be in the Panel.cpp
Include all three files (Panel.h, Panel.cpp and _testPanel.cpp ) in the project and check if the outputs correct before submission. If there is any "ERROR" in the console output, make sure to correct your work before the submission.

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books