Question
The LabelMaker Please note that you can (and probably should) add more member functions to make the DIY part work better or more efficiently. Make
The LabelMaker
Please note that you can (and probably should) add more member functions to make the DIY part work better or more efficiently.
Make a program in two modules for a Label Maker application:
The Two modules are used as follows to print labels:
Sample main
///////////////////////////////////////////// #include#include "Label.h" #include "LabelMaker.h" using namespace sdds; using namespace std; int main() { int noOfLabels; // make a lable for the program title // and couple of empty ones: Label theProgram("/-\\|/-\\|", "The Label Maker Program"), EmptyOne1, EmptyOne2("ABCDEFGH"); theProgram.printLabel() << endl << endl; // ask for number of labels to get created cout << "Number of labels to create: "; cin >> noOfLabels; cin.ignore(10000, ' '); // Create a LabelMaker for the number of // the labels requested LabelMaker lblMkr(noOfLabels); // Ask for the label texts lblMkr.readLabels(); // Print the labels lblMkr.printLabels(); return 0; }
DIY Execution sample
EmptyOne1 EmptyOne2 /-------------------------\ | | | The Label Maker Program | | | \-------------------------/ Number of labels to create: 3 Enter 3 labels: Enter label number 1 > Introduction to Programming Using C Enter label number 2 > Introduction to Object Oriented Programming Enter label number 3 > Object-Oriented Software Development Using C++ +-------------------------------------+ | | | Introduction to Programming Using C | | | +-------------------------------------+ +---------------------------------------------+ | | | Introduction to Object Oriented Programming | | | +---------------------------------------------+ +------------------------------------------------+ | | | Object-Oriented Software Development Using C++ | | | +------------------------------------------------+
The Label Module
The label class makes a label by drawing a frame around a one-line text with an unknown size (maximum of 70 chars,must be kept dynamically).
The frame is dictated by series of 8 characters in a Cstring. These characters indicate how the frame is to be drawn:
character 1: top left corner character. character 2: character to repeat for the top line. character 3: top right corner character character 4: character to repeat for the right line. character 5: bottom right corner character character 6: character to repeat for the bottom line. character 7: bottom left corner character character 8: character to repeat for the left line.
For example the following CString:"AbCdEfGh"
will generate the following frame around a text:
AbbbbbbbbbbbbbbbbbbbbbbbbbC h d h d h d GfffffffffffffffffffffffffE
Mandatory constructors and methods:
Label()
Creates an empty label and defaults the frame to"+-+|+-+|"
Label(const char* frameArg)
Creates an empty label and sets the frame to theframeArgargument.
Label(const char* frameArg, const char* content)
Creates a Label with theframeset toframeArgand the content of the Label set to the corresponding argument. Note that you must keep the content dynamically even though it should never be more than 70 characters.
destructor
Makes sure there is no memory leak when the label goes out of scope.
void readLabel();
Reads the label from console up to 70 characters and stores it in the Label as shown in theExecution sample
std::ostream& printLabel()const;
Prints the label by drawing the frame around the content ad shown in theExecution sample. Note that no newline is printed after the last line and cout is returned at the end.
The LabelMaker Module
The LabelMaker class creates a dynamic array of Labels and gets their content from the user one by one and prints them all at once.
Mandatory constructors and methods:
LabelMaker(int noOfLabels);
creates a dynamic array of Labels to the size ofnoOfLabels
void readLabels();
Gets the contents of the Labels as demonstrated in theExecution sample
void printLabels();
Prints the Labels as demonstrated in theExecution sample
~LabelMaker();
Deallocates the memory when LabelMaker goes out of scope.
Modify the tester program to test are the different circumstances/cases of the application if desired and note that the professor's tester may have many more samples than the tester program here.
w4_tester.cpp
// Workshop 4:
// Version: 0.9
// Date: 2021/02/04
// Author: Fardad Soleimanloo
// Description:
// This file tests the DIY section of your workshop
/////////////////////////////////////////////
#include
#include "Label.h"
#include "LabelMaker.h"
using namespace sdds;
using namespace std;
int main() {
int noOfLabels;
// make a lable for the program title:
Label
theProgram("/-\\|/-\\|", "The Label Maker Program"),
EmptyOne1,
EmptyOne2("ABCDEFGH");
cout << "EmptyOne1" << endl;
EmptyOne1.printLabel() << endl;
cout << "EmptyOne2" << endl;
EmptyOne2.printLabel() << endl;
theProgram.printLabel() << endl << endl;
// ask for number of labels to get created
cout << "Number of labels to create: ";
cin >> noOfLabels;
cin.ignore(10000, ' ');
// make a LabelMaker for the number of
// the labels requested
LabelMaker lblMkr(noOfLabels);
// Ask for the label texts
lblMkr.readLabels();
// Print the labels
lblMkr.printLabels();
return 0;
}
cstring.h
#ifndef SDDS_CSTRING_H_
#define SDDS_CSTRING_H_
namespace sdds {
}
#endif // !SDDS_CSTRING_H_
canister.cpp
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include "cstring.h"// using strLen, strCpy and strCmp
#include "Canister.h"
using namespace std;
namespace sdds {
}
canister.h
#ifndef SDDS_BOX_H
#define SDDS_BOX_H
#include
namespace sdds {
class Canister {
char* m_contentName;
double m_diameter; // in centimeters
double m_height;// in centimeters
double m_contentVolume;// in CCs
bool m_usable;
void setToDefault();
void setName(const char* Cstr);
bool isEmpty()const;
bool hasSameContent(const Canister& C)const;
public:
Canister();
Canister(const char* contentName);
Canister(double height, double diameter,
const char* contentName = nullptr);
~Canister();
Canister& setContent(const char* contentName);
Canister& pour(double quantity);
Canister& pour(Canister&);
double volume()const;
std::ostream& display()const;
double capacity()const;
void clear();
};
}
#endif // !SDDS_BOX_H
canisterMain.cpp
// Workshop 4:
// Version: 0.9
// Date: 2021/02/04
// Author: Fardad Soleimanloo
// Description:
// This file tests the lab section of your workshop
/////////////////////////////////////////////
#include
#include "Canister.h"
using namespace std;
using namespace sdds;
void showCans(const char* title, const Canister* boxArray, int num = 1);
int main() {
int i;
Canister C[]={
Canister(),
Canister(nullptr),
Canister("Orange Juice"),
Canister(40,30),
Canister(20, 10, "Olive Oil"),
Canister(9,20, "Bad ones"),
Canister(20,9),
Canister(41,20, "Bad ones"),
Canister(20,31, "Bad ones")
};
showCans("Five good ones and 4 bad ones:", C, 9);
for (i = 5; i < 9; i++) C[i].clear();
showCans("All good:", C, 9);
C[5].setContent("Milk").pour(500);
C[6].setContent("MilK");
showCans("Milk canisters", &C[5], 2);
C[6].pour(C[5]);
showCans("Poured one into another", &C[5], 2);
showCans("Poured 800ccs into the empty canister", &C[5].pour(800), 1);
C[6].pour(C[5]);
showCans("Filled one with the milk from another", &C[5], 2);
showCans("Poured 1500ccs of Olive oil into Olive oil canister", &C[4].pour(1500), 1);
C[5].pour(C[4]);
showCans("Filled can of milk with olive oil", &C[4], 2);
showCans("Poured too much into olive oil canister", &C[4].pour(1500), 1);
for (i = 3; i < 9; i++) C[i].setContent(nullptr);
showCans("All bad", &C[3], 6);
return 0;
}
void showCans(const char* title, const Canister* canArray, int num ) {
cout << " " << title << endl;
cout << " Capacity,DimensionsVolumeContent" << endl;
cout << "------------------------------------------------------------------" << endl;
for (int i = 0; i < num; i++) {
canArray[i].display() << endl;
}
cout << "------------------------------------------------------------------------" << endl << endl;
}
cstring.cpp
#include "cstring.h"
namespace sdds {
}
cstring.h
#ifndef SDDS_CSTRING_H_
#define SDDS_CSTRING_H_
namespace sdds {
}
#endif // !SDDS_CSTRING_H_
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started