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

This exercise consist in two parts. Please we have to use the files given. Part

ID: 3903244 • Letter: T

Question

This exercise consist in two parts. Please we have to use the files given.

Part A:

Problem description: In this assignment, we will revisit Assignment #1 “the example of home decoration company that is attempting to run its storehouse more efficiently”. You will need to modify the program such that the company can make some critical decisions, including processing the received inventory of art, books, furniture, and fabric. This assignment needs the structs art, books, furniture, fabric, date, and dimension.

Processing inventory: The company wants to organize its inventory by cost from least to greatest. If the price of two items is the same, either one can be displayed first. You must use a member function of the appropriate corresponding struct to perform the comparison. Lastly print all items in order by cost. You will need to save the output into a text file named SequencedOrders.txt. You must use constructors to initialize all data variables in structs with default values at the beginning of the program. Use of global variables will incur a deduction of 10 points from your total points.

Part B:

Start a new Code::Blocks project for Part-B. Your task for this portion of the assignment is to choose one of these member functions which you used in part A of this assignment to perform the comparisons and make it a non-member function. You will need to make the appropriate changes accordingly. Your program should compile and run. The user of the program should not notice any difference when running the program with any of your implementations for Part-A and Part-B of this assignment. Clearly comment which function has been turned into a non-member function.

main.cpp given:

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

struct Date{

int day;

int month;

int year;

};

struct Dimension{

double width;

double height;

double depth;

};

struct Furniture{

string name;

string color;

int inventory;

Date dateCreated;

double cost;

};

struct Art{

string name;

double cost;

int inventory;

Date dateCreated;

Dimension artSize;

};

struct Fabric{

string name;

string color;

int inventory;

double cost;

};

struct Book{

string name;

bool hardCover;

int numPages;

double cost;

int inventory;

Date datePublished;

};

/**

These four functions are mandatory as instructed in the Assignment

**/

void getFurnitureData(ifstream& inFile);

void getArtData(ifstream& inFile);

void getFabricData(ifstream& inFile);

void getBookData(ifstream& inFile);

/**

Optional Helper Functions

**/

void displayFurniture(Furniture furniture[], int totalFurniture);

void displayArt(Art art[], int totalArt);

void displayFabric(Fabric fabric[], int totalFabric);

void displayBook(Book book[], int totalBook);

void printHorizontalLine( int width, char border_char);

void printHeading( string title, int width );

int main()

{

cout << "This is Assignment 1 (Structs) - Home Decoration Store" << endl;

/**

Declaring the input streams for each file

**/

ifstream inFileFurniture;

ifstream inFileArt;

ifstream inFileFabric;

ifstream inFileBook;

/**

Opening the files. You can either hardcode the name of the files or ask the user to give the names

**/

inFileFurniture.open("Furniture.txt");

inFileArt.open("Art.txt");

inFileFabric.open("Fabric.txt");

inFileBook.open("Book.txt");

/**

If the any of the file cannot be opened then the program terminates displaying

the error message

**/

if (!inFileFurniture)

{

cout << "The Furniture input file does not exist. Program terminates!" << endl;

//return 1;

}

if (!inFileArt)

{

cout << "The Art input file does not exist. Program terminates!" << endl;

return 1;

}

if (!inFileFabric)

{

cout << "The Fabric input file does not exist. Program terminates!" << endl;

return 1;

}

if (!inFileBook)

{

cout << "The Book input file does not exist. Program terminates!" << endl;

return 1;

}

/**

Display the prompt and do the requested action. Keep repeating the prompt until exit.

If the number entered is not an option, just repeat the prompt.

**/

int chosenOption;

do{

cout << " Select which option you would like to see "

<< "1. Print all Furniture "

<< "2. Print all Art "

<< "3. Print all Fabric "

<< "4. Print all Book "

<< "5. Exit "

<< " "

<< "Enter Option (1-5): ";

cin >> chosenOption;

/**

Do the correct action according to the chosenOption

**/

switch(chosenOption)

{

case 1:

/**

Furniture

Function call to read data from input file. That function then calls a print Function

**/

getFurnitureData(inFileFurniture);

break;

case 2:

/**

Art

Function call to read data from input file. That function then calls a print Function

**/

getArtData(inFileArt);

break;

case 3:

/**

Fabric

Function call to read data from input file. That function then calls a print Function

**/

getFabricData(inFileFabric);

break;

case 4:

/**

Book

Function call to read data from input file. That function then calls a print Function

**/

getBookData(inFileBook);

break;

default:

break;

}

}while(chosenOption != 5);

return 0;

}

