Que Generate software for a garment shop at Treasure Island where a monsoon offer is going on.the offer
states as below
1. On the purchase of one item, bill amount will be of actual printed price(No offer)
2. On the purchase of two items, bill amount will be of the item having the higher price.
3. On the purchase of three items, bill amount will be the sum of highest and lowest price.
Create a class SHOP having three overloaded methods named billAmount()……..{with parameter with
return type.}
Create another class containing main method and generate the bill for above given situations
My Code
#include<iostream.h>
#include<conio.h>
class Shop
{
private:
int item;
float price,p1,p2,p3;
public:
float billAmount(float p);
float billAmount(float p,float x);
float billAmount(float p,float x,float y);
};
float Shop::billAmount(float p)
{
price=p;
item=1;
cout<<"no offer on the purchase of 1 item,cost:"<<price;
return (price);
}
float Shop::billAmount(float p,float x)
{
p1=p;
p2=x;
item=2;
if(p1>p2)
{
cout<<"On the purchase of two items, bill amount will be of the item having the higher price.cost:"<<p1;
return (p1);
}
else
{
cout<<"On the purchase of two items, bill amount will be of the item having the higher price.cost:"<<p2;
return (p2);
}
}
float Shop:: billAmount(float p,float x,float y)
{
p1=p;
p2=x;
p3=y;
item=3;
if(p1>p2 && p1>p3)
{
if(p2<p3)
{
float n=p1+p2;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
else
{
float n=p1+p3;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
}
else if(p3>p1 && p3>p2)
{
if(p1<p2)
{
float n=p1+p3;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
else
{
float n=p2+p3;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
}
else if(p2>p1 && p2>p3)
{
if(p1<p3)
{
float n=p1+p2;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
else
{
float n=p2+p3;
cout<<"On the purchase of 3 items, bill amount will be of the item having the sum of lower and higher price.cost:"<<n;
return (n);
}
}
class Ti:Shop
{
void main()
{
clrscr();
Shop s;
s.billAmount(1421.9);
s.billAmount(1930,2020);
s.billAmount(1502,2004,9125);
getch();
}
}
#include <iostream> //note not .h
//I'll suggest you to not use conio. You aren't giving it a good use either way
class Shop //¿what is this class for?
{
private:
//int item;
//float price,p1,p2,p3; //you don't seem to use them
//...
};
float Shop::billAmount(float p)
{
price=p;
item=1; //it seems that you don't care about the state of you object.
std::cout<<"no offer on the purchase of 1 item,cost:"<<price; //this shouldn't be here. Ditto for all the other methods
return (price);
}
class Ti:Shop //¿private inheritance?
{
void main() //this ain't java.
{
clrscr(); //Don't touch my screen
Shop s;
s.billAmount(1421.9);
s.billAmount(1930,2020);
s.billAmount(1502,2004,9125);
getch(); //If you finish then finish
}
}
int main(){ //starting point of the program
//...
}