Question

In: Electrical Engineering

The major advantage of using structs is to make the C++ code simpler, easier to read,...

The major advantage of using structs is to make the C++ code simpler, easier to read, and easier to work with. After completing this assignment, students will be able to: • use structs to create and/or introduce new custom data types • implement structs to group fixed numbers of pieces of data of different types • implement structs within structs • chaining using the dot operators to access nested fields • copy an entire structure • create an array of a structured data type • combine structs and arrays with one another Task Description: A Decoration Store Manager wants you to create a program to keep track some of the best-selling items. You are given 4 files: Furnitire.txt, Art.txt, Fabric.txt, and Book.txt. Your task is to create an array of structs for each file to hold the entries. The first line of each file will be a number indicating how many entries are in the file. Furnitire.txt 1. Name 2. Color 3. Amount of Inventory 4. Date Created (month:day:year) 5. Price Art.txt 1. Name 2. Price 3. Amount of Inventory 4. Date Created (month:day:year) 5. Dimensions of Art (height:width:depth) Fabric.txt 1. Name 2. Color 3. Amount of Inventory 4. Price Book.txt 1. Name 2. Hardcover? (1 for yes 0 for no) 3. Amount of Pages 4. Price 5. Amount of Inventory 6. Date Published (month:day:year) Write a C++ program to help the Decoration Store Manager. Create four arrays of structs named Furniture, Art, Fabric, and Book. The size of the array should be read in from the file. Structs should be created to hold the variables that won’t fit a standard data type. The main() function of your program should be very simple. The main function should be a collection of variables declaration and functions call. You will need to use four different functions to read the data from the four files. You can add more functions if you want. You are to give the user the ability to print out each section’s records (Furniture, Art, Fabric, and Book). Do NOT use global variables.

These are the files given:

1) 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

2) 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

3) 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

4)

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

Solutions

Expert Solution

C++ code

#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<<"\n----------------------------------------"<<endl;
cout<<"\n*** Demonstration of Structure Array **"<<endl;
cout<<"\n----------------------------------------"<<endl;
cout<<"\n*** 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<<"\n------------------------------"<<endl;
cout<<"\nName\tPrice\tInventaryAmount\tData\tDimensions"<<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<<"\n-------------------------------"<<endl;
cout<<"\n****** Book Structure *********"<<endl;
cout<<"\n-------------------------------"<<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\t\tHardcpver\t\tAmount\t\tPrice\t\tAmount_pages\t\tDate"<<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<<"\n-------------------------------"<<endl;
cout<<"\n****** Furniture Structure *********"<<endl;
cout<<"\n-------------------------------"<<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\t\tColor\t\tAmount\t\tDate\t\tPrice"<<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<<"\n-------------------------------"<<endl;
cout<<"\n****** Fabric Structure *********"<<endl;
cout<<"\n-------------------------------"<<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\t\tColor\t\tAmount\t\tPrice"<<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;
}
Output:-

*** Demonstration of Structure Array **
----------------------------------------
*** Art Structure ****
------------------------------
Name Price InventaryAmount Data Dimensions
0 0
WaterColorPainting 25.95 20 07:02:2015 20:20:1
AcrylicPainting 10.22 89 06:15:2014 12:14:1
Photo 2.5 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.4 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
-------------------------------
****** Book Structure *********
-------------------------------
Name Hardcpver Amount Price Amount_pages Date
0 0 0 0
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
-------------------------------
****** Furniture Structure *********
-------------------------------
Name Color Amount Date Price
0 0
Table brown 10 01:16:2000 100
Chair black 20 05:14:2006 25.2
Couch brown 5 10:21:2015 325.5
LoveSeat yellow 3 09:08:2011 145.7
RockingChair red 15 06:03:2013 45.6
Desk brown 5 11:10:2004 50
Lamp blue 8 12:06:2014 10.95
Light grey 10 06:12:2003 11
Bed red 7 07:18:2006 150
HighChair white 11 08:22:2007 25.6
FootRest brown 5 08:23:2015 15.95
CoffeeTable white 0 06:25:2016 57.1
BedsideTable black 2 04:23:2015 45.23
-------------------------------
****** Fabric Structure *********
-------------------------------
Name Color Amount Price
0 0
WoolRug white 10 24.2
NaturalFiberRug red 21 18.65
Drapes brown 15 10.6
DoorMat green 50 21.2
TableMat red 60 5.95
CottonRug white 10 14.26
SyntheticRug blue 15 18.1
PlaceMat brown 26 2.55
ClothNapkins white 18 3.05



