Skip to content

Instantly share code, notes, and snippets.

@cypher-nullbyte
Last active April 27, 2020 15:46
Show Gist options
  • Save cypher-nullbyte/d8289c149d168cacc514a1610d35d211 to your computer and use it in GitHub Desktop.
Save cypher-nullbyte/d8289c149d168cacc514a1610d35d211 to your computer and use it in GitHub Desktop.
//||||Hola chicos{HEllo GUYS}, many students requested me to contribute this code. Here is your solution:)||||
//I have used STL and created the program using Pure Object Oriented Paradigm.
// This code tried to solve the problem considering TIME_COMPLEXITY.
// The algorithm and schema can be improved though.
// https://vitspot.com/code/amount-remaining-after-shopping/
// Else go to bottom of file, to read the whole question.
#include<iostream>
#include<string>
#include<tuple>
#include<vector>
#include<sstream>
#include<limits>
#include<iomanip>
class abc
{
static std::vector<std::tuple<std::string,long,double>>Db;
public:
abc()
{
}
abc(std::string input)
{
std::tuple<std::string,long,double> t;
std::string temp;
std::vector<std::string>vec;
std::stringstream check1(input);
while(getline(check1,temp,' '))
vec.push_back(temp);
long x=0;double y=0.0;
std::stringstream s1(vec[1]); s1>>x;
std::stringstream s2(vec[2]); s2>>y;
t=std::make_tuple(vec[0],x,y);
Db.push_back(t);
}
double customerBalance(std::string name)
{
for(int i=0;i<Db.size();i++)
{
if(std::get<0>(Db[i])==name)
return std::get<2>(Db[i]);
}
return std::numeric_limits<double>::infinity();
}
};
std::vector<std::tuple<std::string,long,double>> abc::Db;
class m1
{
private:
static std::vector<std::tuple<std::string,int,double>>Name_amt;
static std::vector<std::vector<std::string>> Items;
static int idx;
public:
m1()
{
}
m1(std::string input)
{
std::tuple<std::string,int,double> t;
std::string temp;
std::vector<std::string> vec;
std::stringstream check1(input);
while(getline(check1,temp,' '))
vec.push_back(temp);
int num=0;
std::stringstream s1(vec[1]); s1>>num;
double total=0.0;
for(int i=2;i<2+2*num;i+=2)
{
double n=0.0;
std::stringstream s(vec[i+1]);s>>n;
total+=n;
Items[idx].push_back(vec[i]);
}
t=std::make_tuple(vec[0],num,total);
Name_amt.push_back(t);
idx++;
}
double totalprice(std::string name)
{
for(int i=0;i<Name_amt.size();i++)
{
if(std::get<0>(Name_amt[i])==name)
{
return std::get<2>(Name_amt[i]);
}
}
return std::numeric_limits<double>::infinity();
}
void item_display(std::string name)
{
for(int i=0;i<Name_amt.size();i++)
{
if(std::get<0>(Name_amt[i])==name)
{
for(int j=0;j<std::get<1>(Name_amt[i]);j++)
std::cout<<Items[i][j]<<std::endl;
return;
}
}
}
};
std::vector<std::tuple<std::string,int,double>> m1::Name_amt;
std::vector<std::vector<std::string>> m1::Items(20);
int m1::idx=0;
int main()
{
int n;
std::cin>>n;
std::cin.ignore();
//abc obj1[n];
std::string k;
for(int i=0;i<n;i++)
{
std::getline(std::cin,k);
abc obj(k);
}
int m;
std::cin>>m;
std::cin.ignore();
//m1 obj[m];
for(int i=0;i<m;i++)
{
std::getline(std::cin,k);
m1 obj2(k);
}
abc obj1;m1 obj2;
double net_bal=obj1.customerBalance("Sherley")-obj2.totalprice("Sherley");
obj2.item_display("Sherley");
std::cout<<std::fixed<<std::setprecision(2)<<net_bal;
return 0;
}
/*
Sherley goes for a shopping to a mall ‘M1’ . She uses credit card of bank ‘ABC’ for her purchases.
Account details of each customer of ‘ABC’ contain Account holder name, Account number and Balance.
Details of customers of mall ‘M1’ includes customer name and list of items purchased and cost of the items.
Given the details of ‘n’ customers of bank ‘ABC’ and the purchase details of ‘m’ customers to mall ‘M1’,
design an algorithm and write a C program to print the name of items purchased by Sherley and
the balance amount in the account of Sherley in the bank ‘ABC’.
For example, if details (Name, Account number, Balance) of six customers of bank are given as follows:
Raju 12356 1000.00
Sam 12789 980.00
Ram 13457 975.50
Sherley 16789 1500.00
Sheela 17890 1345.50
Kamala 12378 2567.75
Details (Name, number of items purchased, item name1, cost1, item name2, cost2,…)
of three customers of mall m1 are given as follows:
Ram 2 Bread 50.00 Jam 25.00
Sherley 3 Milk 20.00 Bread 50.00 Butter 31.50
Mukesh 4 Chocolate 15.00 Chips 12.50 Rice 29.00 Dall 31.25
Assume that the customer of mall has purchased only a maximum of ten items
Input Format
First line contains the number of customers of ABC bane, n
Next ‘n’ lines contain the details of customers of bank such as Account holder name,
Account number and Balance in order and separated by space
Next line contains the number of customers to mall M1, m
Next ‘m’ lines contains the details of customers to mall such as name,
number of items purchased ‘r’, 2*r detail such as item name and cost. Each detail is separated by a space
Output Format
Print name of the items purchased by Sherley, one item name in a line and balance amount in account of Sherley in the bank
----------SAMPLE INSTANCE OF PROGRAMME--------------------
Input
6
Raju 12356 1000.00
Sam 12789 980.00
Ram 13457 975.50
Sherley 16789 1500.00
Sheela 17890 1345.50
Kamala 12378 2567.75
3
Ram 2 Bread 50.00 Jam 25.00
Sherley 3 Milk 20.00 Bread 50.00 Butter 31.50
Mukesh 4 Chocolate 15.00 Chips 12.50 Rice 29.00 Dall 31.25
output
Milk
Bread
Butter
1398.50
*/
// ### Thank YOu :)
// @cs_jawanda
// .Chiranjeet Singh Jawanda.
// VIT VELLORE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment