User Tools

Site Tools


perso:study:cnam:main.cpp

main.cpp

#include <iostream>
#include <string>
 
#include "c_account.hpp"
#include "c_standardAccount.hpp"
#include "c_customer.hpp"
 
using namespace std;
 
int main ( int argc, char *argv[] )
{
	c_account *Account = null;
	c_customer *Customer = null;
 
	bool bLoop = true;
	char cInput = 0;
	string sName;
	float fAmount = 0;
 
	cout << "Welcome to the Bank Intranet" << endl << endl;
 
	while ( bLoop == true )
	{
		cout << "Menu" << endl << endl;
		cout << " 1. Create Customer" << endl;
		cout << " 2. Create Account" << endl;
		cout << " 3. Add money on account" << endl;
		cout << " 4. Get money from account" << endl;
		cout << " 5. Check money" << endl;
		cout << " 6. Delete Customer" << endl;
		cout << " 7. Delete Account" << endl;
		cout << " 8. Go online to manage account" << endl;
		cout << " 9. Manage customers stock options" << endl;
		cout << " A. Manage employees" << endl;
		cout << " B. Manage credits" << endl;
		cout << " C. Manage loans" << endl;
		cout << " D. Declare bankrupt" << endl;
		cout << " E. Move officies to some money-paradise islands" << endl;
		cout << "x. Exit" << endl;
 
		cin >> cInput;
		switch (cInput)
		{
			case '1':
				cout << "You choose to create a customer" << endl;
				if (Customer == null)
				{
					cout << "What is his/her name? ";
					cin >> sName;
					Customer = new c_customer;
					Customer->setCustomerLastName(Name);
					cout << "Hint: Do not forget to welcome him/her." << endl;
				}
				else
				{
					cout << "Our business plan is to grow slowly but steadily. No more than one customer please :-)." << endl << "Operation rejected. Find a good excuse :p" << endl;
				}
				break;
			case '2':
				cout << "You choose to create an account" << endl;
				cout << "Here is the list of customers:" << endl;
				if (Customer == null)
				{
					cerr << "Sorry no customer as for now, byebye" << endl;
				}
				else
				{
					cout << "You have 1 customer: " << Customer.getName() << endl;
					cout << "what type of account (1. Std/2. Savings)";
					cin >> cInput;
					switch (cInput)
					{
						case '1':
							Account = new c_standardAccount;
							Account->setAccountBalance(15);
							Account->setC_customer(*Customer);
							// add code here to offer a present of 15 euro
							cout << "Tell customer that he has been awarded 15 euro as a present to have made the right choice." << endl;
							cout << "His/her account's ID is: " << Account->getAccountID() << endl;
							break;
						case '2':
							cout << "As we have a 0% interest, the customer after some thought is not interesting anymore in a savings account." << endl;
							break;
						default:
							cerr << "Wrong answer, operation canceled" << endl;
							break;
					}
				}
				break;
			case '3':
				if (Account == null)
				{
					cerr << "No customer or account..." << endl;
				}
				else
				{
					cout << "How much: ";
					cin >> fAmount;
					Account->setAccountBalance(Account->getAccountBalance() + fAmount);
				}
				break;
			case '4':
				if (Account == null)
				{
					cerr << "No customer or account..." << endl;
				}
				else
				{
					cout << "How much: ";
					cin >> fAmount;
					if (Account->getAccountBalance() - fAmount < 0)
					{
						cerr << "Our house does not do credits, sorry." << endl;
					}
					else
					{
						Account->setAccountBalance(Account->getAccountBalance() - fAmount);
					}
				}
				break;
			case '5':
				if (Account == null)
				{
					cerr << "No customer or account..." << endl;
				}
				else
				{
					cout << "The customer has: " << Account->getAccountBalance() << " what ever currency best suit us ;-)" << endl;
				}
				break;
			case '6':
				if (Customer == null)
				{
					cerr << "No customer..." << endl;
				}
				else
				{
					if (Account != null)
					{
						cerr << "Close the customer's account first." << endl << "Operation cancelled!" << endl;
					}
					else
					{
						delete [] Customer;
						cout << "No more account opened" << endl;
					}
				}
			case '7':
				if (Account == null)
				{
					cerr << "No account..." << endl;
				}
				else
				{
					delete [] Account;
					cout << "No more account opened" << endl;
				}
				break;
			case '8':
			case '9':
			case 'A':
			case 'B':
			case 'C':
			case 'D':
			case 'E':
				cout << "Function will be implemented at a later stage ;-)" << endl;
				break;
			case 'x':
				bLoop = false;
				break;
			default:
				cerr << endl << "Input ignored, please reformulate" << endl;
				break;
		}
	}
	if ( (Customer != null) || (Account != null) )
	{
		cerr << "Hey you forgot to close the customer and/or account!" << endl;
		return 1;
	}
	else
	{
		cout << "Ciao..." << endl;
		return 0;
	}
}
perso/study/cnam/main.cpp.txt · Last modified: 2015/05/01 23:32 (external edit)