void printHorizontalLine( int width, char border_char){

cout.fill( border_char );

cout << setw( width ) << border_char << " ";

cout.fill(' ');

}

void printHeading( string title, int width ){

//Declare Variables

int magic_width = 0;

magic_width = (width/2) - (title.length()/2) + title.length();

cout << " ";

cout << left << setfill('=') << setw( width ) << "=" << " ";

cout << right << setfill(' ') << setw( magic_width ) << title << " ";

cout << right << setfill('=') << setw( width ) << "=" << endl;

//reset count

cout.clear();

cout.fill(' ');

//VOID functions do NOT return a value

}

/**

Using the input stream sent as parameter we are reading the content from the Furniture.txt and storing it in the Furniture struct array

**/

void getFurnitureData(ifstream& inFile){

int totalFurniture;

inFile >> totalFurniture;

Furniture furniture[totalFurniture];

char decimal;

for(int i = 0; i < totalFurniture; i++){

inFile >> furniture[i].name;

inFile >> furniture[i].color;

inFile >> furniture[i].inventory;

inFile >> furniture[i].dateCreated.month >> decimal >> furniture[i].dateCreated.day >> decimal >> furniture[i].dateCreated.year;

inFile >> furniture[i].cost;

}

inFile.close();

printHeading("Furniture", 60);

displayFurniture(furniture,totalFurniture);

}

/**

Using the input stream sent as parameter we are reading the content from the fabric.txt and storing it in the fabric struct array

**/

void getFabricData(ifstream& inFile){

int totalFabric;

inFile >> totalFabric;

Fabric fabric[totalFabric];

for(int i = 0; i < totalFabric; i++){

inFile >> fabric[i].name;

inFile >> fabric[i].color;

inFile >> fabric[i].inventory;

inFile >> fabric[i].cost;

}

inFile.close();

printHeading("Fabric", 60);

displayFabric(fabric,totalFabric);

}

/**

Using the input stream sent as parameter we are reading the content from the Art.txt and storing it in the art struct array

**/

void getArtData(ifstream& inFile){

int totalArt;

inFile >> totalArt;

Art art[totalArt];

char decimal;

for(int i = 0; i < totalArt; i++){

inFile >> art[i].name;

inFile >> art[i].cost;

inFile >> art[i].inventory;

inFile >> art[i].dateCreated.month >> decimal >> art[i].dateCreated.day >> decimal >> art[i].dateCreated.year;

inFile >> art[i].artSize.width >> decimal >> art[i].artSize.height >> decimal >> art[i].artSize.depth;

}

inFile.close();

printHeading("Art", 60);

displayArt(art,totalArt);

}

/**

Using the input stream sent as parameter we are reading the content from the Personnel.txt and storing it in the Book struct array

**/

void getBookData(ifstream& inFile){

int totalBook;

inFile >> totalBook;

Book book[totalBook];

char decimal;

for(int i = 0; i < totalBook; i++){

inFile >> book[i].name;

inFile >> book[i].hardCover;

inFile >> book[i].numPages;

inFile >> book[i].cost;

inFile >> book[i].inventory;

inFile >> book[i].datePublished.month >> decimal >> book[i].datePublished.day >> decimal >> book[i].datePublished.year;

}

inFile.close();

printHeading("Books", 60);

displayBook(book,totalBook);

}