Related Solutions

Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would like to find another way to compile the program without using static_cast in my code. Thank you #include <iostream> #include <iomanip> using namespace std; class Population { private: int population, birth, death; public: Population() { population = 2; birth = 0; death = 0; } Population(int x, int y, int z) { if (x < 2) population = 0; else population = x; if...
Southwest Airlines: (Questions were in one, but separated to make easier to read.) Research on Southwest...
Southwest Airlines: (Questions were in one, but separated to make easier to read.) Research on Southwest Airlines 1.Relate Southwest’s Strategy to Michael Porter’s basic strategy. What strategic position are they seeking to obtain and hold? What are the key policies, procedures, operating practices, and core values underlying this strategy? 2.What are the key elements of Southwest’s culture? Does culture make a difference in their relative success as a business? 3.What weaknesses or problems do you seat Southwest through the case...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a dummy list for a company which stores following information about its customers. Customer ID Customer Name Gender Total items purchased Item category 20% discount in percentage of total purchase amount. Use dynamic array to save at least 20 items by dividing them into 3 different categories. Make a dummy list of items that company sells by dividing them into two categorizes. Items has following...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
Can someone make this code work without using template? C++ using namespace std; template < typename...
Can someone make this code work without using template? C++ using namespace std; template < typename T>    void print_array(T arr[], int size)    {        ofstream outfile;        outfile.open("/Users/android/Desktop/outfile.txt");        cout << "Printing Array: " << endl;        for (int i = 0; i < size; i++)        {            cout << arr[i] << endl;            outfile << arr[i] << endl;        }    } template < typename T>...
A major advantage of using the maximization of shareholder wealth as the primary goal of the...
A major advantage of using the maximization of shareholder wealth as the primary goal of the firm is that this goal considers the timing and the risk of the expected benefits to be received the investor's consumption utility the value of closely held partnerships all the above
QuickBooks: Why is it often easier to complete General Journal entries by using the Make General...
QuickBooks: Why is it often easier to complete General Journal entries by using the Make General Journal Entries form than it is to use the Register?
How can using styles make it easier to change the look and feel of your documents?...
How can using styles make it easier to change the look and feel of your documents? Describe an example of how you can use styles. You can include a style sample in an Word document. How would you go about customizing or creating your own style?
1. The major advantage to using statistical techniques is: a. it limits the risk of incorrect...
1. The major advantage to using statistical techniques is: a. it limits the risk of incorrect acceptance b. it relate sample size to audit risk c. it limits the risk of inefficiency d. it limits sample size to the smallest appropriate size 2. If the auditor is performing an audit of a nonpublic company and the client refuses to provide a management representation letter, the auditor may: a. issue a financial statement audit report b. issue an integrated audit report...
C Code Edit this code to make it output all unique letters IN LOWERCASE of an...
C Code Edit this code to make it output all unique letters IN LOWERCASE of an input file. For example, with this input: Raspberry Grapefruit Straw berry raspBERRY Blue$$berry apple Pine_apple raspberry The output should be: raspberry grapefruit straw berry blue berry apple pine NOTE: Words with different capitlization, like raspberry and raspBERRY count as 1 unique word, so raspberry should only be seen once in the output. #include <stdio.h> #include <stdlib.h> int main() {     //Pointer to access the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT