Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please do the class diagram for the following code.please urgent****CLASS DIAGRAM******very important .please do properly #include #include using namespace std; struct phone { string model;
please do the class diagram for the following code.please urgent****CLASS DIAGRAM"******very important .please do properly
#include
#include
using namespace std;
struct phone
{
string model;
string feature;
string price;
};
class stock
{
private:
int top;
int count;
struct phone phones[100];
public:
stock() {
count = 0;
top=-1;
}
~stock() {
}
void push(struct phone new_p){
top = getCount();
phones[top].model = new_p.model;
phones[top].feature = new_p.feature;
phones[top].price = new_p.price;
top++;
setCount(top);
}
struct phone pop() {
struct phone tmp;
if(top == -1)
cout<<"Stack is empty!"<
else
{
tmp.model = phones[top].model;
tmp.feature = phones[top].feature;
tmp.price = phones[top].price;
top--;
}
}
void setCount(int c)
{
count = c;
}
int getCount()
{
return count;
}
int getCountA()
{
int c=0;
for(int i=0; i
if(phones[i].model=="A")
c++;
return c;
}
int getCountB()
{
int c=0;
for(int i=0; i
if(phones[i].model=="B")
c++;
return c;
}
int getCountC()
{
int c=0;
for(int i=0; i
if(phones[i].model=="C")
c++;
return c;
}
struct phone getPhone(int n) {
return phones[n];
}
void addPhone(struct phone p) {
int c = getCount();
c++;
setCount(c);
phones[c-1] = p;
}
void setPhone(int n, struct phone t)
{
phones[n].model = t.model;
phones[n].feature = t.feature;
phones[n].price = t.price;
}
void display_all()
{
for(int i=0; i
{
cout<
}
}
void display_byModel(string m)
{
for(int i=0; i
{
if(phones[i].model == m)
cout<
}
}
void display_byFeature(string m)
{
for(int i=0; i
{
if(phones[i].feature == m)
cout<
}
}
void display_byPrice(string m)
{
for(int i=0; i
{
if(phones[i].price == m)
cout<
}
}
void display_Sort()
{
cout<<"No Model Feature Price"<
for( int i=0; i
{
for ( int j=i; j
{
if(phones[j].model == "A")
{
if(phones[i].model != "A")
{
struct phone tmp;
tmp.model = phones[i].model;
tmp.feature = phones[i].feature;
tmp.price = phones[i].price;
phones[i].model = phones[j].model;
phones[i].feature = phones[j].feature;
phones[i].price = phones[j].price;
phones[j].model = tmp.model;
phones[j].feature = tmp.feature;
phones[j].price = tmp.price;
}
}
}
}
for( int i=0; i
{
for ( int j=i; j
{
if(phones[j].model == "B")
{
if(phones[i].model == "C")
{
struct phone tmp;
tmp.model = phones[i].model;
tmp.feature = phones[i].feature;
tmp.price = phones[i].price;
phones[i].model = phones[j].model;
phones[i].feature = phones[j].feature;
phones[i].price = phones[j].price;
phones[j].model = tmp.model;
phones[j].feature = tmp.feature;
phones[j].price = tmp.price;
}
}
}
}
display_all();
}
};
int main()
{
stock p;
struct phone t;
struct phone b;
int go_on;
struct phone new_phone;
ifstream myfile ("stock.txt");
if (myfile.is_open())
{
while(1)
{
getline(myfile, new_phone.model);
getline(myfile, new_phone.feature);
getline(myfile, new_phone.price);
p.addPhone(new_phone);
if(myfile.eof())
break;
}
myfile.close();
}
do{
cout << "Are you Customer(1) or Shop Owner(2)?";
int choice;
cin>>choice;
switch(choice)
{
case 2:
cout<<"1. Display phone list sorted by model"<
cout<<"2. Order Phone"<
cout<<"3. Receive stock update info"<
cout<<"4. View a phone info"<
int c2;
cin>>c2;
switch(c2)
{
case 1:
p.display_Sort();
break;
case 2:
cout<<"Available list(model): "<
if(p.getCountA()<10)
cout<<"A :"<
if(p.getCountB()<10)
cout<<"B :"<
if(p.getCountC()<10)
cout<<"C :"<
cout<<"Add a phone"<
cout<<"model: ";
cin>>t.model;
cout<<"feature: ";
cin>>t.feature;
cout<<"price: ";
cin>>t.price;
p.push(t);
break;
case 3:
cout<<"Recently added phone"<
cout<<"model: "<
cout<<"feature: "<
cout<<"price: "<
break;
case 4:
cout<<"---Total count of phones in the stock now:"<
cout<<"Input No of phone you want to see:";
int n;
cin>>n;
cout<
cout<
cout<
break;
default:
break;
}
break;
case 1:
cout<<"Search by model(1) feature(2) price(3):"<
cout<<"Buy a phone(4)"<
cout<<"Get invoice(5)"<
int c;
string m,f,pr;
cin>>c;
switch(c)
{
case 1:
cout<<"model:";
cin>>m;
p.display_byModel(m);
break;
case 2:
cout<<"feature:";
cin>>f;
p.display_byFeature(f);
break;
case 3:
cout<<"price:";
cin>>pr;
p.display_byPrice(pr);
break;
case 4:
cout<<"Phone list:"<
p.display_Sort();
cout<<"Input the No you are gonna buy:"<
int n;
cin>>n;
b.model = p.getPhone(n-1).model;
b.feature = p.getPhone(n-1).feature;
b.price = p.getPhone(n-1).price;
for( int i = n; i
{
p.setPhone(i, p.getPhone(i-1));
}
//p.setPhone(p.getCount()-1,NULL);
break;
case 5:
cout<<"Invoice:"<
cout<<"Model:"<
break;
default:
break;
}
break;
}
cout<<"Continue?(yes:1, No:0)";
cin>>go_on;
}while(go_on);
return 0;
}
stock.txt
A
abc
120
B
sdf
150
C
ewr
190
A
wer
302
A
asdf
405
B
qwer
900
C
wew
340
B
wers
230
A
ass
643
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