/**

Displaying the content from the Furniture struct array on the monitor

**/

void displayFurniture(Furniture furniture[], int totalFurniture){

cout << setw(10) << "Name" << " | "

<< "Color" << " | "

<< "Inventory" << " | "

<< "Date Created" << " | "

<< "Cost" << endl;

printHorizontalLine(80,'-');

for(int i = 0; i < totalFurniture; i++){

cout << left << setw(13) << furniture[i].name << " | "

<< right << setw(6) << setfill(' ') << furniture[i].color << " | "

<< right << setw(6) << setfill(' ') << furniture[i].inventory << " | "

<< right <<setw(2) << setfill('0') << furniture[i].dateCreated.month <<":" << setw(2) << setfill('0') << furniture[i].dateCreated.day <<":" << setw(2) << setfill('0') << furniture[i].dateCreated.year << " | "

<< right <<setw(9) << setfill(' ') << furniture[i].cost << " "

<< setfill(' ') << endl;

}

}

/**

Displaying the content from the Fabric struct array on the monitor

**/

void displayFabric(Fabric fabric[], int totalFabric){

cout << setw(15) << "Name" << " | "

<< "Color" << " | "

<< "Inventory" << " | "

<< "Cost" << endl;

printHorizontalLine(80,'-');

for(int i = 0; i < totalFabric; i++){

cout << left << setw(15) << setfill(' ') << fabric[i].name << " | "

<< right << setw(5) << setfill(' ') << fabric[i].color << " | "

<< right << setw(5) << setfill(' ') << fabric[i].inventory << " | "

<< right << setw(3) << setfill(' ') << fabric[i].cost << " "

<< setfill(' ') << endl;

}

}

/**

Displaying the content from the Art struct array on the monitor

**/

void displayArt(Art art[], int totalArt){

cout << setw(18) << "Name" << " | "

<< " Cost" << " | "

<< "Inventory" << " | "

<< "Date Created" << " | "

<< "Art Dimensions" << endl;

printHorizontalLine(80,'-');

for(int i = 0; i < totalArt; i++){

cout << left << setw(18) << art[i].name << " | "

<< right << setw(5) << art[i].cost << " | "

<< right << setw(4) << setfill(' ') << art[i].inventory << " | "

<< right << setw(2) << setfill('0') << art[i].dateCreated.month <<":" << setw(2) << setfill('0') << art[i].dateCreated.day <<":" << setw(2) << setfill('0') << art[i].dateCreated.year << " | "

<< right << setw(2) << setfill('0') << art[i].artSize.width <<":" << setw(2) << setfill('0') << art[i].artSize.height <<":" << setw(2) << setfill('0') << art[i].artSize.depth << " | "

<< setfill(' ') << endl;

}

}

/**

Displaying the content from the Personnel struct array on the monitor

**/

void displayBook(Book book[], int totalBook){

cout << setw(25) << "Name" << " | "

<< "Is Hardcover" << " | "

<< "Number Pages" << " | "

<< "Cost" << " | "

<< "Inventory" << " | "

<< "Date Published" << endl;

printHorizontalLine(80,'-');

for(int i = 0; i < totalBook; i++){

cout << left << setw(25) << book[i].name << " | "

<< right << setw(7) << setfill(' ') << book[i].hardCover << " | "

<< right << setw(9) << setfill(' ') << book[i].numPages << " | "

<< right << setw(9) << setfill(' ') << book[i].cost << " | "

<< right << setw(9) << setfill(' ') << book[i].inventory << " | "

<< right << setw(2) << setfill('0') << book[i].datePublished.month <<":" << setw(2) << setfill('0') << book[i].datePublished.day <<":" << setw(2) << setfill('0') << book[i].datePublished.year << " | "

<< setfill(' ') << endl;

}

}

Files:

Art.txt:

