Untitled
unknown
plain_text
3 years ago
8.8 kB
8
Indexable
#include <iostream>
#include <cstdlib>
using namespace std;
#define EXIT_MENU 0
#define WRONG_SELECT 1
#define MENU_SELECT 2
#define MAX_TRY 3
#define MAX_ID_LIMIT 999999999LL
#define MIN_ID_LIMIT 100000000LL
#define MAX_CREDIT_LIMIT 9999
#define MIN_CREDIT_LMIT 1000
#define LOGO_SIZE 9
void main_menu();
void second_menu();
int render_main_menu();
char render_second_menu();
int main_menu_handelr();
int second_menu_handler();
void read_email();
bool is_alpha_num(char);
void read_id();
void read_credit();
void leaving_service(int);
int random_generator(int min, int max);
void payment();
void identification();
void cheking_age();
void register_client();
void leave_company();
void logo_company();
void human_conaction();
int main()
{
// Reading id
identification();
read_id();
main_menu();
return 0;
}
void main_menu() {
int menu_result = MENU_SELECT, counter = 0;
while (menu_result != EXIT_MENU)
{
menu_result = main_menu_handelr();
if (menu_result == WRONG_SELECT && ++counter > MAX_TRY)
break;
else
counter = 0;
}
leaving_service(counter);
}
int main_menu_handelr()
{
int select = render_main_menu();
switch (select)
{
case 1:
register_client();
return MENU_SELECT;
case 2:
second_menu();
return MENU_SELECT;
case 3:
leave_company();
return MENU_SELECT;
case 4:
return EXIT_MENU;
default:
return WRONG_SELECT;
}
return EXIT_MENU;
}
void second_menu() {
int menu_result = MENU_SELECT;
int counter = 0;
while (menu_result != EXIT_MENU)
{
menu_result = second_menu_handler();
if (menu_result == WRONG_SELECT && ++counter > MAX_TRY)
break;
}
leaving_service(counter);
}
void register_client() {
identification();
cheking_age();
read_email();
read_credit();
cout << "Thank you for choosing our company and welcome! Our people will contact youshortly!" << endl;
}
void leave_company() {
cout << "You must speak with a service representative, please leave an email so that we can get back to you." << endl;;
cout << "Enter your email:\n";
read_email();
cout << "We are sorry to hear you are unhappy. We will contact you in the next " << random_generator(72, 168) << "hours.\n";
}
int render_main_menu()
{
int select;
cout << "Thank you for choosing SCE Internet Company! How can we help you?" << endl;
cout << "" << endl;
cout << "\n\t\tMENU :" << endl;
cout << "Press 1\nI want to join your company as a new client." << endl;
cout << "" << endl;
cout << "Press 2\nI want to find out some details about my already existing account." << endl;
cout << "" << endl;
cout << "Press 3\nI want to leave your company." << endl;
cout << "" << endl;
cout << "Press 4\nI want to exit the chat." << endl;
cin >> select;
getchar();
return select;
}
int second_menu_handler()
{
char select = render_second_menu();
switch (select)
{
case 'a':
payment();
return MENU_SELECT;
case 'b':
logo_company();
return MENU_SELECT;
case 'c':
human_conaction();
return MENU_SELECT;
case 'd':
return EXIT_MENU;
default:
return WRONG_SELECT;
}
}
char render_second_menu()
{
char select;
cout << "What information are you after?" << endl;
cout << "" << endl;
cout << "\n\t\tMENU :" << endl;
cout << "Press a\nI would like to know how much I need to pay this month." << endl;
cout << "" << endl;
cout << "Press b\nI would like to know more about you." << endl;
cout << "" << endl;
cout << "Press c\nI would like to speak with a real human." << endl;
cout << "" << endl;
cout << "Press d\nI want to return to the main menu." << endl;
cin >> select;
return select;
}
void leaving_service(int counter)
{
if (counter > MAX_TRY)
cout << "Come back when you have something to do.\n";
else
cout << "nice to see you.\n";
}
// Services
void read_credit()
{
int card_num = 0;
cout << "Enter 4 last number of your card:" << endl;
cin >> card_num;
while (card_num > MAX_CREDIT_LIMIT || card_num < MIN_CREDIT_LMIT)
{
cout << "Error! Please try again:" << endl;
cin >> card_num;
}
cout << "Correct" << endl;
getchar();
}
void read_id()
{
int long long id;
cout << "Enter 9 digit id number:\n";
cin >> id;
while (id > MAX_ID_LIMIT || id < MIN_ID_LIMIT)
{
cout << "Error! Please try again:" << endl;
cin >> id;
}
cout << "Correct" << endl;
getchar();
}
bool is_alpha_num(char c)
{
if (c <= '9' && c >= '0')
return true;
if (c >= 'a' && c <= 'z')
return true;
if (c >= 'A' && c <= 'Z')
return true;
if (c == '_')
return true;
return false;
}
void read_email()
{
cout << "Enter your email" << endl;
// @ flag
bool domin_flag = false;
// Bad Email
bool bad_email = false;
// Input char
char input = 0, prev = 0;
do
{
if (bad_email)
cout << "Error! Please try again:" << endl;
bad_email = domin_flag = false;
input = prev = 0;
while (input != ' ')
{
cin.get(input);
if (!bad_email)
{
if (!is_alpha_num(input))
{
// Dot case
if (input == '.' && prev == '.')
bad_email = true;
// @ case
if (input == '@')
if (domin_flag)
bad_email = true;
else
domin_flag = true;
}
prev = input;
}
}
cin.get(input);
} while (bad_email);
cout << "Correct.\n";
}
void identification()
{
cout << "Enter name and press '.' at the end:" << endl;
bool strValid = false;
while (!strValid)
{
char inputChar = getc(stdin);
if (inputChar < 'A' || inputChar>'Z')
{
continue;
}
bool scanningActive = true;
while (scanningActive)
{
char inputChar = getc(stdin);
if (inputChar == '.')
{
strValid = true;
break;
}
if (inputChar < 'a' || inputChar>'z')
{
break;
}
}
}
getchar();
}
void cheking_age()
{
int age = 0;
bool flag = 0;
cout << "Enter your age:" << endl;
cin >> age;
while (age > 120 || age < 18)
{
flag == false;
if (flag == false)
{
cout << "Your age is incorrect, Please try again:" << endl;
cin >> age;
}
}
cout << "Correct" << endl;
getchar();
}
int random_generator(int min, int max) {
srand(time(NULL)); //*Initialization of random*//
int value = min + (rand() % (max - min));
return value;
}
void payment() {
read_credit();
cout << " you have to pay " << random_generator(20, 100) << endl;
}
void logo_company()
{
cout << "SCE Internet Company is a growing internet service company located in Israel. More details can be found in our website." << endl;
int number = 0;
cout << "Enter number between 3-9" << endl;
cin >> number;
for (int i = 0; i < LOGO_SIZE; ++i)
{
for (int j = 0; j < LOGO_SIZE; ++j)
{
if (number < 3 || number>9)
{
cout << "Error ,You entered an incorrect value: Try again." << endl;
cin >> number;
break;
}
if (i == 0 && j < number)
{
cout << "*";
}
if (i == 1 && j == 0)
{
cout << "*";
}
if (i == 2 && j < number)
{
cout << "*";
}
if (i == 3)
{
if (j == number - 1)
{
cout << "*";
}
else
cout << " ";
}
if (i == 4 && j < number)
{
cout << "*";
}
}
cout << endl;
}
}
void human_conaction()
{
cout << "We apologize, there is no service representative available right now, please enter your email so we can get back to you as soon as possible." << endl;
read_email();
{
cout << "We will contact you in the next 48 hours." << endl;
}
}Editor is loading...