* Exercise 2: *Exercise 2: Shoes Style is a Shoes shop that offers types of shoe
ID: 648243 • Letter: #
Question
*Exercise 2:
*Exercise 2: Shoes Style is a Shoes shop that offers types of shoes. Use Shoes as base class of the hierarchy, then include HighHeels, Sneakers and Flat classes that inherent from Shoes as illustrated in the figure 1. Base class Shoes should include data members representing the size, price and model .Shoes constructor should initialize these data members. Shoes shop sells types of Shoes for SR 200, except: flat shoes which are sold for SR85 more and high heels shoes which are sold for SR150 more. The model for sneakers shoes is running shoes, flat shoes is Ballet and for high heels shoes is cone Heels. In the main function create a pointer object for base class. Create object form each class to test your functions properly in the main function.Explanation / Answer
#include <iostream>
#include<string>
using namespace std;
class Shoes
{protected:
string smodel;
float sprice;
float size;
public:
Shoes()
{
smodel="shoes";
sprice=200;
size=7;
}
int getsize()
{
return size;
}
float getsprice()
{
return sprice;
}
string getsmodel()
{
return smodel;
}
};
class flat :public Shoes
{
public:
flat ()
{
smodel="ballet";
sprice=285;
size=7;
}
int getsize()
{
return size;
}
float getsprice()
{
return sprice;
}
string getsmodel()
{
return smodel;
}
};
class Sneaker :public Shoes
{
public:
Sneaker()
{
smodel="running shoes";
sprice=200;
size=7;
}
int getsize()
{
return size;
}
float getsprice()
{
return sprice;
}
string getsmodel()
{
return smodel;
}
};
class highheals :public Shoes
{
public:
highheals()
{
smodel="heals";
sprice=350;
size=7;
}
int getsize()
{
return size;
}
float getsprice()
{
return sprice;
}
string getsmodel()
{
return smodel;
}
};
int main() {
// your code goes here
Shoes *sPtr;
cout<< sPtr -> getsize();
cout<<sPtr -> getsprice();
cout<<sPtr -> getsmodel();
Sneaker sp;
sPtr=&sp;
cout<< sPtr -> getsize();
cout<<sPtr -> getsprice();
cout<<sPtr -> getsmodel();
flat fd;
//float so = sp.getsize();
sPtr=&fd;
cout<<sPtr -> getsize();
sPtr -> getsprice();
sPtr -> getsmodel();
highheals he;
sPtr=&he;
cout<< sPtr -> getsize();
cout<<sPtr -> getsprice();
cout<<sPtr -> getsmodel();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.