12
WaterColorPainting 25.95 20 07:02:2015 20:20:1
AcrylicPainting 10.22 89 06:15:2014 12:14:1
Photo 2.50 4 06:25:2017 10:10:1
LatexPainting 22.49 11 08:29:2015 18:13:1
PencilDrawing 5.25 56 05:01:2010 12:10:1
ClaySculpture 20.25 16 04:19:2011 12:12:3
GlassSculpture 15.40 40 09:05:2002 4:18:15
PlasticSculpture 2.96 22 05:20:2010 10:10:10
WoodenSculpture 27.89 9 03:11:2016 14:12:4
MetalSculpture 14.65 1 06:24:2013 18:15:7
ConcreteSculpture 3.69 0 03:29:2016 19:28:4
MarbleSculpture 29.99 16 06:15:2013 13:20:7

Book.txt:

16
PrideandPrejudice 1 209 10.99 10 04:01:2010
ToKillaMockingbird 0 276 10.99 3 03:10:2013
TheGreatGatsby 1 257 7.99 3 06:21:2000
JaneEyre 1 294 10.99 8 06:01:2005
TheCatcherintheRye 1 171 10.99 2 07:06:2006
LittleWomen 0 354 10.99 3 02:26:2008
HuckleberryFin 1 269 7.99 2 02:27:2015
MobyDick 0 278 10.99 1 07:13:2012
AliceinWonderland 1 494 10.99 7 08:17:2015
LordoftheFlies 1 133 10.99 1 06:06:2016
AnimalFarm 1 119 7.99 5 03:22:2015
GreatExpectations 0 287 10.99 9 06:13:2013
1984 0 275 10.99 8 04:14:2017
GreatExpectations 1 360 10.99 7 07:23:2016
Frakenstein 0 146 10.99 3 03:20:2010
TheScarletLetter 1 248 10.99 5 02:28:2014

Fabric.txt:

10
WoolRug white 10 24.20
NaturalFiberRug red 21 18.65
Drapes brown 15 10.60
DoorMat green 50 21.20
TableMat red 60 5.95
CottonRug white 10 14.26
SyntheticRug blue 15 18.10
PlaceMat brown 26 2.55
ClothNapkins white 18 3.05
Curtains grey 28 12.32

Furniture.txt:

14
Table brown 10 01:16:2000 100.00
Chair black 20 05:14:2006 25.20
Couch brown 5 10:21:2015 325.50
LoveSeat yellow 3 09:08:2011 145.70
RockingChair red 15 06:03:2013 45.60
Desk brown 5 11:10:2004 50.00
Lamp blue 8 12:06:2014 10.95
Light grey 10 06:12:2003 11.00
Bed red 7 07:18:2006 150.00
HighChair white 11 08:22:2007 25.60
FootRest brown 5 08:23:2015 15.95
CoffeeTable white 0 06:25:2016 57.10
BedsideTable black 2 04:23:2015 45.23
Stool brown 25 08:26:2014 20.00

Explanation / Answer

Below is your code.Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

