1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#include <chrono>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
class user
{
private:
std::string name;
std::string pass;
public:
void getdata()
{
int flag = 0;
do {
std::cout << "Enter username: "; std::getline(std::cin, name);
std::cout << "\nEnter password: "; std::getline(std::cin, pass);
if(name == "myname" && pass == "tiger")
{
std::cout << "\n\nLogin successful\n";
flag = 1;
}
else {
std::cout << "\n\nInvalid username or password\n\nHint:Your "
"username and password is myname and tiger\n\n";
}
} while(flag == 0);
}
};
class cart
{
private:
char items[80] {};
int no = 0;
double price = 0;
public:
void getdata()
{
category();
std::ofstream w1("file.dat", std::ios_base::app);
w1 << "Total price = " << price << '\n';
w1 << "Total items = " << no << '\n';
w1.close();
}
void outdata() { std::cout << "\n\nProceeding to checkout\n"; }
double category()
{
std::ofstream w1("file.dat");
char ch {};
do {
std::cout << "\nEnter:\n1) for Fruits and Vegetables\n2) for Beverages"
"\n3) for Household needs\n>>> ";
int option {};
std::cin >> option;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
////////////////////////////
switch(option) {
case 1:
{
char fv[80][80] = { "onion", "potato", "banana"};
double fvp[5] = { 50, 15, 7 };
std::cout << "\nEnter:\n1) for onion (Rs 50 per kg)\n2) for "
"potato (Rs 15 per kg)\n3) for bananas (Rs 7 per "
"unit)\n>>> ";
int choice {};
std::cin >> choice;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::strncpy(items, fv[choice-1], 80);
std::cout << "Enter number required: ";
int n {};
std::cin >> n;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
no += n;
price += n * fvp[choice-1];
w1 << items << ": " << n << '\n';
}
break;
case 2:
{
char bv[80][80] = { "Tea", "Coffee", "Juice" };
double bvp[5] = { 160, 400, 175 };
std::cout << "\nEnter:\n1) for tea (Rs 160 per 500 gm)\n2) for "
"coffee (Rs 400 per 500 gm)\n3) for juice (Rs "
"175 per 500ml)\n>>> ";
int choice {};
std::cin >> choice;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::strncpy(items, bv[choice-1], 80);
std::cout << "Enter number required: ";
int n {};
std::cin >> n;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
no += n;
price = n * bvp[choice-1];
w1 << items << ": " << n << '\n';
}
break;
case 3:
{
char hn[80][80] = { "Detergent", "Dishwashers", "Air freshener" };
double hnp[5] = {160, 105, 43 };
std::cout << "\nEnter:\n1) for detergent (Rs 160 per 1.5 kg)"
"\n2) for dishwasher (Rs 105 per 200 gm)\n3) for "
"juice (Rs 43 per 50gm)\n>>> ";
int choice {};
std::cin >> choice;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::strncpy(items, hn[choice-1], 80);
std::cout << "Enter number required: ";
int n {};
std::cin >> n;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
no += n;
price = n * hnp[choice-1];
w1 << items << ": " << n << '\n';
}
break;
}
std::cout << "\nDo you want to continue (y/n)? ";
std::cin >> ch;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} while(ch == 'y');
w1.close();
return 0;
}
};
void waitForEnter();
int main()
{
user s1;
std::cout << "############################################################"
<< "\n## Welcome To 100% Supermarket ##\n"
<< "############################################################"
<< "\nEnter your username and password\n\n";
s1.getdata();
cart c1;
c1.getdata();
c1.outdata();
std::string line;
std::ifstream r1("file.dat");
std::cout << "Your shopping details are as follows:--\n";
while(getline(r1,line)) { std::cout << line << '\n'; }
r1.close();
waitForEnter();
return 0;
}
void waitForEnter()
{
std::cout << "\nPress ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
|