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

(10%) Be sure that you zip up the entire folder that contains all of the files a

ID: 3806693 • Letter: #

Question


(10%) Be sure that you zip up the entire folder that contains all of the files and the project before uploading.
(10%)Both programs #2 and #3 ask you to create arrays. use vectors instead.

Program #3: (30%) Create a class called suit that contains fields for type of material, size, style, and price. Create a class called shoes that contains fields for size, style, and price. overload both the insertion and extraction operators to get data from the user for each object. Create an array of 4 suits and an array 3 shoes (or if using vectors until the user decides to quit). Randomly pick one suit and a pair of shoes, create a function that will accept both objects and display the entire outfit randomly selected. Overload the operator to add a pair of shoes and a suit and return the total price. Overload aperator to compare the price of the suits. Use your array of suits and your overloaded operator to find the most expensive suit and display its price save the file as suits.cpp and upload to the Suit Program in Moodie.

Explanation / Answer

Given below is the suits.cpp file containing all the implemntation. Output shown at end. Please don't forget to rate the answer if ti helped. Thank you very much.

#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
class suit
{
private:
string material;
int size;
string style;
double price;
public:
suit()
{
size = 0;
price = 0;
;
material = "";
}
  
double getPrice() const
{
return price;
}
  
int getSize() const
{
return size;
}
  
string getStyle() const
{
return style;
}
  
string getMaterial() const
{
return material;
}
  
void setPrice(double prc)
{
price = prc;
}
void setMaterial(string mat)
{
material = mat;
}
void setStyle(string sty)
{
style = sty;
}
  
void setSize(int sz)
{
size = sz;
}
  
bool operator > (const suit &other)
{
return price > other.price;
}
friend ostream & operator << (ostream &out, const suit &s);
friend istream & operator >> (istream &in, suit &s);
  
};

ostream & operator << (ostream &out, const suit &s)
{
out << "Material: " << s.material << " Size: " << s.size << " Style: " << s.style << " Price: $" << s.price;
return out;
}

istream & operator >> (istream &in, suit &s)
{
in >> s.material >> s.size >> s.style >> s.price;
return in;
}

class shoes
{
private:
  
int size;
string style;
double price;
public:
shoes()
{
size = 0;
price = 0;
;
  
}
double getPrice() const
{
return price;
}
  
int getSize() const
{
return size;
}
  
string getStyle() const
{
return style;
}
  
void setPrice(double prc)
{
price = prc;
}
  
void setStyle(string sty)
{
style = sty;
}
  
void setSize(int sz)
{
size = sz;
}
friend ostream & operator << (ostream &out, const shoes &s);
friend istream & operator >> (istream &in, shoes &s);
  
};

ostream & operator << (ostream &out, const shoes &s)
{
out << " Size: " << s.size << " Style: " << s.style << " Price: $" << s.price;
return out;
}

istream & operator >> (istream &in, shoes &s)
{
in >> s.size >> s.style >> s.price;
return in;
}

double operator + (const suit &suit1, const shoes &shoes1)
{
return suit1.getPrice() + shoes1.getPrice();
}

void displayCombination(const suit &suit1, const shoes &shoes1)
{
cout << "Combination is - " <<endl;
cout << "Suit=> " << suit1 << endl;
cout << "Shoes=> " << shoes1 << endl;
cout << "Total cost: $" << suit1 + shoes1 << endl << endl;
}
int main()
{
vector<suit> suitslist;
vector<shoes> shoeslist;
suit suit1;
shoes shoes1;
string ans = "y";
while(ans == "y" || ans == "Y")
{
cout << "Enter a suit in the format <material> <size> <style> <price> [e.g. Cotton 40 Wedding 110.00]" << endl;
cin >> suit1;
suitslist.push_back(suit1);
cout << "Add another? y/n: ";
cin >> ans;
}
cout << "=============================" << endl << endl;
ans = "y";
while(ans == "y" || ans == "Y")
{
cout << "Enter a shoes in the format <size> <style> <price> [e.g. 47 Sports 55.00]" << endl;
cin >> shoes1;
shoeslist.push_back(shoes1);
cout << "Add another? y/n: ";
cin >> ans;
}

cout << "=============================" << endl << endl;
ans = "y";
srand(time(0));
while(ans == "y" || ans == "Y")
{
//generate 2 random numbers
int r1 = rand() % suitslist.size();
int r2 = rand() % shoeslist.size();
displayCombination(suitslist[r1], shoeslist[r2]);
  
cout << "Show another combination? y/n: ";
cin >> ans;
}
  
cout << "=============================" << endl << endl;
cout << "Sorting the suits" << endl;
  
int minIdx;
for(int i = 0; i < suitslist.size(); i++)
{
minIdx = i;
for(int j = i + 1; j < suitslist.size(); j++)
{
if( suitslist[minIdx] > suitslist[j])
minIdx = j;
}
if(minIdx != i)
{
suit temp = suitslist[i];
suitslist[i] = suitslist[minIdx];
suitslist[minIdx] = temp;
}
}
  
  
cout << "The sorted list of suits is - " << endl;
for(int i = 0; i < suitslist.size(); i++)
cout << suitslist[i] << endl;

}

output

Enter a suit in the format <material> <size> <style> <price> [e.g. Cotton 40 Wedding 110.00]
Linen 42 Formal 149.00
Add another? y/n: y
Enter a suit in the format <material> <size> <style> <price> [e.g. Cotton 40 Wedding 110.00]
Cotton 40 Casual 120.00
Add another? y/n: y
Enter a suit in the format <material> <size> <style> <price> [e.g. Cotton 40 Wedding 110.00]
Cotton 42 Formal 145.00
Add another? y/n: y
Enter a suit in the format <material> <size> <style> <price> [e.g. Cotton 40 Wedding 110.00]
Polyster 44 Wedding 179.00
Add another? y/n: n
=============================

Enter a shoes in the format <size> <style> <price> [e.g. 47 Sports 55.00]
46 Sports 89.00
Add another? y/n: y
Enter a shoes in the format <size> <style> <price> [e.g. 47 Sports 55.00]
47 Casual 70.00
Add another? y/n: y
Enter a shoes in the format <size> <style> <price> [e.g. 47 Sports 55.00]
46 Formal 99.00
Add another? y/n: n
=============================

Combination is -
Suit=> Material: Cotton Size: 40 Style: Casual Price: $120
Shoes=> Size: 47 Style: Casual Price: $70
Total cost: $190

Show another combination? y/n: y
Combination is -
Suit=> Material: Polyster Size: 44 Style: Wedding Price: $179
Shoes=> Size: 46 Style: Formal Price: $99
Total cost: $278

Show another combination? y/n: n
=============================

Sorting the suits
The sorted list of suits is -
Material: Cotton Size: 40 Style: Casual Price: $120
Material: Cotton Size: 42 Style: Formal Price: $145
Material: Linen Size: 42 Style: Formal Price: $149
Material: Polyster Size: 44 Style: Wedding Price: $179