#include<iostream>
#include<fstream>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
struct Furniture
{
char Name[100];
char Color[100];
double Amount;
char Date[100];
double Price;
};
struct Fabric
{
char Name[100];
char Color[100];
double Amount;
double Price;
};
struct Book
{
char Name[100];
int Hardcover;
double Amount_pages;
double Price;
double Amount_Inventory;
char Date_Published[100];
};
struct Art{
char Name[100];
double Price;
int Amount_Inventory;
char Date_Created[100];
char Dimensions_Art[100];
};
int main()
{
struct Art ArtArray[100];
struct Book BookArray[100];
struct Furniture FurnitureArray[100];
struct Fabric Fabricarray[100];
cout<<" ----------------------------------------"<<endl;
cout<<" ** Demonstration of Structure Array *"<<endl;
cout<<" ----------------------------------------"<<endl;
cout<<" ** Art Structure ***"<<endl;
ifstream artfile,bookfile,furniturefile,fabricfile;
char Name[100];
char Date[100],Dimensions[100];
double price,Amount;
artfile.open("Art.txt");
int i=0,art_length,book_length,FurnitureLength,FabricLength;
while(i<13)
{
if(i==0)
{
artfile>>art_length;
}
else
{
artfile>>Name;
strcpy(ArtArray[i].Name,Name);
artfile>>price;
ArtArray[i].Price=price;
artfile>>Amount;
ArtArray[i].Amount_Inventory=Amount;
artfile>>Date;
strcpy(ArtArray[i].Date_Created,Date);
artfile>>Dimensions;
strcpy(ArtArray[i].Dimensions_Art,Dimensions);
}
i++;
}
artfile.close();
cout<<" ------------------------------"<<endl;
cout<<" Name Price InventaryAmount Data Dimensions"<<endl;
for(int i=0;i<art_length;i++)
{
cout<<ArtArray[i].Name<<setw(20)
<<ArtArray[i].Price<<setw(20)
<<ArtArray[i].Amount_Inventory<<setw(20)
<<ArtArray[i].Date_Created<<setw(20)
<<ArtArray[i].Dimensions_Art<<endl;
}
cout<<" -------------------------------"<<endl;
cout<<" *** Book Structure ****"<<endl;
cout<<" -------------------------------"<<endl;
bookfile.open("Book.txt");
i=0;
while(i<17)
{
if(i==0)
{
bookfile>>book_length;
}
else
{
bookfile>>BookArray[i].Name;
bookfile>>BookArray[i].Hardcover;
bookfile>>BookArray[i].Amount_Inventory;
bookfile>>BookArray[i].Price;
bookfile>>BookArray[i].Amount_pages;
bookfile>>BookArray[i].Date_Published;
}
i++;
}
bookfile.close();
cout<<"Name Hardcpver Amount Price Amount_pages Date"<<endl;
for(int i=0;i<book_length;i++)
{
cout<<BookArray[i].Name<<setw(20)
<<BookArray[i].Hardcover<<setw(20)
<<BookArray[i].Amount_Inventory<<setw(20)
<<BookArray[i].Price<<setw(20)
<<BookArray[i].Amount_pages<<setw(20)
<<BookArray[i].Date_Published<<endl;
}
cout<<" -------------------------------"<<endl;
cout<<" *** Furniture Structure ****"<<endl;
cout<<" -------------------------------"<<endl;
furniturefile.open("Furniture.txt");
i=0;
while(i<15)
{
if(i==0)
{
furniturefile>>book_length;
}
else
{
furniturefile>>FurnitureArray[i].Name;
furniturefile>>FurnitureArray[i].Color;
furniturefile>>FurnitureArray[i].Amount;
furniturefile>>FurnitureArray[i].Date;
furniturefile>>FurnitureArray[i].Price;
}
i++;
}
furniturefile.close();
cout<<"Name Color Amount Date Price"<<endl;
for(int i=0;i<book_length;i++)
{
cout<<FurnitureArray[i].Name<<setw(20)
<<FurnitureArray[i].Color<<setw(20)
<<FurnitureArray[i].Amount<<setw(20)
<<FurnitureArray[i].Date<<setw(20)
<<FurnitureArray[i].Price<<endl;
}
cout<<" -------------------------------"<<endl;
cout<<" *** Fabric Structure ****"<<endl;
cout<<" -------------------------------"<<endl;
fabricfile.open("Fabric.txt");
i=0;
while(i<11)
{
if(i==0)
{
fabricfile>>FabricLength;
}
else
{
fabricfile>>Fabricarray[i].Name;
fabricfile>>Fabricarray[i].Color;
fabricfile>>Fabricarray[i].Amount;
fabricfile>>Fabricarray[i].Price;
}
i++;
}
fabricfile.close();
cout<<"Name Color Amount Price"<<endl;
for(int i=0;i<FabricLength;i++)
{
cout<<Fabricarray[i].Name<<setw(20)
<<Fabricarray[i].Color<<setw(20)
<<Fabricarray[i].Amount<<setw(20)
<<Fabricarray[i].Price<<endl;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote