Computer Science, asked by roysubhadip76, 8 months ago

A shopaholic has to buy a pair of jeans , a pair of shoes l,a skirt and a top with budgeted dollar.Given the quantity of each product and the price per unit determine how many options of each item are present.if required all dollars are spent write the programming in c​

Answers

Answered by yaswanth28
0

Answer:

Explanation:

of shoes l,a skirt and a top with budgeted dollar.Given the quantity of each product and the price per unit determine how many opt

Answered by dreamrob
0

Program in C++:

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int jeans, shoes, skirt, top, budget;

 

cout<<"Enter number of jeans : ";

cin>>jeans;

if(jeans < 1 || jeans > 1000)

{

 cout<<"Invalid input. \nError : Input not in range";

 return 0;

}

 

int jeans_price[jeans];

cout<<"Enter possible prices of jeans : ";

for(int i = 0 ; i < jeans ; i++)

{

 cin>>jeans_price[i];

 if(jeans_price[i] < 1 || jeans_price[i] > (int)pow(10,9))

 {

  cout<<"Invalid input. \nError : Input not in range";

  return 0;

 }

}

 

cout<<"Enter number of shoes : ";

cin>>shoes;

if(shoes < 1 || shoes > 1000)

{

 cout<<"Invalid input. \nError : Input not in range";

 return 0;

}

 

int shoes_price[shoes];

cout<<"Enter possible prices of shoes : ";

for(int i = 0 ; i < shoes ; i++)

{

 cin>>shoes_price[i];

 if(shoes_price[i] < 1 || shoes_price[i] > (int)pow(10,9))

 {

  cout<<"Invalid input. \nError : Input not in range";

  return 0;

 }

}

 

cout<<"Enter number of skirt : ";

cin>>skirt;

if(skirt < 1 || skirt > 1000)

{

 cout<<"Invalid input. \nError : Input not in range";

 return 0;

}

 

int skirt_price[skirt];

cout<<"Enter possible prices of skirt : ";

for(int i = 0 ; i < skirt ; i++)

{

 cin>>skirt_price[i];

 if(skirt_price[i] < 1 || skirt_price[i] > (int)pow(10,9))

 {

  cout<<"Invalid input. \nError : Input not in range";

  return 0;

 }

}

 

cout<<"Enter number of top : ";

cin>>top;

if(top < 1 || top > 1000)

{

 cout<<"Invalid input. \nError : Input not in range";

 return 0;

}

 

int top_price[top];

cout<<"Enter possible prices of top : ";

for(int i = 0 ; i < top ; i++)

{

 cin>>top_price[i];

 if(top_price[i] < 1 || top_price[i] > (int)pow(10,9))

 {

  cout<<"Invalid input. \nError : Input not in range";

  return 0;

 }

}

 

cout<<"Enter Budget : ";

cin>>budget;

if(budget < 1 || budget > (int)pow(10,9))

{

 cout<<"Invalid input. \nError : Input not in range";

 return 0;

}

 

if(jeans==1 && shoes==1 && skirt==1 && top==1)

{

 int sum = jeans_price[0] + shoes_price[0] + skirt_price[0] + top_price[0];

 if(sum <= budget)

 {

  cout<<"Number of combinations that can be bought = 1";

 }

 else

 {

  cout<<"Number of combinations that can be bought = 0";

 }

}

else

{

 int sum = 0, count = 0;

 for(int i = 0 ; i < jeans ; i++)

 {

  for(int j = 0 ; j < shoes ; j++)

  {

   for(int k = 0 ; k < skirt ; k++)

   {

    for(int l = 0 ; l < top ; l++)

    {

     sum = sum + jeans_price[i] + shoes_price[j] + skirt_price[k] + top_price[l];

     if(sum <= budget)

     {

      count++;

     }

     sum = 0;

    }

   }

  }

 }

 cout<<"Number of combinations that can be bought = "<<count;

}

return 0;

}

Output 1:

Enter number of jeans : 2

Enter possible prices of jeans : 2 3

Enter number of shoes : 1

Enter possible prices of shoes : 4

Enter number of skirt : 1

Enter possible prices of skirt : 2

Enter number of top : 3

Enter possible prices of top : 1 2 3

Enter Budget : 10

Number of combinations that can be bought = 3

Output 2:

Enter number of jeans : 1

Enter possible prices of jeans : 4

Enter number of shoes : 3

Enter possible prices of shoes : 3 4 1

Enter number of skirt : 2

Enter possible prices of skirt : 3 2

Enter number of top : 1

Enter possible prices of top : 4

Enter Budget : 12

Number of combinations that can be bought = 2

Output 3:

Enter number of jeans : 1

Enter possible prices of jeans : 1

Enter number of shoes : 1

Enter possible prices of shoes : 4

Enter number of skirt : 1

Enter possible prices of skirt : 3

Enter number of top : 1

Enter possible prices of top : 1

Enter Budget : 3

Number of combinations that can be bought = 0

Attachments:
Similar questions