deptmain.cpp /* * Apparel Dept program * For Lab 4 * * Create two separate files
ID: 3857779 • Letter: D
Question
deptmain.cpp
/*
* Apparel Dept program
* For Lab 4
*
* Create two separate files called apparel.cpp and apparel.h
* to be compiled with this file.
* DO NOT CHANGE THIS FILE!. I will be using an exact copy of this file
* with different data to compile your code with so whatever changes
* are made will not be used when I grade your lab submission.
*
*/
#include <cstdlib>
#include <iostream>
#include <cstring>
#include "apparel.h"
using namespace std;
int main()
{
Apparel array[2]; // note that this uses the default constructor
char name[MAX_STR];
char type[MAX_STR];
char color[MAX_STR];
float size;
int stock;
cout << "Just after array is created" << endl;
for(int i=0; i<2; i++)
{
cout << "printing " << i << " apparel in array" << endl;
array[i].print();
}
// note that this uses the non-default constructor
Apparel shoe1("Keds Tennis Shoes","shoe","white", 7.5, 6);
cout << "Printing the shoe1 info " << endl;
shoe1.print();
cout << "Changing size to -3 (this should print an error and not change the value)" << endl;
shoe1.setSize(-3);
cout << "size is now " << shoe1.getSize() << endl;
cout << "setting array values and getting values of array" << endl;
for(int i=0; i<2; i++)
{
cout << "for apparel " << i << endl;
cout << "name?";
cin.getline(name, MAX_STR);
array[i].setName(name);
cout << "type?";
cin.getline(type, MAX_STR);
array[i].setType(type);
cout << "color?";
cin.getline(color, MAX_STR);
array[i].setColor(color);
cout << "size?";
cin >> size;
cin.ignore();
array[i].setSize(size);
cout << "how many in stock?";
cin >> stock;
cin.ignore();
array[i].setInStock(stock);
}
for(int i=0; i<2; i++)
{
cout << "getting apparel " << i << " information " << endl;
array[i].getName(name);
cout << "name: " << name << endl;
array[i].getType(type);
cout << "type: " << type << endl;
array[i].getColor(color);
cout << "color: " << color << endl;
cout << "size: " << array[i].getSize() << endl;
cout << "in stock: " << array[i].getInStock() << endl;
}
return 0;
}
Code should be in C++
We will be practicing designing a class for the clothing department of a store. Download the file called deptmain.cpp. You must use this file as I will be using the same exact file when compiling your code. Please don't change deptmain.cpp at all as your changes will not be used when I grade your submission. Note that deptmain.cpp makes an array of three Apparel objects. Your task is to design the class Apparel. You need to make two extra files to do this: a apparel.cpp file and a apparel.h file. The Apparel class has five attributes or fields: name, type, color, size and stock amount. The name, type and color are C-strings of length 200 and the size and stock are positive integers. These fields should not be public; make them private. Also, implement a full set of setters and getters plus a print apparel function; these should be public. You will also create a default constructor which will set strings to empty and size/stock to zero. HINT: To set a C-string to empty, it is sufficient to just set the first index to the null character: name [0] 0'; = Using a make file when compilingExplanation / Answer
//Apparel Header file
class Apparel //Apparel Class
{
private:
char name[200];
char type[200];
char color[200];
unsigned int size;
unsigned int stock;
public:
Apparel() //constructor
{
name[0]='';
type[0]='';
color[0]='';
size=0;
stock=0;
}
//setters
void setName(char * name)
{
this->name=name;
}
void setType(char * type)
{
this->type=type;
}
void setColor(char * color)
{
this->color=color;
}
void setSize(unsigned int size)
{
this->size=size;
}
void setInStock(unsigned int stock)
{
this->stock=stock;
}
//getters
const char* getName()
{
return this->name;
}
const char* getType()
{
return this->type;
}
const char* getColor()
{
return this->color;
}
unsigned int getSize()
{
return this->size;
}
unsigned int getInStock()
{
return this->stock;
}
//print Apparel
void print()
{
cout<<"======Apparel======"<<endl;
cout<<"name:"<<this->name<<endl;
cout<<"type:"<<this->type<<endl;
cout<<"color:"<<this->color<<endl;
cout<<"size"<<this->size<<endl;
cout<<"in stock"<<this->stock<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.